Skip to content

Commit

Permalink
Start Observation before scope open for Scheduled operation
Browse files Browse the repository at this point in the history
When ScheduledAnnotationReactiveSupport adds the Observation to the
context, Reactor opens a scope through the Context Propagation API.
This happens before TrackingSubscriber would start the Observation and
opening a scope without starting an Observation is invalid.

This change moves the Observation start before the scope opening.

Closes gh-33349
  • Loading branch information
jonatan-ivanov authored and snicoll committed Aug 8, 2024
1 parent 6c74fee commit 38a3d18
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -244,6 +244,7 @@ public void run() {
private void subscribe(TrackingSubscriber subscriber, Observation observation) {
this.subscriptionTrackerRegistry.add(subscriber);
if (reactorPresent) {
observation.start();
Flux.from(this.publisher)
.contextWrite(context -> context.put(ObservationThreadLocalAccessor.KEY, observation))
.subscribe(subscriber);
Expand Down Expand Up @@ -300,7 +301,6 @@ public void run() {
@Override
public void onSubscribe(Subscription subscription) {
this.subscription = subscription;
this.observation.start();
subscription.request(Integer.MAX_VALUE);
}

Expand Down

0 comments on commit 38a3d18

Please sign in to comment.