Skip to content

fix(otlp): emit non-overlapping delta metric windows - #10086

Open
mabdinur wants to merge 3 commits into
masterfrom
codex/fix-otlp-delta-windows
Open

mabdinur wants to merge 3 commits into
masterfrom
codex/fix-otlp-delta-windows

Conversation

@mabdinur

@mabdinur mabdinur commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Prevents overlapping OTLP delta metric windows in the TraceMetrics and general metrics exporters.

For traces.span.sdk.metrics.duration, span statistics now use continuous process-relative collection windows instead of fixed wall-clock buckets. A periodic flush closes the current window at collection time. A force flush closes the partial window and refreshes the timer so the next periodic window receives a full interval. Empty windows advance the boundary without emitting a metric payload.

For general delta counters and histograms, each point ends at collection time and that endpoint becomes the next point start. Counts, sums, and histogram buckets are unchanged.

Motivation

The previous wall-clock buckets could be drained before completion and then recreated by later spans, producing overlapping delta histogram points. Force flushes could trigger the same overlap in reused serverless processes.

Collection-relative windows remain continuous across periodic and force flushes without requiring ten-second wall-clock alignment.

Performance

This change does not add metric series or payloads. Span metrics emit at most one non-empty window per flush, empty windows are not exported, and refreshing the timer after force flush avoids an additional scheduled export. The OTLP span hot path also avoids wall-clock timestamp and modulo calculations.

Testing

  • ./node_modules/.bin/mocha packages/dd-trace/test/span_stats.spec.js packages/dd-trace/test/opentelemetry/metrics/otlp_span_stats_transformer.spec.js packages/dd-trace/test/opentelemetry/metrics/otlp_span_stats_exporter.spec.js packages/dd-trace/test/opentelemetry/metrics.spec.js
  • ./node_modules/.bin/eslint packages/dd-trace/src/span_stats.js packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js packages/dd-trace/test/span_stats.spec.js packages/dd-trace/test/opentelemetry/metrics/otlp_span_stats_transformer.spec.js --max-warnings 0
  • git diff --check

@mabdinur
mabdinur requested review from a team as code owners August 31, 2026 19:49
@mabdinur
mabdinur requested a review from BridgeAR August 31, 2026 19:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-18T20:45:32.268355Z 29f88d7 New commits
🔒 Security Review Completed 2026-09-18T20:45:11.098836Z 29f88d7 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dd-octo-sts

dd-octo-sts Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.99 MB
Deduped: 9.72 MB
No deduping: 9.72 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.1 | 127.66 kB | 513.61 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@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: f2d04e8281

ℹ️ 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".

Comment thread packages/dd-trace/src/span_stats.js Outdated
Comment thread packages/dd-trace/src/span_stats.js Outdated
@pr-commenter

pr-commenter Bot commented Aug 31, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-18 20:55:44

Comparing candidate commit 29f88d7 in PR branch codex/fix-otlp-delta-windows with baseline commit 5f84573 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 3 performance regressions! Performance is the same for 2297 metrics, 13 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:plugin-graphql-long-with-depth-off-26

  • 🟥 cpu_user_time [+176.536ms; +615.354ms] or [+2.319%; +8.083%]
  • 🟥 execution_time [+187.581ms; +650.314ms] or [+2.418%; +8.382%]
  • 🟥 throughput [-28.716op/s; -8.536op/s] or [-8.663%; -2.575%]

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-22.510MB; +20.050MB] or [-6.332%; +5.640%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-389.688ms; +617.193ms] or [-4.730%; +7.492%]
  • unstable execution_time [-385.946ms; +630.407ms] or [-4.132%; +6.748%]
  • unstable throughput [-79.399op/s; +49.538op/s] or [-6.537%; +4.078%]

scenario:dogstatsd-aggregated-20

  • unstable execution_time [-102.894ms; +185.617ms] or [-5.266%; +9.500%]
  • unstable throughput [-879218.806op/s; +465991.707op/s] or [-7.099%; +3.763%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-12314.925KB; +12079.925KB] or [-15.825%; +15.523%]

scenario:fs-subscribed-24

  • unstable execution_time [-22.954ms; +37.158ms] or [-5.640%; +9.130%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-6.452MB; +9.723MB] or [-8.255%; +12.440%]

scenario:log-with-debug-24

  • unstable execution_time [-221.818ms; +213.106ms] or [-5.506%; +5.289%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [+17.618MB; +52.419MB] or [+7.753%; +23.067%]

scenario:plugin-graphql-long-with-depth-on-max-26

  • unstable max_rss_usage [+15.125MB; +52.325MB] or [+6.552%; +22.666%]

scenario:plugin-pg-service-26

  • unstable execution_time [-76.488ms; +123.117ms] or [-4.611%; +7.422%]

@datadog-prod-us1-3

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

Copy link
Copy Markdown

Tests

All CI checks and tests passed. Datadog automation helped this PR pass.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog retried 1 test - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.21% (-0.01%)

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

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.75%. Comparing base (5f84573) to head (29f88d7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10086   +/-   ##
=======================================
  Coverage   98.74%   98.75%           
=======================================
  Files        1029     1029           
  Lines      161207   161233   +26     
  Branches       74       74           
=======================================
+ Hits       159188   159226   +38     
+ Misses       2019     2007   -12     
Flag Coverage Δ
ai-guard 65.01% <ø> (-0.02%) ⬇️
apm-capabilities 63.47% <100.00%> (+<0.01%) ⬆️
apm-integrations 81.82% <ø> (-0.02%) ⬇️
appsec 58.65% <ø> (-0.01%) ⬇️
debugger 70.28% <ø> (-0.01%) ⬇️
instrumentation 54.27% <ø> (-0.01%) ⬇️
llmobs 78.66% <ø> (-0.02%) ⬇️
master-coverage 98.75% <100.00%> (?)
openfeature 66.42% <ø> (-0.03%) ⬇️
platform 69.34% <ø> (-0.01%) ⬇️
profiling 66.93% <ø> (-0.03%) ⬇️
serverless 65.63% <ø> (-0.02%) ⬇️
test-optimization 82.23% <ø> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mabdinur
mabdinur force-pushed the codex/fix-otlp-delta-windows branch from 7216079 to b19bdae Compare September 17, 2026 19:55

@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: 29f88d759b

ℹ️ 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".

Comment on lines +567 to +568
dataPoint.startTimeUnixNano = lastState?.timeUnixNano ??
dataPoint.startTimeUnixNano ?? dataPoint.timeUnixNano

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Seed the first observable delta window before collection

When an ObservableCounter uses DELTA temporality, #aggregateLastValue provides no startTimeUnixNano, so its first collection takes this final fallback after timeUnixNano has already been overwritten with collectionTime. The exported point therefore has startTimeUnixNano === timeUnixNano while containing the entire initial observed value, producing a zero-duration delta window that receivers may reject or cannot use for rate calculations. Initialize first-seen observable series from an earlier boundary such as the aggregator start, and cover this sibling of the synchronous counter path in the new timestamp test.

AGENTS.md reference: AGENTS.md:L79-L80

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant