spring-bootmonitoringtracespring-micrometerobservability

What is "Baggage" in spring boot tracing?


I read spring boot documentaion about observability and see the section about Baggage

You can create baggage with the Tracer API:

@Component
class CreatingBaggage {

  private final Tracer tracer;

  CreatingBaggage(Tracer tracer) {
      this.tracer = tracer;
  }

  void doSomething() {
      try (BaggageInScope scope = this.tracer.createBaggageInScope("baggage1", "value1")) {
          // Business logic
      }
  }

}

This example creates baggage named baggage1 with the value value1. The baggage is automatically propagated over the network if you’re using W3C propagation. If you’re using B3 propagation, baggage is not automatically propagated. To manually propagate baggage over the network, use the management.tracing.baggage.remote-fields configuration property (this works for W3C, too). For the example above, setting this property to baggage1 results in an HTTP header baggage1: value1.

If you want to propagate the baggage to the MDC, use the management.tracing.baggage.correlation.fields configuration property. For the example above, setting this property to baggage1 results in an MDC entry named baggage1.

I haven't come across baggage in context of tracing and can't find any clear definition.

Could you please explain what is Baggage and how it relates to tracing ?


Solution

  • Baggage is key-value pairs that are propagated to other services.
    So without the baggage only default key-value pairs (e.g. traceId) are propagated.
    And the baggage allows you to define what custom key-value pairs, you want to propagate.

    In the example from the doc, also key-value pair "baggage1": "value1" is propagated to other services.

    Pretty common example of baggage usage is to pass userId