From 7f149a8c994316626006d6ff8bd3e15eed02ee81 Mon Sep 17 00:00:00 2001 From: Miguel Fernandez Date: Tue, 24 Jan 2023 13:29:56 +0100 Subject: [PATCH] Set proper traceparent in the case of root spans --- query-engine/core/src/telemetry/helpers.rs | 23 +++++++-- query-engine/query-engine/src/server/mod.rs | 56 ++++++++++++--------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/query-engine/core/src/telemetry/helpers.rs b/query-engine/core/src/telemetry/helpers.rs index b65484234e98..418a1d907a75 100644 --- a/query-engine/core/src/telemetry/helpers.rs +++ b/query-engine/core/src/telemetry/helpers.rs @@ -41,6 +41,24 @@ pub fn set_span_link_from_traceparent(span: &Span, traceparent: Option) } } +pub fn get_trace_parent_from_span(span: &Span) -> String { + let cx = span.context(); + let binding = cx.span(); + let span_context = binding.span_context(); + + format!("00-{}-{}-01", span_context.trace_id(), span_context.span_id()) +} + +pub fn get_trace_id_from_span(span: &Span) -> TraceId { + let cx = span.context(); + get_trace_id_from_context(&cx) +} + +pub fn get_trace_id_from_context(context: &Context) -> TraceId { + let context_span = context.span(); + context_span.span_context().trace_id() +} + pub fn get_trace_id_from_traceparent(traceparent: Option<&str>) -> TraceId { traceparent .unwrap_or("0-0-0-0") @@ -50,11 +68,6 @@ pub fn get_trace_id_from_traceparent(traceparent: Option<&str>) -> TraceId { .unwrap() } -pub fn get_trace_id_from_context(context: &Context) -> TraceId { - let context_span = context.span(); - context_span.span_context().trace_id() -} - pub enum QueryEngineLogLevel { FromEnv, Override(String), diff --git a/query-engine/query-engine/src/server/mod.rs b/query-engine/query-engine/src/server/mod.rs index 72cc7b894f10..6afc72a5f0ad 100644 --- a/query-engine/query-engine/src/server/mod.rs +++ b/query-engine/query-engine/src/server/mod.rs @@ -4,7 +4,7 @@ use hyper::service::{make_service_fn, service_fn}; use hyper::{header::CONTENT_TYPE, Body, HeaderMap, Method, Request, Response, Server, StatusCode}; use opentelemetry::trace::TraceContextExt; use opentelemetry::{global, propagation::Extractor}; -use query_core::helpers::get_trace_id_from_traceparent; +use query_core::helpers::*; use query_core::{ schema::QuerySchemaRenderer, telemetry, ExtendedTransactionUserFacingError, TransactionOptions, TxId, }; @@ -132,30 +132,36 @@ async fn graphql_handler(state: State, req: Request) -> Result