Skip to content

Tag @Async @Scheduled spring-scheduling spans as errored on exception#12071

Open
ValentinZakharov wants to merge 1 commit into
masterfrom
vzakharov/APMS-20053-spring-async-error
Open

Tag @Async @Scheduled spring-scheduling spans as errored on exception#12071
ValentinZakharov wants to merge 1 commit into
masterfrom
vzakharov/APMS-20053-spring-async-error

Conversation

@ValentinZakharov

Copy link
Copy Markdown
Contributor

What Does This Do

Marks the span of a Spring @Async + @Scheduled method as errored when the method throws. Before, the exception was lost and the trace looked successful.

Fix: add a catch in SpannedMethodInvocation that calls DECORATE.onError(...) and rethrows - the same handling the synchronous path already does. It also calls DECORATE.afterStart(...) so the async span carries the spring-scheduling component/integration tags, like the sync span.

Motivation

With @Async the 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 clean

Untitled-2024-09-10-1730b

Additional 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 spans measured so their errors show up on the stats pages, at the cost of a new APM operation per @Async method. It's modeled on the existing hystrix.measured.enabled / resilience4j.measured.enabled flags.

Out of scope: methods that return an already-failing Future (instead of throwing) are still not tagged.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@ValentinZakharov ValentinZakharov self-assigned this Jul 24, 2026
@ValentinZakharov ValentinZakharov added type: bug fix Bug fix inst: spring Spring instrumentation labels Jul 24, 2026
@ValentinZakharov
ValentinZakharov requested review from a team as code owners July 24, 2026 18:49
@ValentinZakharov
ValentinZakharov requested review from dougqh and ygree and removed request for a team July 24, 2026 18:49

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

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.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit dff8956 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.89 s 14.62 s [+1.0%; +2.8%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.64 s 13.77 s [-1.7%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 16.94 s 16.58 s [+1.2%; +3.1%] (significantly worse)
startup:petclinic:iast:Agent 16.81 s 16.97 s [-1.8%; -0.1%] (maybe better)
startup:petclinic:profiling:Agent 16.80 s 16.93 s [-2.0%; +0.4%] (no difference)
startup:petclinic:sca:Agent 17.00 s 16.84 s [+0.2%; +1.8%] (maybe worse)
startup:petclinic:tracing:Agent 16.11 s 16.25 s [-1.9%; +0.2%] (no difference)

Commit: 68a976bb · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@ValentinZakharov
ValentinZakharov force-pushed the vzakharov/APMS-20053-spring-async-error branch 2 times, most recently from b7fdb82 to 708e3f5 Compare July 26, 2026 07:57
@ValentinZakharov
ValentinZakharov force-pushed the vzakharov/APMS-20053-spring-async-error branch from 708e3f5 to 68a976b Compare July 26, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: spring Spring instrumentation type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant