Search code examples
javaspring-webfluxspring-cloud-sleuthzipkinopentracing

Create traceID in a non-Spring application


Small question on how to create traceID, but when the app is not Spring-based please.

My application is the first, the initiator of a HTTP call. Therefore, the app can be considered as client.

The destinations, the servers, are all Spring Boot Spring Cloud based web applications. I would like to emphasize, while the servers are Spring-based, me, the client, I am not a Spring Boot app.

While my app, being a non-Spring app, I do use the Spring Webflux WebClient in order to create the HTTP requests to those servers. To emphasize, it is not because I use the Spring Webflux WebClient, that makes the app a Spring app!

Since I am the first of the call chain, I would like to create some kind of traceID, so the subsequent services will carry the traceID I created.

I am puzzled as what should come inside this piece of code that I tried:

final var  response = webClient.post().uri("http://some-third-party-api.com/someroute").header("X-B3-TraceId", "How to create a traceID?").body(BodyInserters.fromValue(payload)).retrieve().bodyToMono(String.class).block();

Therefore, I would like to ask, being the first, the HTTP call initiator, using a Spring Webflux WebClient, but in a non-Spring app, how to create those traceID so the subsequent services get the one that I created?


Solution

  • By default Sleuth is using OpenZipkin's tracing library called Brave. If your application is java-based, you can use Brave, if not, you can find official implementations for other platforms in the OpenZipkin org or official and non-official ones in https://zipkin.io/pages/tracers_instrumentation.html