From ac171b4654fb2231647ab0ef4c69ad8ea3ec7caf Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Mon, 4 Sep 2023 14:02:04 +0200 Subject: [PATCH 1/3] GraphQL response processing must happen under the execution span Previously, any event in processing would be reported under the supergraph span, or any plugin span (like rhai) happening in between --- .../src/services/execution_service.rs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/apollo-router/src/services/execution_service.rs b/apollo-router/src/services/execution_service.rs index 274b215265..5e38fab3a6 100644 --- a/apollo-router/src/services/execution_service.rs +++ b/apollo-router/src/services/execution_service.rs @@ -23,6 +23,7 @@ use tower::ServiceExt; use tower_service::Service; use tracing::event; use tracing::Instrument; +use tracing::Span; use tracing_core::Level; use super::new_service::ServiceFactory; @@ -171,17 +172,21 @@ impl ExecutionService { let schema = self.schema.clone(); let mut nullified_paths: Vec = vec![]; + let execution_span = Span::current(); + let stream = stream .filter_map(move |response: Response| { - ready(Self::process_graphql_response( - &query, - operation_name.as_deref(), - &variables, - is_deferred, - &schema, - &mut nullified_paths, - response, - )) + ready(execution_span.in_scope(|| { + Self::process_graphql_response( + &query, + operation_name.as_deref(), + &variables, + is_deferred, + &schema, + &mut nullified_paths, + response, + ) + })) }) .boxed(); From a96acdb78c3814da50455e7a0c65b2ab114e33cb Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Mon, 4 Sep 2023 14:06:11 +0200 Subject: [PATCH 2/3] changeset --- .changesets/fix_geal_fix_execution_span_attribution.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changesets/fix_geal_fix_execution_span_attribution.md diff --git a/.changesets/fix_geal_fix_execution_span_attribution.md b/.changesets/fix_geal_fix_execution_span_attribution.md new file mode 100644 index 0000000000..03a11c421a --- /dev/null +++ b/.changesets/fix_geal_fix_execution_span_attribution.md @@ -0,0 +1,5 @@ +### GraphQL response processing must happen under the execution span ([PR #3732](https://github.com/apollographql/router/pull/3732)) + +Previously, any event in processing would be reported under the supergraph span, or any plugin span (like rhai) happening in between + +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/3732 \ No newline at end of file From 20e09555715975c73dff9ed787f54d7494b83a7e Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Mon, 4 Sep 2023 14:17:22 +0200 Subject: [PATCH 3/3] update snapshots --- ...acing_tests__traced_basic_composition.snap | 32 +++++++++---------- .../tracing_tests__traced_basic_request.snap | 32 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/apollo-router/tests/snapshots/tracing_tests__traced_basic_composition.snap b/apollo-router/tests/snapshots/tracing_tests__traced_basic_composition.snap index d729a01f61..8c976a59d0 100644 --- a/apollo-router/tests/snapshots/tracing_tests__traced_basic_composition.snap +++ b/apollo-router/tests/snapshots/tracing_tests__traced_basic_composition.snap @@ -707,24 +707,24 @@ expression: get_spans() } } } + }, + "apollo_router::services::execution_service::format_response": { + "name": "apollo_router::services::execution_service::format_response", + "record": { + "entries": [], + "metadata": { + "name": "format_response", + "target": "apollo_router::services::execution_service", + "level": "DEBUG", + "module_path": "apollo_router::services::execution_service", + "fields": { + "names": [] + } + } + }, + "children": {} } } - }, - "apollo_router::services::execution_service::format_response": { - "name": "apollo_router::services::execution_service::format_response", - "record": { - "entries": [], - "metadata": { - "name": "format_response", - "target": "apollo_router::services::execution_service", - "level": "DEBUG", - "module_path": "apollo_router::services::execution_service", - "fields": { - "names": [] - } - } - }, - "children": {} } } } diff --git a/apollo-router/tests/snapshots/tracing_tests__traced_basic_request.snap b/apollo-router/tests/snapshots/tracing_tests__traced_basic_request.snap index 628a15d7a3..e5c11265d4 100644 --- a/apollo-router/tests/snapshots/tracing_tests__traced_basic_request.snap +++ b/apollo-router/tests/snapshots/tracing_tests__traced_basic_request.snap @@ -422,24 +422,24 @@ expression: get_spans() "children": {} } } + }, + "apollo_router::services::execution_service::format_response": { + "name": "apollo_router::services::execution_service::format_response", + "record": { + "entries": [], + "metadata": { + "name": "format_response", + "target": "apollo_router::services::execution_service", + "level": "DEBUG", + "module_path": "apollo_router::services::execution_service", + "fields": { + "names": [] + } + } + }, + "children": {} } } - }, - "apollo_router::services::execution_service::format_response": { - "name": "apollo_router::services::execution_service::format_response", - "record": { - "entries": [], - "metadata": { - "name": "format_response", - "target": "apollo_router::services::execution_service", - "level": "DEBUG", - "module_path": "apollo_router::services::execution_service", - "fields": { - "names": [] - } - } - }, - "children": {} } } }