Skip to content

fix(llmobs): aggregate span.finished telemetry counts per interval - #12136

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
masterfrom
fix/llmobs-telemetry-span-finished-aggregation
Sep 3, 2026
Merged

fix(llmobs): aggregate span.finished telemetry counts per interval#12136
gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
masterfrom
fix/llmobs-telemetry-span-finished-aggregation

Conversation

@Yun-Kim

@Yun-Kim Yun-Kim commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Makes LLMObsMetricCollector aggregate mlobs.span.finished counts per tag combination in-process and emit one metric carrying the summed value per metrics interval, instead of enqueuing one raw metric of value 1 per finished span.

Why

dd.instrumentation_telemetry_data.mlobs.span.finished severely underreports on the spans that are received by Datadog LLM Observability backend. recordSpanFinished enqueued one LLMObsMetric of value 1 per span, and prepareMetrics() was a no-op, so no summation ever happened. MetricCollector.java reduces each object stamped to second-granularity timestamp. This means every point a series emits within the same second collapses to a single value at the metrics intake, so the reported rate is pinned at ~1/s per series no matter the real span rate.

I confirmed on the affected org: max:dd.instrumentation_telemetry_data.mlobs.span.finished{org_id:...}.as_rate() sits flat at exactly 1.0/s, and the org-wide sum of ~1k/min is just the ~17 active tag combinations each contributing 1/s.

How It Works

  • recordSpanFinished increments a LongAdder keyed by tag combo. stop enqueuing to metrics queue directly
  • prepareMetrics() drains each counter with sumThenReset() and stages one summed metric per tag combo
  • The queue now holds one entry per tag combination per interval rather than one per span, so 1024 slots is ample (bounded at 128 combinations x 6 intervals per heartbeat).
  • If a metric cannot be queued, its count is returned to the counter and reported in a later interval rather than lost.

Verification

Built and tested locally on JDK 21.

Same scratch test, same input (5000 identical spans inside one metrics interval), before vs after:

Collector Result
Before emitted 1024 metric entries, distinct values=[1], total reported=1024 out of 5000 spans
After passes - one entry, value 5000

Those "before" numbers are the two failure modes made concrete: the count pinned at exactly RAW_QUEUE_SIZE (1024), and every emitted point carrying value 1 - the shape that then collapses to ~1/s per series at the metrics intake.

Manual Validation - tested twice, sending 500 spans per instance with the fix and master:
Screenshot 2026-09-01 at 6 51 39 PM

LLMObsMetricCollector enqueued one raw metric of value 1 per finished
span and left prepareMetrics() as a no-op, so the count was never
aggregated in-process. Two problems followed:

- Metric timestamps are second-granularity, so all points a series
  emits within the same second collapse to one value at the metrics
  intake. The reported rate was pinned at ~1/s per series regardless of
  the real span rate.
- The raw queue holds RAW_QUEUE_SIZE (1024) entries per 10s metrics
  interval, silently dropping anything above ~102 spans/s per JVM.

Count per tag combination with a LongAdder and emit one metric carrying
the summed value in prepareMetrics(), matching CoreMetricCollector and
the other tracers. The queue now holds one entry per tag combination per
interval instead of one per span. A counter whose metric cannot be
staged keeps its count for a later interval rather than losing it, and
the number of tracked tag combinations is bounded.

Also migrates the two affected Groovy tests to JUnit 5 / Java per the
repo test convention. The previous "test aggregation of identical
metrics" case asserted the buggy shape (three points of value 1); it is
replaced by cases asserting a single point carrying the summed count,
including one well above RAW_QUEUE_SIZE.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Yun-Kim Yun-Kim added tag: ai generated Largely based on code generated by an AI or LLM comp: mlobs ML Observability (LLMObs) comp: telemetry Telemetry type: bug fix Bug fix labels Aug 3, 2026
@datadog-datadog-prod-us1-2

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Aug 3, 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.85 s 14.75 s [-0.3%; +1.7%] (no difference)
startup:insecure-bank:tracing:Agent 13.64 s 13.66 s [-0.8%; +0.5%] (no difference)
startup:petclinic:appsec:Agent 17.02 s 16.76 s [+0.7%; +2.4%] (maybe worse)
startup:petclinic:iast:Agent 16.35 s 16.95 s [-7.8%; +0.6%] (no difference)
startup:petclinic:profiling:Agent 16.71 s 16.84 s [-1.9%; +0.2%] (no difference)
startup:petclinic:sca:Agent 16.89 s 16.63 s [+0.6%; +2.4%] (maybe worse)
startup:petclinic:tracing:Agent 16.02 s 16.11 s [-1.5%; +0.4%] (no difference)

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

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Yun-Kim Yun-Kim changed the title Aggregate LLMObs span.finished telemetry counts per interval fix(llmobs): aggregate span.finished telemetry counts per interval Sep 1, 2026
Yun-Kim and others added 2 commits September 1, 2026 19:20
The three span.finished telemetry tests in DDLLMObsSpanTest asserted that
finish() alone puts a metric in the queue. Recording now only increments a
LongAdder, so drain() returned empty and the tests failed on every JVM.

Reset the collector in the shared setup() fixture (a bare drain() no longer
isolates counter state) and call prepareMetrics() before the assertion drain.

Also from review:
- drop the historical rationale from the class and field javadoc
- reword the MAX_TAG_COMBINATIONS javadoc and raise the bound to 512, above
  the cardinality the 8-entry tag caches imply and clear of RAW_QUEUE_SIZE
- guard the tag-limit debug log with isDebugEnabled()
- annotate resetForTesting() with @VisibleForTesting

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Conflict was in LLMObsMetricCollector imports only: master added
javax.annotation.Nullable for recordFeedbackSubmitted while this branch added
ConcurrentHashMap/LongAdder for the span.finished aggregation. Kept both.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Yun-Kim
Yun-Kim marked this pull request as ready for review September 2, 2026 15:43
@Yun-Kim
Yun-Kim requested review from a team as code owners September 2, 2026 15:43
@Yun-Kim
Yun-Kim requested review from sarahchen6 and removed request for a team September 2, 2026 15:43

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3d305cda9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

Cool. Looks good from LP side!

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 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 new counters keep span totals across intervals and queue saturation. The static source review found no reportable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

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

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

Looks good to me, but I wonder if you think the bot's comment is worth addressing.

@Yun-Kim
Yun-Kim added this pull request to the merge queue Sep 2, 2026
@dd-octo-sts

dd-octo-sts Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 2, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-02 18:14:52 UTC ℹ️ Start processing command /merge


2026-09-02 18:14:58 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-09-02 18:32:18 UTCMergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 9d31521:

⚠️ 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 Sep 2, 2026
@Yun-Kim
Yun-Kim added this pull request to the merge queue Sep 3, 2026
@dd-octo-sts

dd-octo-sts Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 3, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-03 19:56:34 UTC ℹ️ Start processing command /merge


2026-09-03 19:56:40 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-09-03 21:01:40 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 Sep 3, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 3f139e8 into master Sep 3, 2026
601 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the fix/llmobs-telemetry-span-finished-aggregation branch September 3, 2026 21:01
@github-actions github-actions Bot added this to the 1.66.0 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: mlobs ML Observability (LLMObs) comp: telemetry Telemetry tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants