From cbd495834ab1765cbfc99cf771773b0ece4111de Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Thu, 2 Nov 2023 22:49:37 +0000 Subject: [PATCH] fix: Resolve trace propagation issues --- src/telemetry/actix_web_tracing.rs | 17 +++-------------- src/telemetry/session.rs | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/telemetry/actix_web_tracing.rs b/src/telemetry/actix_web_tracing.rs index 7c30f0ac..5d4eb455 100644 --- a/src/telemetry/actix_web_tracing.rs +++ b/src/telemetry/actix_web_tracing.rs @@ -4,7 +4,7 @@ use actix_web::{Error, http::header::HeaderMap}; use actix_service::*; use actix_web::dev::*; use futures::{Future, future::{ok, Ready}, FutureExt}; -use opentelemetry::{propagation::Extractor, global, trace::{TraceContextExt, SpanContext}}; +use opentelemetry::{propagation::Extractor, global}; use tracing::{Instrument, Span, field::display}; use tracing_opentelemetry::OpenTelemetrySpanExt; @@ -48,7 +48,7 @@ where let user_agent = req .headers() .get("User-Agent") - .map(|h| h.to_str().unwrap_or("")) + .and_then(|h| h.to_str().ok()) .unwrap_or(""); let span = tracing::info_span!( @@ -66,21 +66,10 @@ where ); // Propagate OpenTelemetry parent span context information - let mut context = global::get_text_map_propagator(|propagator| { + let context = global::get_text_map_propagator(|propagator| { propagator.extract(&HeaderMapExtractor::from(req.headers())) }); - let span_ref = context.span(); - let span_context = span_ref.span_context(); - println!("Span Context: {:?}-{:?}", span_context.trace_id(), span_context.span_id()); - context = context.with_remote_span_context(SpanContext::new( - span_context.trace_id(), - span_context.span_id(), - span_context.trace_flags().with_sampled(true), - true, - span_context.trace_state().clone(), - )); - span.set_parent(context); let fut = self.service.call(req).map(move |outcome| match &outcome { diff --git a/src/telemetry/session.rs b/src/telemetry/session.rs index f89e06ab..62c31757 100644 --- a/src/telemetry/session.rs +++ b/src/telemetry/session.rs @@ -1,4 +1,4 @@ -use opentelemetry::{global, sdk::{propagation::TraceContextPropagator, trace::Sampler}}; +use opentelemetry::{global, sdk::propagation::TraceContextPropagator}; use opentelemetry_otlp::WithExportConfig; use sentry::ClientInitGuard; use tracing_subscriber::prelude::*;