The `opentelemetry-propagator-ot-trace` library provides a TextMapPropagator for OpenTelemetry that allows traces to be propagated using the proprietary OT Trace context format (e.g., `uber-trace-id` header), which is often associated with older Jaeger clients. It's part of the `opentelemetry-python-contrib` project, currently at version `0.62b0`, and releases frequently alongside other contrib packages.
pip install opentelemetry-propagator-ot-traceVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to register the `OTTracePropagator` globally and use it within a basic OpenTelemetry tracing setup. It includes examples of injecting context into a carrier and extracting it to demonstrate the propagator's function. Ensure you have the `opentelemetry-sdk` installed for this example to run.
Refer to the release notes and migration guides for each new version. Plan for potential minor code adjustments upon upgrade.
For interoperability with most OpenTelemetry-compliant systems, use the default `W3CTraceContextPropagator` (often implicitly enabled) or `CompositeTextMapPropagator` if you need to support multiple formats. Only use `OTTracePropagator` when specifically integrating with legacy Jaeger systems.
For fine-grained control or in complex environments, consider explicitly passing context via `opentelemetry.context.Context` objects rather than relying solely on global propagation. Ensure global settings are configured once at application startup, ideally within your application's entry point.
Always ensure a `TracerProvider` is globally set (`opentelemetry.trace.set_tracer_provider`) and configured with appropriate processors and exporters alongside your propagator setup.
Ensure that the carrier dictionary passed to `extract` contains the 'uber-trace-id' key, even if its value is an empty string, or handle cases where the header might be missing gracefully before calling `extract`. The library's design should ideally not throw an exception in this scenario, as per OpenTelemetry specification. A fixed version of the library (after 0.61b0) should handle this automatically. If using an older version, ensure the carrier has the expected keys.
Install the package using pip: `pip install opentelemetry-propagator-ot-trace`
Ensure the `OTTracePropagator` is set as the global propagator in your application's OpenTelemetry SDK initialization. For example: ```python from opentelemetry import propagators from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from opentelemetry.propagators.composite import CompositePropagator from opentelemetry.propagators.ot_trace import OTTracePropagator # Configure the tracer provider provider = TracerProvider() span_processor = SimpleSpanProcessor(ConsoleSpanExporter()) provider.add_span_processor(span_processor) # Set the global propagator propagators.set_global_textmap(CompositePropagator([OTTracePropagator()])) # Set the global tracer provider from opentelemetry import trace trace.set_tracer_provider(provider) # Your application code ```