Module opentelemetry_jaeger_propagator::propagator

source ·
Expand description

The Jaeger propagator propagates span contexts in Jaeger propagation format.

Cross-cutting concerns send their state to the next process using Propagators, which are defined as objects used to read and write context data to and from messages exchanged by the applications. Each concern creates a set of Propagators for every supported Propagator type.

Note that a jaeger header can be set in http header or encoded as url.

§Examples

// setup jaeger propagator
global::set_text_map_propagator(JaegerPropagator::default());
// You also can init propagator with custom header name
// global::set_text_map_propagator(JaegerPropagator::with_custom_header("my-custom-header"));

// before sending requests to downstream services.
let mut headers = std::collections::HashMap::new(); // replace by http header of the outgoing request
let caller_span = global::tracer("caller").start("say hello");
let cx = Context::current_with_span(caller_span);
global::get_text_map_propagator(|propagator| {
    propagator.inject_context(&cx, &mut headers); // propagator serialize the tracing context
});
// Send the request..


// Receive the request sent above on the other service...
// setup jaeger propagator
global::set_text_map_propagator(JaegerPropagator::new());
// You also can init propagator with custom header name
// global::set_text_map_propagator(JaegerPropagator::with_custom_header("my-custom-header"));

let headers = std::collections::HashMap::new(); // replace this with http header map from incoming requests.
let parent_context = global::get_text_map_propagator(|propagator| {
     propagator.extract(&headers)
});

// this span's parent span will be caller_span in send_request functions.
let receiver_span = global::tracer("receiver").start_with_context("hello", &parent_context);

Structs§

  • Propagator implements the [Jaeger propagation format].