question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Distributed tracing: How should I?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cero-tcommented, Mar 7, 2020

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.

0reactions
artursouzacommented, Oct 12, 2020

Closing this issue. Please, use SDK version 0.9.0 or greater to use W3C tracing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Distributed Tracing? How it Works & Use Cases
Distributed tracing helps measure the time it takes to complete key user actions, such as purchasing an item. Traces can help identify backend...
Read more >
Distributed tracing: A Complete Guide - Lightstep
Distributed tracing provides end-to-end visibility and reveals service dependencies – showing how the services respond to each other. By being able to visualize ......
Read more >
What is distributed tracing and why does it matter? - Dynatrace
Distributed tracing is a method of observing requests as they propagate through distributed cloud environments. Distributed tracing follows an ...
Read more >
Why Distributed Tracing is Essential for APM - New Relic
Distributed tracing is the ability to trace a solution to track and observe service requests as they flow through distributed systems by collecting...
Read more >
What Is Distributed Tracing? | How it Works - Honeycomb
Distributed tracing is a technique used to monitor and observe requests as they flow through your distributed services or microservices-based ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found