Skip to content
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

Auto-configure ObservationRegistry in ScheduledTaskRegistrar for scheduled tasks observations #36119

Closed
Tracked by #35776
bclozel opened this issue Jun 29, 2023 · 7 comments
Assignees
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Jun 29, 2023

As of Spring Framework 6.1.0-M2, a new instrumentation observes the execution of @Scheduled annotated methods. See spring-projects/spring-framework#29883.

To support this feature automatically, Spring Boot should configure the ObservationRegistry with a SchedulingConfigurer. As far as I understand, a SchedulingConfigurer bean is currently considered as a signal for auto-configuration backoff so we might need to tweak the approach here.

@bclozel bclozel added type: enhancement A general enhancement theme: observability Issues related to observability labels Jun 29, 2023
@bclozel bclozel added this to the 3.2.x milestone Jun 29, 2023
@mhalbritter
Copy link
Contributor

mhalbritter commented Jun 30, 2023

I've got something working in https://github.com/mhalbritter/spring-boot/tree/mh/36119-auto-configure-observationregistry-in-scheduledtaskregistrar-for-scheduled-tasks-observations

This removes SchedulingConfigurer as a signal to back-off for the ThreadPoolTaskScheduler. And I had to update to Spring Framework 6.1.0-SNAPSHOT.

@Alos
Copy link

Alos commented Feb 6, 2024

I've upgraded to Java 21 and Spring 3.2, turned on virtual threads and I still can't see spanIds in the logs, am I missing something else?

@bclozel
Copy link
Member Author

bclozel commented Feb 6, 2024

@Alos does it work without virtual threads?

@Alos
Copy link

Alos commented Feb 6, 2024

@bclozel after some tinkering, it looks like the issue might related to the Micrometer implementation with Spring Cloud GCP and/or the permissions needed to populate spanIds.

Thanks for the comment tho :)

@bclozel
Copy link
Member Author

bclozel commented Feb 6, 2024

@Alos thanks for letting me know!

@Alos
Copy link

Alos commented Feb 12, 2024

Ahhh I discovered something @bclozel, it looks like @Async annotated methods are not instrumented. For example:

 @Scheduled(
      fixedDelayString = "2",
      timeUnit = TimeUnit.SECONDS)
 @Async
  public void doSomething() throws InterruptedException {
    log.info(
        "->doSomething thread name: {} Id: {}",
        Thread.currentThread().getName(),
        Thread.currentThread().threadId());
    Thread.sleep(10000);
  }

Would not have any spanIds. Is the correct way to enable this to create a custom ThreadPoolTaskScheduler and add the instrumentation manually?

@bclozel
Copy link
Member Author

bclozel commented Feb 12, 2024

I think this is similar to the event listener support for async: https://docs.spring.io/spring-framework/reference/integration/observability.html#observability.application-events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants