Skip to content

Commit

Permalink
Add operation_name to apollo_router_query_planning_time metric
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnou committed Feb 7, 2024
1 parent 271791e commit c3966cc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ impl Service<QueryPlannerRequest> for BridgeQueryPlanner {
Some(d) => d.clone(),
};

let executable_operation;
let schema = &this.schema.api_schema().definitions;
match add_defer_labels(schema, &doc.ast) {
Err(e) => {
Expand All @@ -541,6 +542,9 @@ impl Service<QueryPlannerRequest> for BridgeQueryPlanner {
.to_executable(schema)
// Assume transformation creates a valid document: ignore conversion errors
.unwrap_or_else(|invalid| invalid.partial);
executable_operation = executable.get_operation(operation_name.as_deref()).ok()
.map(|op| op.name.clone().map(|n| n))
.flatten();
doc = Arc::new(ParsedDocumentInner {
executable,
ast: modified_query,
Expand Down Expand Up @@ -569,7 +573,9 @@ impl Service<QueryPlannerRequest> for BridgeQueryPlanner {
)
.await;
let duration = start.elapsed().as_secs_f64();
tracing::info!(histogram.apollo_router_query_planning_time = duration);
tracing::info!(histogram.apollo_router_query_planning_time = duration,
operation_name = executable_operation.map(|n| n.to_string()).unwrap_or_else(|| "anonymous".to_string())
);

match res {
Ok(query_planner_content) => Ok(QueryPlannerResponse::builder()
Expand Down

0 comments on commit c3966cc

Please sign in to comment.