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
propagator
required:TextMapPropagator
Returns
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
carrier
required:object
A mutable mapping (typically a dict) to write
propagation headers into.
context
:Optional[Context]
The OTel context to inject. Defaults to the current Judgment context.
None
setter
:Setter
Strategy for writing values into the carrier.
default_setter
Returns
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
carrier
required:object
A mapping containing propagation headers
(e.g. request.headers).
context
:Optional[Context]
Base context to merge into. Defaults to the current Judgment context.
None
getter
:Getter
Strategy for reading values from the carrier.
default_getter
Returns
opentelemetry.context.Context - A new Context with the extracted trace and baggage data.