{"library":"opentelemetry-processor-baggage","title":"OpenTelemetry Baggage Span Processor","description":"The `opentelemetry-processor-baggage` library provides a `BaggageSpanProcessor` for OpenTelemetry Python, which automatically reads entries stored in Baggage from the parent context and adds their keys and values to the span as attributes upon span start. This enables propagating business context across services. It is part of the `opentelemetry-python-contrib` repository, which has an active release cadence, often with pre-release (`0.x.y.b0`) versions. The current version is 0.62b0.","language":"python","status":"active","last_verified":"Thu May 14","install":{"commands":["pip install opentelemetry-processor-baggage"],"cli":null},"imports":["from opentelemetry.processor.baggage import BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom opentelemetry import baggage, trace\nfrom opentelemetry.context import attach, detach\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleExportSpanProcessor\nfrom opentelemetry.processor.baggage import BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS\n\n# --- Example 1: Copy all baggage entries to span attributes ---\n\n# Configure TracerProvider\nprovider = TracerProvider()\n# Add the BaggageSpanProcessor to copy all baggage entries to span attributes\nprovider.add_span_processor(BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS))\n# Add a console exporter for demonstration\nprovider.add_span_processor(SimpleExportSpanProcessor(ConsoleSpanExporter()))\ntrace.set_tracer_provider(provider)\n\ntracer = trace.get_tracer(__name__)\n\n# Create a context with baggage\n# IMPORTANT: Baggage entries are strings, convert non-string values\nctx = baggage.set_baggage(\"user.id\", \"user123\")\nctx = baggage.set_baggage(\"tenant.id\", \"acme\", context=ctx)\nctx_token = attach(ctx)\n\ntry:\n    with tracer.start_as_current_span(\"parent_span\") as parent_span:\n        print(f\"Parent Span ID: {parent_span.context.span_id:x}\")\n        # Baggage is automatically propagated to child spans\n        with tracer.start_as_current_span(\"child_span\") as child_span:\n            print(f\"Child Span ID: {child_span.context.span_id:x}\")\n            print(f\"Child Span Attributes (should contain baggage): {child_span.attributes}\")\nfinally:\n    detach(ctx_token)\n\nprint(\"\\n--- Example 2: Copy baggage entries with a custom predicate ---\")\n\n# Configure a new provider with a custom predicate\nprovider_custom = TracerProvider()\n# Only copy baggage entries starting with 'my-key'\nstarts_with_predicate = lambda baggage_key: baggage_key.startswith(\"my-key\")\nprovider_custom.add_span_processor(BaggageSpanProcessor(starts_with_predicate))\nprovider_custom.add_span_processor(SimpleExportSpanProcessor(ConsoleSpanExporter()))\ntrace.set_tracer_provider(provider_custom) # Set this new provider\n\ntracer_custom = trace.get_tracer(\"custom_predicate_example\")\n\nctx_custom = baggage.set_baggage(\"my-key-1\", \"value1\")\nctx_custom = baggage.set_baggage(\"other-key\", \"value_ignored\", context=ctx_custom)\nctx_custom_token = attach(ctx_custom)\n\ntry:\n    with tracer_custom.start_as_current_span(\"filtered_span\") as filtered_span:\n        print(f\"Filtered Span ID: {filtered_span.context.span_id:x}\")\n        print(f\"Filtered Span Attributes (should only contain 'my-key-1'): {filtered_span.attributes}\")\nfinally:\n    detach(ctx_custom_token)\n","lang":"python","description":"This quickstart demonstrates how to configure the `BaggageSpanProcessor` with a `TracerProvider` to automatically copy baggage entries as span attributes. It shows both copying all baggage entries and using a custom predicate to filter which entries are copied. Baggage is set on the context and then automatically appears as attributes on subsequent spans.","tag":null,"tag_description":null,"last_tested":"2026-04-25","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-14","installed_version":"0.62b1","pypi_latest":"0.62b1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.4,"avg_import_s":0.44,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.33,"mem_mb":14.7,"disk_size":"23.1M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.36,"mem_mb":14.7,"disk_size":"23.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":0.26,"mem_mb":14.7,"disk_size":"24M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.29,"mem_mb":14.7,"disk_size":"24M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.46,"mem_mb":15.8,"disk_size":"25.4M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.55,"mem_mb":15.8,"disk_size":"25.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.4,"mem_mb":15.8,"disk_size":"26M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.52,"mem_mb":15.8,"disk_size":"26M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.65,"mem_mb":16.2,"disk_size":"17.2M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.81,"mem_mb":16.2,"disk_size":"17.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.61,"mem_mb":16.2,"disk_size":"18M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.68,"mem_mb":16.2,"disk_size":"18M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.35,"mem_mb":14.1,"disk_size":"16.9M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.43,"mem_mb":14,"disk_size":"16.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.34,"mem_mb":14.1,"disk_size":"17M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.39,"mem_mb":14,"disk_size":"17M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.31,"mem_mb":14.4,"disk_size":"22.6M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.36,"mem_mb":14.4,"disk_size":"22.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.9,"import_time_s":0.28,"mem_mb":14.4,"disk_size":"23M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-processor-baggage","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":14.4,"disk_size":"23M"}]}}