Propagation
get_global_textmap()
Return the active composite propagator (W3C TraceContext + Judgment Baggage).
def get_global_textmap() -> TextMapPropagator:
Returns
TextMapPropagator
set_global_textmap()
Replace the global text-map propagator.
def set_global_textmap(propagator) -> None:
Parameters
propagatorTextMapPropagator
TextMapPropagatorReturns
None
inject()
Inject trace context and baggage into an outgoing carrier (e.g. HTTP headers).
Call this before making an outbound HTTP request to propagate the current trace across service boundaries.
headers = {}
propagation.inject(headers)
response = requests.get("https://api.example.com", headers=headers)
def inject(carrier, context=None, setter=default_setter) -> None:
Parameters
carrierobject
A mutable mapping (typically a dict) to write propagation headers into.
objectcontext?Optional[Context]
The OTel context to inject. Defaults to the current Judgment context.
Optional[Context]Nonesetter?Setter
Strategy for writing values into the carrier.
Setterdefault_setterReturns
None
extract()
Extract trace context and baggage from an incoming carrier.
Call this when handling an inbound request to continue an existing trace started by an upstream service.
ctx = propagation.extract(request.headers)
with Tracer.start_as_current_span("handle-request", context=ctx):
...
def extract(carrier, context=None, getter=default_getter) -> opentelemetry.context.Context:
Parameters
carrierobject
A mapping containing propagation headers (e.g. request.headers).
objectcontext?Optional[Context]
Base context to merge into. Defaults to the current Judgment context.
Optional[Context]Nonegetter?Getter
Strategy for reading values from the carrier.
Getterdefault_getterReturns
opentelemetry.context.Context - A new Context with the extracted trace and baggage data.