Skip to content

Commit 26e88c8

Browse files
committed
inject_context and inject_context_on_context
1 parent da4353c commit 26e88c8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/http.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use opentelemetry::propagation::{Extractor, Injector};
66
use opentelemetry::Context;
7+
use tracing_opentelemetry_instrumentation_sdk as otel;
78

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

39-
pub fn inject_context(context: &Context, headers: &mut http::HeaderMap) {
40+
pub fn inject_context_on_context(context: &Context, headers: &mut http::HeaderMap) {
4041
let mut injector = HeaderInjector(headers);
4142
opentelemetry::global::get_text_map_propagator(|propagator| {
4243
propagator.inject_context(context, &mut injector);
4344
});
4445
}
4546

47+
pub fn inject_context(headers: &mut http::HeaderMap) {
48+
let mut injector = HeaderInjector(headers);
49+
opentelemetry::global::get_text_map_propagator(|propagator| {
50+
propagator.inject_context(&otel::find_current_context(), &mut injector);
51+
});
52+
}
53+
4654
// If remote request has no span data the propagator defaults to an unsampled context
4755
#[must_use]
4856
pub fn extract_context(headers: &http::HeaderMap) -> Context {

0 commit comments

Comments
 (0)