Hello! Today, we’re going to explore a powerful OpenTelemetry feature that will upgrade development and debugging in distributed system environments: Baggage.

π€ Distributed Tracing, but how do we pass information?
In microservice architectures (MSA), a single request often passes through multiple services. Distributed tracing systems like OpenTelemetry are used to track the flow of the entire request.
But you might have had these thoughts: “Is there a way to pass a user ID known in the first service all the way to the last service?” “Do I have to query the DB in each service to check tenant information?”
The magical feature that solves these problems is Baggage! β¨
π What is Baggage?
Baggage, as the name suggests, is easy to think of as a bag that carries the data we want throughout a journey (Trace), just like luggage.
To explain it more technically, it’s a mechanism to store specific data as key-value pairs within a trace and propagate it from one span to another, even across service boundaries.
- Starting point π«: The upstream service (the service that receives the request first) puts information into Baggage.
- During the journey β‘οΈ: When the request is passed to another service, this Baggage information travels along with it.
- Destination π¬: The downstream service (the service that receives the request later) can open the Baggage and retrieve the information at any time.
π‘ Baggage is really useful in these situations!
The true value of Baggage shines when passing context information.
For example, let’s assume user A is using a ‘premium’ plan.
- Authentication Service (Service A) π
- Receives user A’s login request and confirms that this user is on the ‘premium’ plan.
- Puts plan: premium information into Baggage.
- Order Service (Service B) π
- Receives the request from the authentication service.
- Opens the Baggage and finds plan: premium information!
- Immediately recognizes, “Aha, this user is a premium member!” and applies a premium member-exclusive discount coupon. ποΈ
- Notification Service (Service C) π
- Receives the request from the order service.
- Similarly, through Baggage, it knows this user is a premium member and can send personalized notifications like “Premium member exclusive special delivery has started.”
If Baggage didn’t exist, the order service and notification service would have had to query the database separately to check the user’s plan. π± Thanks to Baggage, unnecessary DB queries are reduced, inter-service dependencies are lowered, and the overall system efficiency is increased!
π What’s the difference from Span Attributes?
You might think, “Oh? Can’t that just be stored as a span attribute?” But there’s an important difference.
- Span Attribute π·οΈ: Information that is dependent only on ‘that single’ span. It’s like attaching a tag; when that span ends, the information ends with it.
- Baggage π: Information carried within the trace context itself, continuously following along for the ‘entire journey’. Like a travel bag, it crosses service boundaries.
β¨ In summary
OpenTelemetry’s Baggage is a very powerful tool for easily and efficiently propagating context information in a distributed environment. By utilizing Baggage to carry various data such as user information, tenant ID, and experiment group information, you can build smarter and higher-performing distributed systems.
Now, how about giving your system a wonderful travel bag called Baggage?
Leave a Reply