Skip to content

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

Open
mabdinur wants to merge 1 commit into
masterfrom
codex/fix-otlp-delta-windows
Open

fix(otlp): emit non-overlapping delta metric windows#10086
mabdinur wants to merge 1 commit into
masterfrom
codex/fix-otlp-delta-windows

Conversation

@mabdinur

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, periodic flushes now retain the active wall-clock bucket until it is complete. This keeps spans recorded on both sides of a process-relative timer tick in one histogram point. Explicit force flushes continue to drain all pending buckets.

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

Motivation

The TraceMetrics timer can fire before its active wall-clock bucket closes. Draining that bucket early allows later spans to recreate the same (startTimeUnixNano, timeUnixNano] window, producing overlapping delta histogram points that an OTLP receiver cannot safely combine.

Testing

  • ./node_modules/.bin/mocha packages/dd-trace/test/span_stats.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/periodic_metric_reader.js packages/dd-trace/test/span_stats.spec.js packages/dd-trace/test/opentelemetry/metrics.spec.js --max-warnings 0

@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-08-31T19:56:12.388897Z f2d04e8 PR opened
ℹ️ 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.64 MB
Deduped: 9.3 MB
No deduping: 9.3 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.4.0 | 127.33 kB | 447.04 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 on lines 253 to +254
forceFlush (done) {
this.#flush(done)
this.#flush(done, true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prevent force flushes from reopening exported buckets

When a reused Vercel worker handles multiple requests within one wall-clock bucket, flushAll() invokes this force flush after every request, so the first request drains and exports the still-open bucket; a later span then recreates the same timeNs, and the next flush exports another point with the identical [timeNs, timeNs + bucketSizeNs] window. This preserves the overlap that the change is intended to eliminate, so force flushes need to retain a boundary/state that lets subsequent data use a non-overlapping window while still completing lifecycle delivery.

AGENTS.md reference: AGENTS.md:L76-L80

Useful? React with 👍 / 👎.

Comment on lines +257 to +258
#flush (done, force = false) {
const drained = this.#drainBuckets(this.otlpExporter && !force ? Date.now() * 1e6 : Infinity)

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 Use the span timestamp clock for the bucket cutoff

If the system wall clock is corrected while a span is active, this cutoff and the bucket timestamps can diverge: formatted span end times are anchored to Date.now() at trace creation but advance using performance.now(), whereas this newly added cutoff reads the current Date.now(). A forward correction can therefore drain a bucket before a pre-correction span later lands in it, recreating an already-exported window; a backward correction can retain completed buckets until the wall clock catches up. Derive the cutoff from the same monotonic epoch clock as span timestamps.

AGENTS.md reference: AGENTS.md:L76-L80

Useful? React with 👍 / 👎.

@pr-commenter

pr-commenter Bot commented Aug 31, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-31 19:59:07

Comparing candidate commit f2d04e8 in PR branch codex/fix-otlp-delta-windows with baseline commit e0c56cf in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2293 metrics, 17 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 ----------------------------------'

Unstable benchmarks

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

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

  • unstable max_rss_usage [-14.865MB; +24.465MB] or [-6.370%; +10.484%]

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

  • unstable max_rss_usage [-13.070MB; +32.542MB] or [-3.603%; +8.970%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-204.519ms; +508.430ms] or [-4.139%; +10.289%]
  • unstable execution_time [-204.930ms; +507.974ms] or [-4.083%; +10.122%]
  • unstable throughput [-170957.475op/s; +69278.798op/s] or [-10.209%; +4.137%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-6.418MB; +9.724MB] or [-8.217%; +12.451%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-26

  • unstable cpu_usage_percentage [-5.838%; +6.414%]

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

  • unstable max_rss_usage [-7.738MB; +5.015MB] or [-6.081%; +3.941%]

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

  • unstable max_rss_usage [-7.474MB; +11.392MB] or [-5.271%; +8.035%]

scenario:plugin-memcached-hashring-24

  • unstable cpu_user_time [-1296.057ms; +446.705ms] or [-43.484%; +14.987%]
  • unstable execution_time [-1301.649ms; +450.000ms] or [-43.534%; +15.050%]
  • unstable instructions [-9.7G instructions; +3.1G instructions] or [-26.326%; +8.510%]
  • unstable throughput [-702325.311op/s; +1515175.371op/s] or [-4.845%; +10.452%]

scenario:plugin-pg-service-26

  • unstable cpu_usage_percentage [-8.130%; +5.149%]
  • unstable execution_time [-59.662ms; +109.967ms] or [-6.503%; +11.987%]
  • unstable throughput [-542747.693op/s; +293212.833op/s] or [-8.175%; +4.416%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-6833.466KB; +4900.133KB] or [-8.366%; +5.999%]

@datadog-prod-us1-3

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

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.63% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f2d04e8 | 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.62%. Comparing base (e0c56cf) to head (f2d04e8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10086   +/-   ##
=======================================
  Coverage   98.62%   98.62%           
=======================================
  Files         996      996           
  Lines      152034   152045   +11     
  Branches    13117    13061   -56     
=======================================
+ Hits       149947   149958   +11     
  Misses       2087     2087           
Flag Coverage Δ
aiguard 63.13% <ø> (-0.03%) ⬇️
aiguard-integration 58.99% <ø> (ø)
apm-bucket-0 62.49% <ø> (-0.03%) ⬇️
apm-bucket-1 67.93% <ø> (-0.03%) ⬇️
apm-bucket-2 67.49% <ø> (-0.03%) ⬇️
apm-bucket-3 64.34% <ø> (-0.03%) ⬇️
apm-capabilities-tracing 62.56% <100.00%> (+<0.01%) ⬆️
apm-integrations-aerospike 60.50% <ø> (-0.03%) ⬇️
apm-integrations-confluentinc-kafka-javascript 66.58% <ø> (-0.06%) ⬇️
apm-integrations-couchbase 61.02% <ø> (-0.02%) ⬇️
apm-integrations-http 66.21% <ø> (-0.03%) ⬇️
apm-integrations-kafkajs 67.20% <ø> (-0.03%) ⬇️
apm-integrations-next 63.83% <ø> (-0.03%) ⬇️
apm-integrations-prisma 61.88% <ø> (-0.03%) ⬇️
appsec 76.72% <ø> (-0.02%) ⬇️
appsec-express_fastify_graphql 72.68% <ø> (-0.02%) ⬇️
appsec-integration 49.52% <ø> (-0.01%) ⬇️
appsec-kafka_ldapjs_lodash 67.44% <ø> (-0.03%) ⬇️
appsec-mongodb-core_mongoose_mysql 70.62% <ø> (-0.02%) ⬇️
appsec-next 57.11% <ø> (-0.02%) ⬇️
appsec-node-serialize_passport_postgres 70.09% <ø> (-0.02%) ⬇️
appsec-sourcing_stripe_template 68.52% <ø> (-0.02%) ⬇️
debugger 69.08% <ø> (-0.03%) ⬇️
instrumentations-bucket-0 56.07% <ø> (-0.03%) ⬇️
instrumentations-bucket-1 64.16% <ø> (-0.03%) ⬇️
instrumentations-bucket-10 53.29% <ø> (-0.03%) ⬇️
instrumentations-bucket-11 65.61% <ø> (-0.03%) ⬇️
instrumentations-bucket-12 61.38% <ø> (-0.03%) ⬇️
instrumentations-bucket-13 56.27% <ø> (-0.03%) ⬇️
instrumentations-bucket-14 55.72% <ø> (-0.03%) ⬇️
instrumentations-bucket-2 56.92% <ø> (-0.03%) ⬇️
instrumentations-bucket-3 57.12% <ø> (-0.03%) ⬇️
instrumentations-bucket-4 63.77% <ø> (-0.03%) ⬇️
instrumentations-bucket-5 56.52% <ø> (-0.03%) ⬇️
instrumentations-bucket-6 58.11% <ø> (-0.02%) ⬇️
instrumentations-bucket-7 65.65% <ø> (-0.03%) ⬇️
instrumentations-bucket-8 62.91% <ø> (-0.03%) ⬇️
instrumentations-bucket-9 64.50% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-couchbase 54.68% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-zlib 55.75% <ø> (-0.03%) ⬇️
instrumentations-integration-esbuild 34.50% <ø> (ø)
llmobs-ai_anthropic_bedrock 66.67% <ø> (-0.02%) ⬇️
llmobs-bucket-1 64.84% <ø> (-0.02%) ⬇️
llmobs-openai 66.68% <ø> (-0.03%) ⬇️
llmobs-openai-agents_vertex-ai 63.97% <ø> (-0.03%) ⬇️
llmobs-sdk 75.90% <ø> (-0.03%) ⬇️
master-coverage 98.62% <100.00%> (?)
openfeature 59.58% <ø> (ø)
openfeature-unit 58.26% <ø> (-0.03%) ⬇️
platform-core_esbuild_instrumentations-misc 41.07% <ø> (-0.02%) ⬇️
platform-integration 64.80% <ø> (+<0.01%) ⬆️
platform-shimmer_unit-guardrails_webpack 38.90% <ø> (-0.02%) ⬇️
plugins-browser-bunyan_bullmq_cassandra 66.22% <ø> (-0.03%) ⬇️
plugins-bucket-0 60.91% <ø> (-0.03%) ⬇️
plugins-bucket-1 58.14% <ø> (ø)
plugins-bucket-11 67.67% <ø> (-0.03%) ⬇️
plugins-bucket-18 65.43% <ø> (-0.03%) ⬇️
plugins-bucket-19 64.92% <ø> (-0.02%) ⬇️
plugins-bucket-20 68.63% <ø> (-0.03%) ⬇️
plugins-bucket-4 61.07% <ø> (-0.03%) ⬇️
plugins-cookie_cookie-parser_crypto 55.66% <ø> (-0.03%) ⬇️
plugins-fastify_fetch_fs 65.32% <ø> (-0.03%) ⬇️
plugins-generic-pool_google-cloud-pubsub_grpc 68.92% <ø> (-0.03%) ⬇️
plugins-handlebars_hapi_hono 63.58% <ø> (-0.03%) ⬇️
plugins-ioredis_knex_langgraph 61.59% <ø> (-0.03%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 63.30% <ø> (-0.03%) ⬇️
plugins-lodash_mariadb_memcached 63.68% <ø> (-0.12%) ⬇️
plugins-moleculer_mongodb_mongodb-core 66.03% <ø> (-0.03%) ⬇️
plugins-mongoose_multer_mysql 63.89% <ø> (-0.03%) ⬇️
plugins-mysql2_nats_node-serialize 66.10% <ø> (-0.03%) ⬇️
plugins-opensearch_passport-http_pino 63.99% <ø> (-0.03%) ⬇️
plugins-postgres_process_pug 63.03% <ø> (-0.03%) ⬇️
plugins-redis_router_sequelize 66.60% <ø> (-0.03%) ⬇️
plugins-test-and-upstream-rhea_undici_url 65.95% <ø> (-0.03%) ⬇️
plugins-valkey_vm_winston 62.31% <ø> (-0.07%) ⬇️
plugins-ws 64.42% <ø> (-0.03%) ⬇️
profiling 66.18% <ø> (-0.03%) ⬇️
serverless-aws-sdk-aws-sdk 55.40% <ø> (-0.02%) ⬇️
serverless-aws-sdk-base-inject-field 55.23% <ø> (-0.03%) ⬇️
serverless-aws-sdk-bedrockruntime 58.25% <ø> (-0.03%) ⬇️
serverless-aws-sdk-client 60.03% <ø> (-0.03%) ⬇️
serverless-aws-sdk-dynamodb 59.12% <ø> (-0.03%) ⬇️
serverless-aws-sdk-eventbridge 57.61% <ø> (-0.02%) ⬇️
serverless-aws-sdk-kinesis 63.09% <ø> (-0.03%) ⬇️
serverless-aws-sdk-lambda 61.05% <ø> (-0.03%) ⬇️
serverless-aws-sdk-s3 59.16% <ø> (-0.03%) ⬇️
serverless-aws-sdk-serverless-peer-service 63.66% <ø> (-0.03%) ⬇️
serverless-aws-sdk-sns 63.98% <ø> (-0.03%) ⬇️
serverless-aws-sdk-sqs 64.43% <ø> (-0.03%) ⬇️
serverless-aws-sdk-stepfunctions 59.02% <ø> (-0.03%) ⬇️
serverless-aws-sdk-util 55.85% <ø> (-0.03%) ⬇️
serverless-bucket-0 56.86% <ø> (-0.91%) ⬇️
serverless-bucket-1 63.66% <ø> (-0.03%) ⬇️
test-optimization-cucumber 70.51% <ø> (+0.02%) ⬆️
test-optimization-cypress 64.73% <ø> (+0.08%) ⬆️
test-optimization-jest 72.05% <ø> (+<0.01%) ⬆️
test-optimization-mocha 71.95% <ø> (+0.05%) ⬆️
test-optimization-playwright-playwright-atr 59.78% <ø> (-0.03%) ⬇️
test-optimization-playwright-playwright-efd 60.46% <ø> (+0.01%) ⬆️
test-optimization-playwright-playwright-final-status 60.02% <ø> (-0.04%) ⬇️
test-optimization-playwright-playwright-impacted-tests 60.13% <ø> (+0.11%) ⬆️
test-optimization-playwright-playwright-reporting 61.10% <ø> (-0.04%) ⬇️
test-optimization-playwright-playwright-test-management 61.19% <ø> (-0.04%) ⬇️
test-optimization-playwright-playwright-test-span 59.82% <ø> (+0.01%) ⬆️
test-optimization-selenium 58.84% <ø> (-0.07%) ⬇️
test-optimization-testopt 61.78% <ø> (+0.06%) ⬆️
test-optimization-vitest 72.66% <ø> (+0.08%) ⬆️
test-optimization-vitest-browser 58.68% <ø> (-0.03%) ⬇️
test-optimization-webdriverio 65.48% <ø> (+0.04%) ⬆️

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.

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