Skip to content

Commit

Permalink
fix: Resolve trace propagation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Nov 2, 2023
1 parent ebc2b79 commit cbd4958
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
17 changes: 3 additions & 14 deletions src/telemetry/actix_web_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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!(
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/session.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down

0 comments on commit cbd4958

Please sign in to comment.