Skip to content

The non-volatile wrapped flag is toggled in apply() on wrappers that are cached and shared between threads. #1517

Closed

Description

@olegz

The non-volatile wrapped flag is toggled in apply() on wrappers that are cached and shared between threads. A concurrent call can skip the around-advice, which is where observability hooks run.

Activity

  1. nrheckman-afero commented on Nov 19, 2026

    @nrheckman-afero

    We're hitting this on Spring Cloud Function 5.0.5 (Spring Cloud 2025.1.4, Spring Boot 4.1.2) with Spring Cloud Stream and the GCP Pub/Sub binder (Spring Cloud GCP 8.3.1), using Micrometer Tracing with the Brave bridge and Hooks.enableAutomaticContextPropagation().

    Impact: the binder delivers on several subscriber threads, so concurrent messages regularly see wrapped == true and skip ObservationFunctionAroundWrapper. Those invocations get no <definition> process observation. The consumer runs only under the binder's Brave on-message span, which is not a Micrometer Observation, so block() captures no observation into the Reactor Context. Any client call made after a thread hop then starts a new trace instead of joining the message's trace. That covers WebClient after an RSocket response, RSocket, and Lettuce reactive commands, since Lettuce's MicrometerTracing reads the parent only from the Reactor Context.

    In one sampling window:

    • Service A: 27 of 49 traced messages had no process span, and their downstream HTTP calls showed up as separate root traces.
    • Service B: 17 of 60 traced messages had no process span, and every Redis command in them became a root trace.

    Workaround until #1521 is released: decorate each consumer so it opens an observation only when none is current. When SCF's own process observation is present, this adds nothing.

    public static <T> Consumer<T> observed(ObservationRegistry registry, String name, Consumer<T> consumer) {
        return input -> {
            if (registry.getCurrentObservation() != null) {
                consumer.accept(input);
                return;
            }
            Observation.createNotStarted("stream.consumer", registry)
                    .contextualName(name + " process")
                    .lowCardinalityKeyValue("consumer", name)
                    .observe(() -> consumer.accept(input));
        };
    }

    With this in place, the root client traces went to zero, and the fallback fires for the concurrent messages SCF skips.

  2. added this to the 5.1.1 milestone on Nov 21, 2026
  3. added a commit that references this issue on Nov 21, 2026
  4. added a commit that references this issue on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions