Help Clean Spring Boot for @Async methods inheriting trace context from @Scheduled parent method -
Can someone help with this springboot micrometer tracing problem please: https://stackoverflow.com/questions/79805315/micrometer-trace-for-async-method-and-scheduled-method
Stack Overflow
Micrometer trace for async method and scheduled method
I have a Spring Boot application with scheduled jobs that call async methods. The scheduled method gets a trace ID automatically, but it's not propagating to the async methods unless i manually cre...
7 Replies
⌛ This post has been reserved for your question.
Hey @bluev! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Please note that opinion-based and code review questions are considered off-topic on Stack Overflow. Questions post should consist of exactly one specific question that is factually answerable.
- I would use constructor injection as opposed to field injection
- Doesn't Spring Boot support distributed tracing with Micrometer with no or almost no configuration? Does that not work for you?
- You have this comment:
These async calls lose trace context - Does that mean the two method calls aren't correlated?@dan1st | Daniel Spring Boot 3.x with Micrometer does provide automatic tracing for:
HTTP requests (automatic)
@Scheduled methods (automatic parent trace)
But it does NOT automatically propagate trace context to @Async methods. The trace context is lost when crossing thread boundaries without additional configuration - that's the problem I was solving.
Without trace propagation:
The scheduled method gets traceId=abc123
The async methods get traceId=null (completely disconnected)
They appear as unrelated operations in distributed tracing tools
With the solution I am trying to implement:
All methods share traceId=abc123 (correlated)
Each has unique spanId (parent-child relationship)
They appear as one distributed trace with multiple spans"
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Yeah I just realised that. You might want to take a look at https://github.com/spring-projects/spring-boot/issues/34622#issuecomment-1474042560
GitHub
@Async annotation breaks Trace continuity · Issue #34622 · spring...
Spring Boot: 3.0.3 Using method with @Async annotation causes that Trace context is broken and spans within Async method are not child for outer spans. Regarding this guide: https://github.com/micr...
also this comment for the specific thing you are doing basically: https://github.com/spring-projects/spring-boot/issues/34622#issuecomment-2243465681
GitHub
@Async annotation breaks Trace continuity · Issue #34622 · spring...
Spring Boot: 3.0.3 Using method with @Async annotation causes that Trace context is broken and spans within Async method are not child for outer spans. Regarding this guide: https://github.com/micr...
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.