lens.propagation

View as Markdown

W3C TraceContext / Baggage propagation helpers.

Module Contents

Functions

NameDescription
extract_contextExtract span context from carrier and return an OTel Context.
inject_contextInject the current span context into carrier (W3C TraceContext + Baggage).

API

lens.propagation.extract_context(
carrier: dict
) -> opentelemetry.context.Context

Extract span context from carrier and return an OTel Context.

Use this to resume a distributed trace from incoming headers/metadata.

Parameters:

carrier
dict

A dict containing W3C traceparent (and optionally tracestate, baggage) headers.

Returns: context.Context

An OTel Context. If no valid trace context is present the returned

lens.propagation.inject_context(
carrier: dict
) -> None

Inject the current span context into carrier (W3C TraceContext + Baggage).

Use this to propagate trace context across process boundaries, e.g. into HTTP header dicts or gRPC metadata.

Parameters:

carrier
dict

A mutable dict that will receive the traceparent (and optionally tracestate, baggage) headers.