user3474541
user3474541

Reputation: 167

spring sleuth baggage propagation not getting propagated/working

We are currently using sleuth 2.2.3.RELEASE, and we couldn't see the field userId passed in http headers are not propagating. Below is our code.

BaggageField REQUEST_ID = BaggageField.create("x-vcap-request-id");
    BaggageField USER_ID = BaggageField.create("userId");
    
    Tracing.newBuilder().propagationFactory(
            BaggagePropagation.newFactoryBuilder(B3Propagation.FACTORY)
            .add(SingleBaggageField.remote(REQUEST_ID))
            .add(SingleBaggageField.newBuilder(USER_ID).addKeyName("baggage-user-id").build())
            .build());

We doubt that some issue in YML file. We tried with all the below options but none is working.

#1 baggage-keys: baggage-user-id 
#2 propagation-keys: baggage-user-id
#3 baggage-keys: user-id 

In logback:

%X{baggage-user-id:-}

We are passing userId as in http header.

Upvotes: 2

Views: 6263

Answers (1)

Marcin Grzejszczak
Marcin Grzejszczak

Reputation: 11179

Please do not create your own instance of tracing. You can create beans that will end up inside the tracing bean.

Here you have an example that uses the latest 3.x api

spring:
 sleuth:
  baggage:
   correlation-fields:
    - TEST-COMMUNICATION-TYPE
   remote-fields:
    - TEST-COMMUNICATION-TYPE

Old, deprecated api

spring:
  application:
    name: service1
  sleuth:
    baggage-keys:
      - baggage
      - key
    log.slf4j.whitelisted-mdc-keys:
      - key

How we retrieve baggage

log.info("Service2: Baggage for [key] is [" + BaggageField.getByName("key") + "]");

How we set the baggage

String baggageKey = "key";
    String baggageValue = "foo";
    BaggageField baggageField = BaggageField.create(baggageKey);
    baggageField.updateValue(baggageValue);

Upvotes: 5

Related Questions