-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable automatic creation of observation on some scheduled tasks #41570
Comments
I'm not sure I understand the use case here.
How would you detect that a scheduled method would be on pause? What do you mean by that? Would it require the execution to be ongoing?
All the solutions you've described could be implemented with an I'm probably missing something here. |
Hi @bclozel
I have some scheduled tasks that are triggered frequently, but can decide by themselves to be on pause until a given time depending on some conditions.
Well, the problem is with children spans : if the ObservationPredicate says false, a NOOP observation is created and becomes the current observation. If the code called by the scheduled task creates also an observation, as its parent span is a NOOP, it will also be a NOOP. That's why it works for behavior 2, the scheduled task and children spans are NOOP. For behavior 3, I want children spans to be actual spans. With the ObservationPredicate, I can't have behavior 2 and behavior 3 depending on the use case. |
I see, thanks for the feedback. So it sounds like you would like to change the active/noop status of an observation after it's been created. Unfortunately, I don't think there is anything we can do in the Spring Framework |
Some additional thoughts. The In your case, I understand that you probably don't want to record metrics for "paused jobs" as they're very short lived and are probably skewing numbers. For this, I think you could maybe let the observation be recorded, but add metadata to the observation context stating that it's been paused. This way, you can build your metrics dashboard using this dimension and avoid conflating paused/unpaused jobs. |
In our application, we have several scheduled tasks annotated with
@Scheduled
. We have different requirements regarding observability (tracing) depending on the scheduled task :Behavior 1 is the default behavior in spring boot, it works well !
For behavior 2, we implemented an ObservationPredicate that filters out observation generated by scheduled tasks we don't want to observe, which prevents generating the automatic observation for the scheduled task, and eventually sub-observations.
For behavior 3, I didn't find a clean way to implement it. I tried a few things : they work, but not very clean.
First, I disabled the auto-configuration that makes observations created automatically, but then I have to manually observe each scheduled task for which I want behavior 1.
Then, I tried the following :
DisableAutomaticObservation
ScheduledAnnotationBeanPostProcessor
and overridecreateRunnable()
:or
SchedulingConfiguration
and replace it with an implementation returning my implementation ofScheduledAnnotationBeanPostProcessor
This implementation works but it means tweaking spring boot configuration and requires copy/pasting spring boot code to properly override method.
Do you see a clean way to implement behavior 3 ?
Otherwise, would it be possible to include such capability in spring boot (for example, with an annotation like
DisableAutomaticObservation
, it would be a simple modification ofScheduledAnnotationBeanPostProcessor
)The text was updated successfully, but these errors were encountered: