I have two spring boot services A and B.
Service A uses a RestTemplate to call an endpoint in Service B.
RestTemplate and the call in Service A looks like below:
@Bean
public RestTemplate simpleRestTemplate() {
return new RestTemplate();
}
restTemplate.exchange(
endpoint,
HttpMethod.GET,
HttpEntity.EMPTY,
new ParameterizedTypeReference<>() {
}
);
Now, I notice that the traceId logged in Service A is different from the one logged in Service B. How do I make the traceId Service A to propagate to Service B when an endpoint is called using the RestTemplate?
I'm adding a solution that worked for me. Hope it helps someone.
I added gradle dependency below:
I built RestTemplate as below: