Overview
Baggage is a mechanism for propagating name-value pairs across service boundaries. It allows you to attach custom attributes to telemetry context that can be accessed by any service in the call chain.What is baggage?
Baggage is a set of key-value pairs that:- Travels with the context across process boundaries
- Can be read and modified by any service
- Follows the W3C Baggage specification
- Has size and count limits for safety
Limits
- Maximum entries: 64 key-value pairs
- Maximum size: 8192 bytes total
Basic usage
Creating baggage
Reading baggage
Baggage with metadata
BaggageExt trait
TheBaggageExt trait extends Context with baggage management:
Propagation
Baggage automatically propagates when using theBaggagePropagator:
Complete example
Service A (upstream)
Service B (downstream)
Common use cases
1. User identification
2. Request tracking
3. Feature flags
4. Multi-tenancy
Iterating over baggage
Adding baggage to telemetry
Add to spans
Add to metrics
Best practices
Explicit attachment - Remember that baggage values don’t automatically appear in telemetry. You must explicitly read and attach them.
Validation - Baggage keys must follow RFC2616 token format. Invalid keys are rejected.
Baggage vs span attributes
Related
Propagators
Configure context propagation
Context propagation
Learn about context flow