Skip to content

Commit

Permalink
keep the same parent span for prepare, execute and format
Browse files Browse the repository at this point in the history
the spans for execute were considered root spans and did not appear
under the graphql_request span
  • Loading branch information
Geoffroy Couprie authored and Geal committed Nov 30, 2021
1 parent 6d18ef2 commit 81720e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion apollo-router-core/src/query_planner/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ impl PlanNode {
Arc::clone(&service_registry),
Arc::clone(&schema),
)
.instrument(tracing::info_span!("execution"))
.await;

// TODO: this is not great but there is no other way
Expand Down
12 changes: 9 additions & 3 deletions apollo-router/src/apollo_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use apollo_router_core::prelude::graphql::*;
use derivative::Derivative;
use futures::prelude::*;
use std::sync::Arc;
use tracing::{Instrument, Span};
use tracing_futures::WithSubscriber;

/// The default router of Apollo, suitable for most use cases.
Expand Down Expand Up @@ -88,6 +89,7 @@ pub struct ApolloPreparedQuery {
impl PreparedQuery for ApolloPreparedQuery {
#[tracing::instrument(level = "debug")]
async fn execute(self, request: Arc<Request>) -> ResponseStream {
let span = Span::current();
stream::once(
async move {
let response_task = self
Expand All @@ -98,13 +100,17 @@ impl PreparedQuery for ApolloPreparedQuery {
Arc::clone(&request),
Arc::clone(&self.service_registry),
Arc::clone(&self.schema),
);
let query_task = self.query_cache.get_query(&request.query);
)
.instrument(tracing::info_span!(parent: &span, "execution"));
let query_task = self
.query_cache
.get_query(&request.query)
.instrument(tracing::info_span!(parent: &span, "query_parsing"));

let (mut response, query) = tokio::join!(response_task, query_task);

if let Some(query) = query {
tracing::debug_span!("format_response").in_scope(|| {
tracing::debug_span!(parent: &span, "format_response").in_scope(|| {
query.format_response(&mut response, request.operation_name.as_deref())
});
}
Expand Down

0 comments on commit 81720e8

Please sign in to comment.