0

I am using Sleuth first time need some help. I am currently using sleuth 2.2.3.RELEASE. My requirement is I want to propagate 2 fields product id and product type so that I can read these 2 values from other microservices for that I am using baggage propagation.

1. In one of the microservice in rest API my code is something like this,
BaggageField PRODUCT_ID = BaggageField.create("x-df-product-id");
PRODUCT_ID.updateValue(productId); // I have value of productId that value I want to propogate

BaggageField PRODUCT_TYPE = BaggageField.create("x-df-product-type");
PRODUCT_TYPE.updateValue(productType); // I have value of productType that value I want to propogate

Tracing.newBuilder().propagationFactory(
            BaggagePropagation.newFactoryBuilder(B3Propagation.FACTORY)
            .add(SingleBaggageField.remote(PRODUCT_ID))
            .add(SingleBaggageField.remote(PRODUCT_TYPE))
            .build());

In another microservice, I am reading the values like this:

String baggageProductId=BaggageField.getAllValues().entrySet().stream.filter(e ->"PRODUCT_ID".equalIgnoreCase(e.getKey())).map(Map.Entry::getValue).findFirst().orElse(null);

String baggageProducType=BaggageField.getAllValues().entrySet().stream.filter(e ->"PRODUCT_TYPE".equalIgnoreCase(e.getKey())).map(Map.Entry::getValue).findFirst().orElse(null);

in application.yml these are the entries:
sleuth:
 baggage:
   remoteFields:
    -x-df-product-id
    -x-df-product-type

but I am getting both values baggageProductId and baggageProducType as null.

I am not using span anywhere is that a problem? not sure how can I read these values. can you please help me?
Sandeep
  • 47
  • 1
  • 7

2 Answers2

0

updates: I updated my code like this and it's working fine, BUT...need some help.

  1. application.yml changed to

sleuth: baggage: baggage-keys:

-x-df-product-id

-x-df-product-type

log.slf4.whitelisted-mdc-keys:

-x-df-product-id

-x-df-product-type

2.In Microservice-1 I have the following code

BaggageField baggageFieldProductId = BaggageField.getByName("x-df-product-id"); baggageProductId=baggageFieldProductId.getValue();

BaggageField baggageFieldProductType = BaggageField.getByName("x-df-product-type"); baggageProductType=baggageFieldProductType.getValue();

I inserted the same entries in each application.yml file for each microservice. after that, I am able to retrieve these values in microservice 1, microservice 2, microservice 3 but getting null value in microservice 4. Don't know why? the logic of code retrieval is the same everywhere.

the only difference is my microservices 1,2,3 spring boot version is 2.2.8 and the microservice 4 spring boot version is 2.3.6.

Need some help. really don't know why I am getting null value. Thank You!!!

Sandeep
  • 47
  • 1
  • 7
0

You must be config in you applicaiton.properties

spring.sleuth.propagation-keys[0]= x-df-product-id
spring.sleuth.propagation.tag.whitelisted-keys[0]=x-df-product-id
spring.sleuth.log.slf4j.whitelisted-mdc-keys[0]= x-df-product-id

this source code org.springframework.cloud.sleuth.autoconfig.TraceBaggageConfiguration

hai046
  • 61
  • 1
  • 7