Skip to content

Commit

Permalink
inject_context and inject_context_on_context
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Jan 14, 2024
1 parent da4353c commit 26e88c8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use opentelemetry::propagation::{Extractor, Injector};
use opentelemetry::Context;
use tracing_opentelemetry_instrumentation_sdk as otel;

// copy from crate opentelemetry-http (to not be dependants of on 3rd: http, ...)
pub struct HeaderInjector<'a>(pub &'a mut http::HeaderMap);
Expand Down Expand Up @@ -36,13 +37,20 @@ impl<'a> Extractor for HeaderExtractor<'a> {
}
}

pub fn inject_context(context: &Context, headers: &mut http::HeaderMap) {
pub fn inject_context_on_context(context: &Context, headers: &mut http::HeaderMap) {
let mut injector = HeaderInjector(headers);
opentelemetry::global::get_text_map_propagator(|propagator| {
propagator.inject_context(context, &mut injector);
});
}

pub fn inject_context(headers: &mut http::HeaderMap) {
let mut injector = HeaderInjector(headers);
opentelemetry::global::get_text_map_propagator(|propagator| {
propagator.inject_context(&otel::find_current_context(), &mut injector);
});
}

// If remote request has no span data the propagator defaults to an unsampled context
#[must_use]
pub fn extract_context(headers: &http::HeaderMap) -> Context {
Expand Down

0 comments on commit 26e88c8

Please sign in to comment.