Learn to add distributed tracing on Spring Boot @Async and @Scheduled methods using Micrometer Context Propagation Library. Also customize span tracing on specific methods using Micrometer Span Annotations (@NewSpan, @ContinueSpan and @SpanTag).
Distributed Tracing Instrumentation of Spring Boot @Async and @Scheduled methods using Micrometer Context Propagation Library. And using Micrometer Span Annotations (@NewSpan, @ContinueSpan and @SpanTag) to customize span tracing on specific methods.

Micrometer Tracing In Spring Boot — Context Propagation For @Async, @Scheduled, @NewSpan, @ContinueSpan And @SpanTag

Amith Kumar
5 min readJun 6, 2023

--

Prequel: Please check my other blog(s) for setup required to enable Micrometer Tracing in a Spring Boot App (depending on your Tech Stack):

1. OpenTelemetry + Jaeger
2. gRPC + OpenTelemetry + Jaeger
3. Brave + Zipkin
4. gRPC + Brave + Zipkin
5. OpenTelemetry + Zipkin
6. gRPC + OpenTelemetry + Zipkin

In this blog, we will focus on extending the tracing context propagation to Spring Asynchronous methods, Spring Scheduled methods and using Micrometer @NewSpan, @CurrentSpan and @SpanTag to customize Span tracing for specific methods.

@Async

Micrometer offers Context Propagation library, which comes as a transitive dependency to Micrometer Tracing library, which automatically propagates thread locals / context objects to child threads. All we have to do is wrap our Spring ThreadPoolExecutors with Micrometer ContextExecutorService.

There are two ways to approaching this, either by using Spring AsyncConfigurer or Spring TaskDecorator, depending on your use case of whether you have one or multiple thread pools in your app.

1. Single ThreadPool, Customize using AsyncConfigurer

--

--