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.
Comment From: mhalbritter
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.
Comment From: Alos
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?
Comment From: bclozel
@Alos does it work without virtual threads?
Comment From: Alos
@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 :)
Comment From: bclozel
@Alos thanks for letting me know!
Comment From: Alos
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?
Comment From: bclozel
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