Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

OpenTelemetry Baggage Span Processor

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))

BaggageLogProcessor

The BaggageLogProcessor reads entries stored in Baggage from the current context and adds the baggage entries’ keys and values to the log record as attributes on emit.

Add this log processor to a logger provider.

To configure the log processor to copy all baggage entries:

from opentelemetry.processor.baggage import BaggageLogProcessor, ALLOW_ALL_BAGGAGE_KEYS

logger_provider = LoggerProvider()
logger_provider.add_log_record_processor(BaggageLogProcessor(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")
logger_provider.add_log_record_processor(BaggageLogProcessor(starts_with_predicate))

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

regex_predicate = lambda baggage_key: re.match(r"^key.+", baggage_key) is not None
logger_provider.add_log_record_processor(BaggageLogProcessor(regex_predicate))

For example, to copy baggage entries matching multiple predicates:

multiple_predicates = [
    lambda baggage_key: baggage_key.startswith("my-key"),
    lambda baggage_key: baggage_key.startswith("other-key"),
]
logger_provider.add_log_record_processor(BaggageLogProcessor(multiple_predicates))

References

Metadata

Release files for opentelemetry-processor-baggage 0.66b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opentelemetry-processor-baggage 0.66b2
File Size Uploaded Provenance Actions
opentelemetry_processor_baggage-0.66b2.tar.gz 8.8 kB Without provenance Details for opentelemetry_processor_baggage-0.66b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for opentelemetry-processor-baggage 0.66b2
File Interpreter ABI Platform Actions
opentelemetry_processor_baggage-0.66b2-py3-none-any.whl Python 3 none any Details for opentelemetry_processor_baggage-0.66b2-py3-none-any.whl

Total release size: 18.3 kB

Release files / opentelemetry_processor_baggage-0.66b2.tar.gz

Download URL opentelemetry_processor_baggage-0.66b2.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1c5acb98a804d62314e0743a567e959bb44a95224c0442fca422536967370bf6
BLAKE2b-256 checksum
How to use checksums
cc52bbff8c2a7ddaef2865e198082f0b39f8d2124eaafb6ea4bb165c28e4d9f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / opentelemetry_processor_baggage-0.66b2-py3-none-any.whl

Download URL opentelemetry_processor_baggage-0.66b2-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d36888f686562f5f31576c4c1156d6e461c41a75162b7196b317a26194e0b8b
BLAKE2b-256 checksum
How to use checksums
9891f4b8d8ce76de96faf706da93684ef7d1f5df1d85753bbb0c2af0f8dd4492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for opentelemetry-processor-baggage 0.66b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page