Distributed tracing: How should I?
See original GitHub issueI tried distributed tracing using Java SDK, Zipkin, and Dapr, but I couldn’t.
When I passed the “x-correlation-id” to the other service running on Dapr using RestTemplate via HTTP header, they were well distributed traced. But when I tried same thing using DaprClientHttp via metadata, the correlation id wasn’t passed.
Here’s code snipet using DaprClient which doesn’t work.
DaprClient client = new DaprClientBuilder().build();
Map<String, String> metadata = Map.of("x-correlation-id", corId);
client.invokeService(Verb.POST, "example1", "someMethod", Map.of("message", "Hello world"), metadata)
.block();
client.invokeService(Verb.GET, "example1", "someMethod", metadata, Map.class)
.block();
And here’s code snipet using RestTemplate which works fine.
// (There're given corId)
HttpHeaders headers = new HttpHeaders();
headers.add("x-correlation-id", corId);
var entity = new HttpEntity<>(Map.of("message", "Hello world"), headers);
restTemplate.exchange(baseUrl + "/invoke/example1/method/someMethod",
HttpMethod.POST, entity, Void.class);
restTemplate.exchange(baseUrl + "/invoke/example1/method/someMethod",
HttpMethod.GET, new HttpEntity<>(headers), Map.class).getBody();
Both of above works fine as functions but the former one doesn’t propagate the correlation id to example1’s someMethod.
In any case, I don’t think the correct way is to use metadata to propagate the correlation id, and adding metadata as an argument to the saveState method or getState method of DaprClient class might be cumbersome. Is there any good way to improve the Java SDK for distributed tracing? For example, it would be nice to have a mechanism to store and retrieve correlation id in a specific thread local context or something like MDC.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (8 by maintainers)
Top GitHub Comments
Thank you for answering. As you mentioned, thread context doesn’t work in the Reactor chain. But as far as I confirmed, when I used Spring WebFlux and Spring Cloud Sleuth I could get the correct correlation id from the thread context (MDC) in the Reactor Chain. I haven’t read the code enught, but I guess that these are the implementations that pass the correlation id from the parent thread context to the reactor’s sub thread context.
https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/ReactorSleuthMethodInvocationProcessor.java
https://github.com/spring-cloud/spring-cloud-sleuth/tree/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor
Although it uses spring container to insert the additional processing, I think we can do the similar thing without spring.
Closing this issue. Please, use SDK version 0.9.0 or greater to use W3C tracing.