Skip to content

Expose isFinished() on AgentSpan#11884

Open
pavlokhrebto wants to merge 2 commits into
masterfrom
pavlo.khrebto/dd-span-finished-state-agent-span
Open

Expose isFinished() on AgentSpan#11884
pavlokhrebto wants to merge 2 commits into
masterfrom
pavlo.khrebto/dd-span-finished-state-agent-span

Conversation

@pavlokhrebto

@pavlokhrebto pavlokhrebto commented Jul 8, 2026

Copy link
Copy Markdown

What Does This Do

Adds a non-breaking default boolean isFinished() to the AgentSpan interface (internal-api), surfacing the finished state that DDSpan already tracks (durationNano != 0) so other modules can query it without reaching into dd-trace-core.

  • DDSpan's existing isFinished() overrides the default — no behavior change.
  • The TrackingSpanDecorator test wrapper (the only AgentSpan wrapper) delegates to its wrapped span.
  • Leaf / synthetic spans (NoopSpan, etc.) keep the false default.
  • Adds a DDSpanTest case asserting false before finish / true after, exercised through the AgentSpan interface.

Motivation

The FFE span-enrichment interceptor (#11658) needs to tell a truly-finished local-root span from a still-running one — with long-running traces enabled, a periodic flush emits the still-running root, and the interceptor currently mis-reads "root present in the flushed batch" as "trace finished". It also wants to resolve the root in O(1) instead of scanning the batch. Both need a finished signal on the interface it uses (AgentSpan). DDSpan already has it, but the interface didn't expose it; this closes only that gap. The consumer change (the interceptor rewrite) lands as a separate follow-up on #11658.

Additional Notes

  • Non-breaking: it's a default method, so no existing AgentSpan implementer has to change. Making it abstract would break every implementer.
  • No behavior change to existing spans — DDSpan already returns this value.
  • Deliberately does not touch MutableSpan / dd-trace-api (the FFE interceptor casts to AgentSpan).

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Add your completed PR to the merge queue by commenting /merge. You can also:
    • Customize the commit message associated with the merge with /merge --commit-message "..."
    • Remove your PR from the merge queue with /merge -c
    • Skip all merge queue checks with /merge -f --reason "reason"; please use this judiciously, as some checks do not run at the PR-level (note: the PR still needs to be mergeable, this will only skip the pre-merge build)
    • Get more information in this doc

Add a non-breaking default boolean isFinished() to the AgentSpan
interface (internal-api), surfacing the finished state DDSpan already
tracks (durationNano != 0) so other modules can query it without
reaching into dd-trace-core. DDSpan's existing method overrides the
default; the TrackingSpanDecorator test wrapper delegates; leaf/synthetic
spans (NoopSpan etc.) keep the false default. Adds a DDSpanTest case
covering false-before / true-after-finish via the interface.

Motivated by the FFE span-enrichment interceptor (PR #11658), which needs
to distinguish a truly-finished local root from a still-running one
(long-running traces) and resolve it in O(1); that consumer lands in a
separate follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pavlokhrebto pavlokhrebto requested review from a team as code owners July 8, 2026 11:56
@pavlokhrebto pavlokhrebto requested review from mhlidd and removed request for a team July 8, 2026 11:56
@dd-octo-sts dd-octo-sts Bot added the tag: ai generated Largely based on code generated by an AI or LLM label Jul 8, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@dd-octo-sts

dd-octo-sts Bot commented Jul 8, 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 13.97 s 14.03 s [-1.3%; +0.4%] (no difference)
startup:insecure-bank:tracing:Agent 13.02 s 13.07 s [-1.0%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 16.85 s 16.73 s [-0.3%; +1.8%] (no difference)
startup:petclinic:iast:Agent 16.45 s 16.96 s [-7.4%; +1.3%] (no difference)
startup:petclinic:profiling:Agent 16.67 s 16.57 s [-0.5%; +1.8%] (no difference)
startup:petclinic:sca:Agent 16.90 s 16.82 s [-0.5%; +1.5%] (no difference)
startup:petclinic:tracing:Agent 16.15 s 16.14 s [-0.8%; +0.9%] (no difference)

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

@pavlokhrebto pavlokhrebto added comp: core Tracer core type: feature Enhancements and improvements tag: no release notes Changes to exclude from release notes labels Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a non-breaking isFinished() default method to the AgentSpan interface so modules depending on internal-api can query span completion without reaching into dd-trace-core, while preserving existing behavior for DDSpan.

Changes:

  • Introduces default boolean isFinished() on AgentSpan (default false).
  • Adds a DDSpanTest case asserting isFinished() transitions from false to true after finish(), via the AgentSpan interface.
  • Updates TrackingSpanDecorator (test wrapper) to delegate isFinished() to the wrapped span.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentSpan.java Adds isFinished() as a default method on the core span interface.
dd-trace-core/src/test/java/datadog/trace/core/DDSpanTest.java Adds coverage to validate AgentSpan.isFinished() reflects DDSpan completion.
dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/TrackingSpanDecorator.groovy Delegates isFinished() in the AgentSpan test wrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 56.92% (-0.02%)

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

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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.
It would probably be worth getting one more approval from an experienced reviewer before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants