traceparent injection into headers
This commit is contained in:
@@ -4,6 +4,7 @@ use opentelemetry::trace::{SpanContext, TraceContextExt, TraceId};
|
||||
use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::IdGenerator};
|
||||
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Make a Carrier for context propagation
|
||||
pub struct ContextCarrier {
|
||||
@@ -76,6 +77,12 @@ impl Extractor for ContextCarrier {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ContextCarrier {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self.data)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ManualContextPropagator {
|
||||
pub root_span: tracing::Span,
|
||||
pub trace_id: TraceId,
|
||||
|
||||
@@ -979,14 +979,10 @@ impl ApiClientCore for Client {
|
||||
// if opentelemetry is activated add the current trace context to the request
|
||||
// TODO featurize opentelemetry
|
||||
use opentelemetry::Context;
|
||||
use opentelemetry::propagation::TextMapPropagator;
|
||||
use opentelemetry_sdk::propagation::TraceContextPropagator;
|
||||
use nym_bin_common::opentelemetry::context::ContextCarrier;
|
||||
|
||||
let context = Context::current();
|
||||
let propagator = TraceContextPropagator::new();
|
||||
let mut carrier = ContextCarrier::new_empty();
|
||||
propagator.inject_context(&context, &mut carrier);
|
||||
let carrier = ContextCarrier::new_with_current_context(Context::current());
|
||||
|
||||
if let Some(traceparent) = carrier.extract_traceparent() {
|
||||
if let Ok(header_value) = HeaderValue::from_str(&traceparent) {
|
||||
req.headers_mut()
|
||||
|
||||
Reference in New Issue
Block a user