Search code examples
spring-cloud-sleuth

WebClient instrumentation in spring sleuth


I'm wondering whether sleuth has reactive WebClient instrumentation supported.

I did't find it from the document:

Instruments common ingress and egress points from Spring applications (servlet filter, async endpoints, rest template, scheduled actions, message channels, Zuul filters, and Feign client).

My case:

I may use WebClient in either a WebFilter or my rest resource to produce Mono.

And I want:

  • A sub span auto created as child of root span
  • trace info propagated via headers

If the instrumentation is not supported at the moment, Am I supposed to manually get the span from context and do it by myself like this:

OpenTracing instrumentation on reactive WebClient

Thanks

Leon


Solution

  • If you go to Sleuth's documentation for the Finchley release train, and you do find and you search for WebClient you'll find it - https://cloud.spring.io/spring-cloud-static/Finchley.RC2/single/spring-cloud.html#__literal_webclient_literal . In other words we do support it out of the box.

    UPDATE:

    New link - https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/html/integrations.html#sleuth-http-client-webclient-integration

    let me paste the contents

    3.2.2. WebClient

    This feature is available for all tracer implementations.

    We inject a ExchangeFilterFunction implementation that creates a span and, through on-success and on-error callbacks, takes care of closing client-side spans.

    To block this feature, set spring.sleuth.web.client.enabled to false. You have to register WebClient as a bean so that the tracing instrumentation gets applied. If you create a WebClient instance with a new keyword, the instrumentation does NOT work.