Skip to content

feat(llmobs): activate APM scope for standalone agent spans - #12347

Draft
yahya-mouman wants to merge 1 commit into
masterfrom
yahya/llmobs-standalone-apm-scope
Draft

feat(llmobs): activate APM scope for standalone agent spans#12347
yahya-mouman wants to merge 1 commit into
masterfrom
yahya/llmobs-standalone-apm-scope

Conversation

@yahya-mouman

Copy link
Copy Markdown
Contributor

Summary

  • When an LLMObs agent span is its own APM local root (no ambient APM parent), it now activates its underlying APM span as the current scope via standaloneApmScope.
  • Without this, each new DDLLMObsSpan inside the same workflow starts a fresh APM root with a different trace ID, causing the trace-ID consistency gate in the DDLLMObsSpan constructor to reject parent_id and session_id inheritance — resulting in a flat LLMObs trace with no hierarchy.
  • When an agent span already has an ambient APM parent (non-standalone), standaloneApmScope is null and no additional scope is opened.

This is a follow-up to #12238 (agent attribution), extracted into its own PR because it's a standalone behavioral change with its own tests.

Test plan

  • New JUnit tests in DDLLMObsSpanStandaloneApmScopeTest:
    • standaloneAgentSpanActivatesApmScopeForOutgoingPropagation — verifies standaloneApmScope is non-null when no ambient APM parent
    • nonStandaloneAgentSpanDoesNotActivateApmScope — verifies standaloneApmScope is null when an APM parent already exists
  • Groovy test cleanup: added cleanup: test.finish() to the two DDLLMObsSpanTest tests that use LLMOBS_AGENT_SPAN_KIND to prevent scope leakage

🤖 Generated with Claude Code

…ve trace-ID consistency

When an agent span is its own APM local root (no ambient APM parent), activate it as the current
APM scope. Without this, each subsequent DDLLMObsSpan starts a fresh APM root with a different
trace ID, causing the trace-ID consistency gate in the constructor to reject parent_id and
session_id inheritance, resulting in a flat LLMObs trace with no hierarchy.

Also adds cleanup blocks to Groovy tests where LLMOBS_AGENT_SPAN_KIND spans were leaking scopes,
and adds JUnit tests verifying standalone vs non-standalone scope activation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yahya-mouman yahya-mouman added type: feature Enhancements and improvements comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM labels Aug 31, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 58.78% (-0.06%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1207e73 | Docs | View more details | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Aug 31, 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.99 s 14.00 s [-0.9%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.00 s [-1.6%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 17.62 s 17.17 s [+1.7%; +3.6%] (significantly worse)
startup:petclinic:iast:Agent 17.53 s 17.63 s [-1.7%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 17.45 s 17.43 s [-1.0%; +1.2%] (no difference)
startup:petclinic:sca:Agent 17.37 s 17.41 s [-1.4%; +0.9%] (no difference)
startup:petclinic:tracing:Agent 16.66 s 16.59 s [-0.5%; +1.4%] (no difference)

Commit: 1207e73c · 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

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant