I have a Parent that calls another microservice (child) with webclient.
public Mono<Product> productFromIntegrator() {
String url = "http://localhost:8282/product";
return Mono.deferContextual(contextView -> {
try (ContextSnapshot.Scope scope = ContextSnapshot.setThreadLocalsFrom(contextView,
ObservationThreadLocalAccessor.KEY)) {
LOG.info("<ACCEPTANCE_TEST> <TRACE:{}> Hello from producer", tracer.currentSpan().context().traceId());
LOG.info("Service Called");
return webClient.get().uri(url)
.retrieve().bodyToMono(Product.class).log(LOG.getName(), Level.FINE)
.onErrorMap(WebClientException.class, ex -> {
LOG.warn("Error retrieving Product");
return ex;
});
}
});
}
RestController from Child:
@Autowired
private final Service service;
private final Tracer tracer;
public Controller(Service service, Tracer tracer) {
this.service = service;
this.tracer = tracer;
}
@GetMapping(value = "/product")
public Mono<Product> getProduct() {
return Mono.deferContextual(contextView -> {
try (ContextSnapshot.Scope scope = ContextSnapshot.setThreadLocalsFrom(contextView,
ObservationThreadLocalAccessor.KEY)) {
LOG.info("<ACCEPTANCE_TEST> <TRACE:{}> Hello from producer", tracer.currentSpan().context().traceId());
LOG.info("Service Called");
return this.service.getProduct();
}
});
}
The Child is not getting the TraceId from Parent, it is creating a new Obsevation Object. Any suggestion/example on how to propagate the TraceId from Parent to Child?