Tag @Async @Scheduled spring-scheduling spans as errored on exception#12071
Tag @Async @Scheduled spring-scheduling spans as errored on exception#12071ValentinZakharov wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
More details
The async invocation path now decorates the child span and records exceptions before rethrowing, while preserving continuation scope lifecycle for both parent and no-parent executions. No concrete behavioral regression was identified in the changed branches; runtime test execution was blocked by the sandbox lacking the required Gradle distribution access and JDK 25.
🤖 Datadog Autotest · Commit dff8956 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
This comment has been minimized.
This comment has been minimized.
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
What Does This Do
Marks the span of a Spring
@Async+@Scheduledmethod as errored when the method throws. Before, the exception was lost and the trace looked successful.Fix: add a
catchinSpannedMethodInvocationthat callsDECORATE.onError(...)and rethrows - the same handling the synchronous path already does. It also callsDECORATE.afterStart(...)so the async span carries thespring-schedulingcomponent/integration tags, like the sync span.Motivation
With
@Asyncthe method runs on a different thread. The parent span (scheduled.call) closes as soon as the task is submitted - before the body runs — and the exception is thrown later on the async thread, in a child span that had no error handling. So it closed cleanAdditional Notes
Tests:
SpringAsyncTest(default) +SpringAsyncMeasuredForkedTest(flag on)Optional: showing these errors on the Service/Resource pages
Optional - surfacing these errors on the Service/Resource pages.
The errored span is a child, not top-level, so by default it doesn't feed APM trace-metrics (same as any non-top-level span). A new opt-in flag
DD_SPRING_SCHEDULING_MEASURED_ENABLED(default off) marks spring-scheduling spansmeasuredso their errors show up on the stats pages, at the cost of a new APM operation per@Asyncmethod. It's modeled on the existinghystrix.measured.enabled/resilience4j.measured.enabledflags.Out of scope: methods that return an already-failing
Future(instead of throwing) are still not tagged.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]