Skip to content

Commit 38a3d18

Browse files
jonatan-ivanovsnicoll
authored andcommitted
Start Observation before scope open for Scheduled operation
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
1 parent 6c74fee commit 38a3d18

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -244,6 +244,7 @@ public void run() {
244244
private void subscribe(TrackingSubscriber subscriber, Observation observation) {
245245
this.subscriptionTrackerRegistry.add(subscriber);
246246
if (reactorPresent) {
247+
observation.start();
247248
Flux.from(this.publisher)
248249
.contextWrite(context -> context.put(ObservationThreadLocalAccessor.KEY, observation))
249250
.subscribe(subscriber);
@@ -300,7 +301,6 @@ public void run() {
300301
@Override
301302
public void onSubscribe(Subscription subscription) {
302303
this.subscription = subscription;
303-
this.observation.start();
304304
subscription.request(Integer.MAX_VALUE);
305305
}
306306

0 commit comments

Comments
 (0)