Skip to main content

OpenTelemetry Baggage Span Processor

Project description

pypi

The BaggageSpanProcessor reads entries stored in Baggage from the parent context and adds the baggage entries’ keys and values to the span as attributes on span start.

Installation

pip install opentelemetry-processor-baggage

Add this span processor to a tracer provider.

Keys and values added to Baggage will appear on subsequent child spans for a trace within this service and be propagated to external services in accordance with any configured propagation formats configured. If the external services also have a Baggage span processor, the keys and values will appear in those child spans as well.

[!WARNING]

Do not put sensitive information in Baggage.

To repeat: a consequence of adding data to Baggage is that the keys and values will appear in all outgoing HTTP headers from the application.

## Usage

Add the span processor when configuring the tracer provider.

To configure the span processor to copy all baggage entries during configuration:

from opentelemetry.processor.baggage import BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS

tracer_provider = TracerProvider()
tracer_provider.add_span_processor(BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS))

Alternatively, you can provide a custom baggage key predicate to select which baggage keys you want to copy.

For example, to only copy baggage entries that start with my-key:

starts_with_predicate = lambda baggage_key: baggage_key.startswith("my-key")
tracer_provider.add_span_processor(BaggageSpanProcessor(starts_with_predicate))

For example, to only copy baggage entries that match the regex ^key.+:

regex_predicate = lambda baggage_key: baggage_key.startswith("^key.+")
tracer_provider.add_span_processor(BaggageSpanProcessor(regex_predicate))

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file opentelemetry_processor_baggage-0.46b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_processor_baggage-0.46b0.tar.gz
Algorithm Hash digest
SHA256 da7d1c7b022ebaaab946a06bdcf50feb8e2eb79e0a1bbfd97d7902059a3faac0
MD5 73054ad5091ff5b69e4012e2b7272695
BLAKE2b-256 438df8ddbb1c77f7a7f3844c69d1f2827f657674b4927a8f1d1096042b698ecd

See more details on using hashes here.

File details

Details for the file opentelemetry_processor_baggage-0.46b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_processor_baggage-0.46b0-py3-none-any.whl
Algorithm Hash digest
SHA256 4825b2152683767a4adfa920a02bef5be39a2d4134a6c7a3744da6f8a1618aa3
MD5 9ae6d02facf1af931e7e33f4b06226af
BLAKE2b-256 313fad4050efa899f23a134cb18ea4e70c81f3a04457647d1d00fad21c7c7d7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page