The `opentelemetry-propagator-gcp` library provides a TextMapPropagator for OpenTelemetry that handles the Google Cloud Trace context header (`x-cloud-trace-context`). It allows OpenTelemetry traces to be linked with existing traces in Google Cloud, facilitating interoperability. This library is part of the `opentelemetry-operations-python` project, is actively maintained, and follows a regular release cadence, typically monthly or bi-monthly, aligned with other OpenTelemetry SDK updates.
pip install opentelemetry-propagator-gcpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to register the `CloudTracePropagator` and then use the global `TextMapPropagator` to extract trace context from incoming headers and inject it into outgoing headers. This is crucial for maintaining trace continuity across services within and outside Google Cloud.
Ensure `propagators.set_global_textmap_propagator(CompositePropagator([CloudTracePropagator(), ...]))` is called early in your application's lifecycle, before any tracing occurs.
When setting the global propagator, construct a `CompositePropagator` like: `CompositePropagator([CloudTracePropagator(), W3CTraceContextPropagator()])`.
Always install `opentelemetry-propagator-gcp` alongside the rest of your OpenTelemetry dependencies, ensuring all are compatible. Consult the `opentelemetry-operations-python` repository for recommended dependency versions or constraints in `pyproject.toml`.
Be aware that only `x-cloud-trace-context` is handled for HTTP propagation. For other protocols or legacy systems, custom propagators or manual context handling might be required.