-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Instrument Scheduled-annotated methods for observability #29883
Comments
Hi there! I noticed this issue and I'm interested in working on it, but I wanted to ask if it's okay if I take some time to get up to speed on the codebase and the Observation API before I start making changes. I'm a new contributor and I want to make sure that I understand everything before I start making modifications. Please let me know if that's okay, and I'll be sure to keep you updated on my progress as I work on the issue. |
@edyda99 I don't think that this issue is a good first issue for contributing to Spring Framework. Maybe consider contributing on a different one? |
Thanks for letting me know. I'll look for another issue. I'd still like to learn from your contributions on this issue, so I'll do my research and keep an eye on your pull requests. Thanks!! |
Is there any plan to have this issue fixed soon? Since after spring boot 3.x upgrade simply vanished. |
@skshyamal Hope this helps until this is implemented: right now, as a workaround, you can add an |
@jonatan-ivanov could you please show an example of the workaround you described? |
Example with |
I have an initial implementation for this feature and I've scheduled it for 6.1.0-M2 as M1 is about to be released and I'd like to gather some feedback before releasing this in a milestone. I have worked on several designs and will share some thoughts about those here. One solution was to build infrastructure directly on the @Service
public class MyService {
private final ObservationRegistry observationRegistry;
private final TaskScheduler taskScheduler;
public void indexBlogEntries() {
Observation observation = Observation.createNotStarted("index.blogs", this.observationRegistry);
this.taskScheduler.schedule(
observation.wrap(() -> {
List<BlogEntry> blogEntries = findBlogEntries();
observation.lowCardinalityKeyValue("count", String.valueOf(blogEntries.size()));
findBlogEntries().forEach(this::indexBlogEntry);
}), Instant.now());
} Instead, we can focus on the main use case, We can schedule methods like: @Scheduled(cron = "0,10,20,30,40,50 * * * * *")
public void blockingError() {
logger.info("Executing 'blockingError' @Scheduled method");
throw new IllegalStateException("Blocking method failed");
}
@Scheduled(cron = "2,12,22,32,42,52 * * * * *")
public Mono<String> reactiveSuccess() {
return Mono.just("success")
.delayElement(Duration.ofSeconds(2))
.doOnNext(element -> logger.info("Done executing 'reactiveSuccess' @Scheduled method"));
} and see in the logs that the current observation is propagated in the scheduled methods as
If configured accordingly, the application can exports timers as metrics and traces: As we can see in the screenshots above, recorded observations do not have any parent as they're not scheduled in the context of any active observation. In case the scheduled work is cancelled in-flight because the application is being shut down, the |
Avoids a package cycle between config and support (only config->support allowed). See gh-29883
Hey I updated to the spring boot 3.2 SNAPSHOT version which should contain these changes. But I still did not get the traceId and spanId in the @scheduled annotated method logs. Am I missing something or did the changes not fully function? |
@alicanhaman you would need the following auto-configuration, which is not done yet: spring-projects/spring-boot#36119 |
Thanks for providing the missing piece of the puzzle. |
We should consider whether we can safely instrument
@Scheduled
-annotated methods with theObservation
API and report relevant metrics and traces.The text was updated successfully, but these errors were encountered: