Skip to content

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

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
vzakharov/APMS-20053-spring-async-error
Jul 28, 2026
Merged

Tag @Async @Scheduled spring-scheduling spans as errored on exception#12071
gh-worker-dd-mergequeue-cf854d[bot] merged 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

datadog-official Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 57.70% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: d087e1d | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🟡 Java Benchmark SLOs — Performance SLO warning (near threshold)

Suite Status
Startup 🟡 warning

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.02 s 13.94 s [-0.4%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.88 s 13.03 s [-2.0%; -0.4%] (maybe better)
startup:petclinic:appsec:Agent 16.90 s 16.73 s [+0.2%; +1.8%] (maybe worse)
startup:petclinic:iast:Agent 16.88 s 16.42 s [-1.6%; +7.2%] (no difference)
startup:petclinic:profiling:Agent 16.27 s 16.89 s [-7.8%; +0.5%] (no difference)
startup:petclinic:sca:Agent 16.88 s 16.70 s [-0.1%; +2.2%] (no difference)
startup:petclinic:tracing:Agent 16.09 s 16.05 s [-0.8%; +1.3%] (no difference)

Commit: d087e1d7 · 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 3 times, most recently from 708e3f5 to 68a976b Compare July 26, 2026 08:10
@vandonr

vandonr commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@codex review

Comment thread metadata/agent-jar-checks.properties Outdated
Comment on lines -3 to -4
# Max agent jar size in bytes. Raise only when the size growth is intentional (~33.02 MiB).
jar.size.budget = 34619392

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.

I think you could bump it by a bit more than 10KB because otherwise we're going to be coming here often 🤔

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.

or maybe 10KB is plenty enough for just code changes, and it should be kept pretty tigh, idk

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 68a976bb4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@vandonr vandonr 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.

LGTM

@ValentinZakharov
ValentinZakharov added this pull request to the merge queue Jul 28, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 28, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-28 13:38:43 UTC ℹ️ Start processing command /merge


2026-07-28 13:38:50 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-07-28 13:52:03 UTCMergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 87cc705:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.
Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 28, 2026
@ValentinZakharov
ValentinZakharov force-pushed the vzakharov/APMS-20053-spring-async-error branch from fa42e74 to d087e1d Compare July 28, 2026 17:27
@ValentinZakharov
ValentinZakharov added this pull request to the merge queue Jul 28, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 28, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-28 18:46:15 UTC ℹ️ Start processing command /merge


2026-07-28 18:46:21 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-07-28 19:33:20 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 28, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit a92b3a6 into master Jul 28, 2026
605 of 607 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the vzakharov/APMS-20053-spring-async-error branch July 28, 2026 19:33
@github-actions github-actions Bot added this to the 1.65.0 milestone Jul 28, 2026
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.

3 participants