• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to pass Sleuth traceid and spanid to downstream services while making API calls using restt

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Currently, I am integrating Sleuth into our existing Microservices to enhance the logging mechanism. The MS is built with Spring Boot 2.5.6 and Spring Cloud 2020.0.6 (This has resolved to Spring Cloud Sleuth 3.0.6)

The challenge that I am trying to solve is while making outbound API calls, we are creating RestTemplate using new() keyword instead of managing RestTemplate as Bean. And unfortunately, we don't have the liberty to change the approach to use resttemplate as Bean in order for Sleuth and Brave instrumentation to work seamlessly ( to avoid introducing any breaking changes in the application) to propagate traceid to downstream logs(as mentioned in the official doc). Due to this, the traceids vary in the MS1 and MS2 logs, which makes the tracing difficult.

As I understand from the official doc, Brave registers interceptors to like LazyTraceClientHttpRequestInterceptor & TracingClientHttpRequestInterceptor to add headers like X-B3-Traceid, X-B3-SpanId to the outbound request, I tried to do something similar.

Here is the code for my custom Interceptor:

   

And In my controller class, I have autowired this interceptor:

   

and using this interceptor for the resttemplate call as below:

   

When I am comparing the MS1 and MS2 logs for this API call, the traceids are different.

  • In my understanding the MS2 SHOULD LOOK FOR X-B3 fields to generate the traceids for the log, but it's not using the traceid sent in the request header.
    And also, in the usual setting, the span for the MS2 should be already injected in the headers inside MS1 only before making the call. But when I debug and check Trace id and SpanId in my interceptor they are same.


  • Can anyone help me what am I doing wrong here? And how can I achieve this traceid propagation to downstream service By Creating RestTemplate with New() keyword.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic