Package brave.baggage

Class BaggagePropagation<K>

java.lang.Object
brave.baggage.BaggagePropagation<K>
All Implemented Interfaces:
Propagation<K>

public final class BaggagePropagation<K>
extends Object
implements Propagation<K>
This implements in-process and remote baggage propagation.

For example, if you have a need to know the a specific request's country code, you can propagate it through the trace as HTTP headers.


 import brave.baggage.BaggagePropagationConfig.SingleBaggageField;

 // Configure your baggage field
 COUNTRY_CODE = BaggageField.create("country-code");

 // When you initialize the builder, add the baggage you want to propagate
 tracingBuilder.propagationFactory(
   BaggagePropagation.newFactoryBuilder(B3Propagation.FACTORY)
                     .add(SingleBaggageField.remote(COUNTRY_CODE))
                     .build()
 );

 // later, you can tag that country code
 Tags.BAGGAGE_FIELD.tag(COUNTRY_CODE, span);
 

See BaggageField for baggage usage examples.

Customizing propagation keys

BaggagePropagationConfig.SingleBaggageField.remote(BaggageField) sets the name used as a propagation key (header) to the lowercase variant of the field name. You can override this by supplying different key names. Note: they will be lower-cased.

For example, the following will propagate the field "x-vcap-request-id" as-is, but send the fields "countryCode" and "userId" on the wire as "baggage-country-code" and "baggage-user-id" respectively.


 import brave.baggage.BaggagePropagationConfig.SingleBaggageField;

 REQUEST_ID = BaggageField.create("x-vcap-request-id");
 COUNTRY_CODE = BaggageField.create("countryCode");
 USER_ID = BaggageField.create("userId");

 tracingBuilder.propagationFactory(
     BaggagePropagation.newFactoryBuilder(B3Propagation.FACTORY)
                       .add(SingleBaggageField.remote(REQUEST_ID))
                       .add(SingleBaggageField.newBuilder(COUNTRY_CODE)
                                              .addKeyName("baggage-country-code").build())
                       .add(SingleBaggageField.newBuilder(USER_ID)
                                              .addKeyName("baggage-user-id").build())
                       .build()
 );
 
Since:
5.11
See Also:
BaggageField, BaggagePropagationConfig, BaggagePropagationCustomizer, CorrelationScopeDecorator