From 38a3d18256935741fa56a05bdd4f7d2ff7980b63 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Wed, 7 Aug 2024 17:35:33 -0700 Subject: [PATCH] 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 --- .../annotation/ScheduledAnnotationReactiveSupport.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java index 3f6b1696433b..4cd82cf647de 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java @@ -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. @@ -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); @@ -300,7 +301,6 @@ public void run() { @Override public void onSubscribe(Subscription subscription) { this.subscription = subscription; - this.observation.start(); subscription.request(Integer.MAX_VALUE); }