Skip to content

Spring-webflux-client instrumentation module issue. #1563

@PavelKhatsimtsau

Description

@PavelKhatsimtsau

I came across an issue related to the logic of io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter class if spring reactive WebClient call is presented in the Reactor upstream chain.
Steps to reproduce:
For example - assume we have to call some external http service 1 but such a call should be preceded by another http service 2 call - in such a case last call resides in the upstream position with regarding to former one.
And parent open telemetry context for http service 1 will contain span under the following key - ContextKey.named("opentelemetry-traces-client-span-key") which is considered as a signal to not create new child span. But according to the logic of
io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter.MonoWebClientTrace publisher - if mentioned above condition will be met - then subscribe method will be left without any subscription - and it is resulting in hanging subscriber chain.
I have found a work around to this problem by turning off spring-webflux-client instrumentation module - otel.instrumentation.spring.webflux.client.enabled=false - and then provides custom module which will be picked up by java Service Loader API.

public void subscribe(CoreSubscriber<? super ClientResponse> subscriber) {
  Context parentContext = Context.current();
  if (!tracer().shouldStartSpan(parentContext)) {
    return;
  }

  ClientRequest.Builder builder = ClientRequest.from(request);
  Context context = tracer().startSpan(parentContext, request, builder);
  try (Scope ignored = context.makeCurrent()) {
    this.next
        .exchange(builder.build())
        .doOnCancel(
            () -> {
              tracer().onCancel(context);
              tracer().end(context);
            })
        .subscribe(new TraceWebClientSubscriber(subscriber, context));
  }
}

But anyway it will be very useful to address such an issue. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions