Skip to content

Within Webflux controller that returns Mono, OpenTelemetry context is not available #38615

Closed as not planned
@jamesmoessis

Description

@jamesmoessis

Versions: 3.1.6 and 3.2.0 (works as expected in 3.1.5)

Using Micrometer OpenTelemetry bridge with W3C context propagation, with Webflux and actuator. Enable automatic reactor context propagation, in 3.2.0 this is is done by spring.reactor.context-propagation=auto.

Minimal reproduction of the issue:

  1. Clone https://github.com/jamesmoessis/tracing-bug-demo
  2. Run the main application
  3. curl -H 'traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' http://localhost:8080/hello
    You will see that the controller errors out, returning 500 because the tracer.getCurrentSpan() returns null.

Message:

java.lang.NullPointerException: Cannot invoke "io.micrometer.tracing.Span.context()" because the return value of "io.micrometer.tracing.Tracer.currentSpan()" is null

Expected: the current span will be available and the trace ID will be returned by the controller. This is the behaviour if you change the SB version to 3.1.5. This seems to only happen when the handler returns a Mono or Flux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions