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.03 s 14.01 s [-0.8%; +1.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.10 s [-2.2%; -0.9%] (maybe better)
startup:petclinic:appsec:Agent 17.19 s 17.43 s [-5.7%; +3.0%] (no difference)
startup:petclinic:iast:Agent 17.31 s 17.57 s [-2.4%; -0.6%] (maybe better)
startup:petclinic:profiling:Agent 17.49 s 17.53 s [-1.5%; +1.1%] (no difference)
startup:petclinic:sca:Agent 17.56 s 17.56 s [-0.9%; +0.8%] (no difference)
startup:petclinic:tracing:Agent 16.52 s 16.64 s [-1.9%; +0.5%] (no difference)

Commit: dff89562 · 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.

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