Skip to main content
Pre-release

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

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

Download files

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

Source Distribution

opentelemetry_processor_baggage-0.65b0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

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

File metadata

File hashes

Hashes for opentelemetry_processor_baggage-0.65b0.tar.gz
Algorithm Hash digest
SHA256 a1007c778e2737e28bae4b1e8b5d135907d03182ad40dfc1558416548209e491
MD5 8be89d74f229dca32437202eec83c40b
BLAKE2b-256 10b3870c377673c44dcf716e78006ec8bbdb5e14ca9b1c2290bb6711534a3828

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_processor_baggage-0.65b0-py3-none-any.whl
Algorithm Hash digest
SHA256 eef686d03220c6969f56c02e7763f3200392fb6af4b797732e3e80bbd024ba66
MD5 2c0f2b27b547495d5022348fb56a2dbb
BLAKE2b-256 f90c6bd5aa64157053acb5c0c908a79e09ece449371b6d70d28eb45753d1e49d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page