Skip to content

feat(opentelemetry): add metrics lifecycle methods - #10023

Draft
bm1549 wants to merge 2 commits into
masterfrom
brian.marks/otel-metrics-lifecycle
Draft

feat(opentelemetry): add metrics lifecycle methods#10023
bm1549 wants to merge 2 commits into
masterfrom
brian.marks/otel-metrics-lifecycle

Conversation

@bm1549

@bm1549 bm1549 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Link (AppGate required)

Adds Promise-returning forceFlush() and shutdown() methods to the concrete Datadog MeterProvider used by the global OTel metrics API.

The reader serializes periodic, explicit, and final exports. Lifecycle Promises settle after the OTLP HTTP result, and shutdown performs one final export before closing the exporter. The Datadog provider type is exported in both TypeScript declaration surfaces without changing upstream OTel types.

Motivation

Short-lived Node.js jobs can exit before the periodic OTel metrics interval. They need a supported way to wait for pending custom metrics before the process ends.

Additional Notes

  • Periodic ticks are coalesced, while each requested flush keeps its own completion.
  • Queue advancement uses a microtask so a large burst of immediately completing requests cannot exhaust the call stack.
  • Callback exceptions, duplicate callbacks, HTTP failures, and timeouts settle lifecycle work without stalling the queue.
  • All 75 OTel metrics tests passed, including a 5,000-call stress test. Lint, the documentation compile-and-run type test, and both shared lifecycle system tests also passed.
  • Companion PRs: system-tests #7606, Java #12317, and documentation #39515.

@bm1549 bm1549 added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Aug 27, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 27, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 6 jobs - 5 passed on retry View in Datadog

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

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

@dd-octo-sts

dd-octo-sts Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.41 MB
Deduped: 9.07 MB
No deduping: 9.07 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 445.14 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

@pr-commenter

pr-commenter Bot commented Aug 27, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-27 13:17:12

Comparing candidate commit 471864e in PR branch brian.marks/otel-metrics-lifecycle with baseline commit deb9a44 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2300 metrics, 10 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:debugger-line-probe-with-snapshot-minimal-24

  • unstable max_rss_usage [-14257.262KB; +12986.862KB] or [-5.706%; +5.198%]

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

  • unstable max_rss_usage [-15589.281KB; +14532.481KB] or [-5.432%; +5.064%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-249.634ms; +406.558ms] or [-5.147%; +8.382%]
  • unstable execution_time [-252.651ms; +406.989ms] or [-5.130%; +8.264%]
  • unstable throughput [-146421.667op/s; +89712.734op/s] or [-8.587%; +5.261%]

scenario:plugin-aws-sdk-extract-response-body-24

  • unstable execution_time [-75.358ms; +106.641ms] or [-4.809%; +6.805%]
  • unstable throughput [-310285.751op/s; +225656.628op/s] or [-6.027%; +4.383%]

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

  • unstable max_rss_usage [-14.749MB; +31.635MB] or [-3.757%; +8.058%]

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

  • unstable max_rss_usage [-6.102MB; +54.007MB] or [-3.298%; +29.187%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-4665.097KB; +6230.097KB] or [-5.836%; +7.794%]

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.57%. Comparing base (deb9a44) to head (471864e).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10023   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         990      990           
  Lines      148949   149047   +98     
  Branches    13143    13148    +5     
=======================================
+ Hits       146827   146926   +99     
+ Misses       2122     2121    -1     
Flag Coverage Δ
aiguard 62.16% <ø> (+4.94%) ⬆️
aiguard-integration 58.88% <ø> (+3.91%) ⬆️
apm-bucket-0 61.60% <ø> (+4.51%) ⬆️
apm-bucket-1 67.11% <ø> (+4.83%) ⬆️
apm-bucket-2 66.65% <ø> (+5.54%) ⬆️
apm-bucket-3 63.31% <ø> (+4.56%) ⬆️
apm-capabilities-tracing 62.37% <100.00%> (+0.06%) ⬆️
apm-integrations-aerospike 59.47% <ø> (+4.68%) ⬆️
apm-integrations-confluentinc-kafka-javascript 65.65% <ø> (+5.56%) ⬆️
apm-integrations-couchbase 59.98% <ø> (+4.28%) ⬆️
apm-integrations-http 65.37% <ø> (+4.69%) ⬆️
apm-integrations-kafkajs 66.23% <ø> (+5.62%) ⬆️
apm-integrations-next 62.83% <ø> (+4.45%) ⬆️
apm-integrations-prisma 61.11% <ø> (+3.84%) ⬆️
appsec 76.14% <ø> (+5.37%) ⬆️
appsec-express_fastify_graphql 72.66% <ø> (+4.45%) ⬆️
appsec-integration 49.16% <ø> (-0.17%) ⬇️
appsec-kafka_ldapjs_lodash 66.66% <ø> (+4.47%) ⬆️
appsec-mongodb-core_mongoose_mysql 70.00% <ø> (+4.31%) ⬆️
appsec-next 56.39% <ø> (+0.68%) ⬆️
appsec-node-serialize_passport_postgres 69.45% <ø> (+4.35%) ⬆️
appsec-sourcing_stripe_template 67.83% <ø> (+4.28%) ⬆️
debugger 68.80% <ø> (+5.53%) ⬆️
instrumentations-bucket-0 54.78% <ø> (+4.01%) ⬆️
instrumentations-bucket-1 63.17% <ø> (+4.56%) ⬆️
instrumentations-bucket-10 64.44% <ø> (+4.73%) ⬆️
instrumentations-bucket-11 65.10% <ø> (+4.74%) ⬆️
instrumentations-bucket-12 54.66% <ø> (+3.98%) ⬆️
instrumentations-bucket-13 54.98% <ø> (+3.43%) ⬆️
instrumentations-bucket-14 54.79% <ø> (+4.00%) ⬆️
instrumentations-bucket-2 55.90% <ø> (+3.86%) ⬆️
instrumentations-bucket-3 56.71% <ø> (+4.05%) ⬆️
instrumentations-bucket-4 62.62% <ø> (+4.91%) ⬆️
instrumentations-bucket-5 49.11% <ø> (+0.68%) ⬆️
instrumentations-bucket-6 64.54% <ø> (+5.33%) ⬆️
instrumentations-bucket-7 54.94% <ø> (+3.96%) ⬆️
instrumentations-bucket-8 62.02% <ø> (+4.58%) ⬆️
instrumentations-bucket-9 57.56% <ø> (+1.29%) ⬆️
instrumentations-instrumentation-couchbase 53.38% <ø> (+3.86%) ⬆️
instrumentations-integration-esbuild 34.00% <ø> (-0.01%) ⬇️
llmobs-ai_anthropic_bedrock 66.12% <ø> (+4.20%) ⬆️
llmobs-bucket-1 64.25% <ø> (+3.78%) ⬆️
llmobs-openai 66.05% <ø> (+4.94%) ⬆️
llmobs-openai-agents_vertex-ai 63.24% <ø> (+4.06%) ⬆️
llmobs-sdk 75.15% <ø> (+6.91%) ⬆️
master-coverage 98.57% <100.00%> (?)
openfeature 59.46% <ø> (+4.45%) ⬆️
openfeature-unit 57.19% <ø> (+4.20%) ⬆️
platform-core_esbuild_instrumentations-misc 40.46% <ø> (-0.22%) ⬇️
platform-integration 64.18% <0.00%> (+4.78%) ⬆️
platform-shimmer_unit-guardrails_webpack 38.20% <ø> (-0.19%) ⬇️
plugins-browser-bunyan_bullmq_cassandra 65.34% <ø> (+4.83%) ⬆️
plugins-bucket-0 60.12% <ø> (+4.15%) ⬆️
plugins-bucket-1 57.35% <ø> (+4.32%) ⬆️
plugins-bucket-11 65.85% <ø> (+4.95%) ⬆️
plugins-bucket-18 65.39% <ø> (+4.92%) ⬆️
plugins-bucket-19 63.90% <ø> (+5.21%) ⬆️
plugins-bucket-20 65.78% <ø> (+5.19%) ⬆️
plugins-bucket-4 60.20% <ø> (+4.87%) ⬆️
plugins-cookie_cookie-parser_crypto 54.33% <ø> (+4.03%) ⬆️
plugins-fastify_fetch_fs 64.49% <ø> (+4.97%) ⬆️
plugins-generic-pool_google-cloud-pubsub_grpc 68.09% <ø> (+5.04%) ⬆️
plugins-handlebars_hapi_hono 62.50% <ø> (+4.95%) ⬆️
plugins-ioredis_knex_langgraph 60.69% <ø> (+4.69%) ⬆️
plugins-ldapjs_light-my-request_limitd-client 62.23% <ø> (+5.00%) ⬆️
plugins-lodash_mariadb_memcached 62.98% <ø> (+4.40%) ⬆️
plugins-moleculer_mongodb_mongodb-core 65.19% <ø> (+4.81%) ⬆️
plugins-mongoose_multer_mysql 63.07% <ø> (+4.85%) ⬆️
plugins-mysql2_nats_node-serialize 65.18% <ø> (+5.34%) ⬆️
plugins-opensearch_passport-http_pino 63.12% <ø> (+5.04%) ⬆️
plugins-postgres_process_pug 62.17% <ø> (+4.94%) ⬆️
plugins-redis_router_sequelize 65.78% <ø> (+5.33%) ⬆️
plugins-test-and-upstream-rhea_undici_url 65.16% <ø> (+5.11%) ⬆️
plugins-valkey_vm_winston 61.48% <ø> (+4.82%) ⬆️
plugins-ws 63.40% <ø> (+5.17%) ⬆️
profiling 65.39% <ø> (+4.64%) ⬆️
serverless-aws-sdk-aws-sdk 54.62% <ø> (+0.65%) ⬆️
serverless-aws-sdk-base-inject-field 53.92% <ø> (+3.91%) ⬆️
serverless-aws-sdk-bedrockruntime 57.24% <ø> (+3.51%) ⬆️
serverless-aws-sdk-client 59.10% <ø> (+3.87%) ⬆️
serverless-aws-sdk-dynamodb 58.18% <ø> (+3.63%) ⬆️
serverless-aws-sdk-eventbridge 56.79% <ø> (+0.72%) ⬆️
serverless-aws-sdk-kinesis 62.21% <ø> (+4.13%) ⬆️
serverless-aws-sdk-lambda 60.13% <ø> (+3.86%) ⬆️
serverless-aws-sdk-s3 58.26% <ø> (+3.61%) ⬆️
serverless-aws-sdk-serverless-peer-service 62.87% <ø> (+4.24%) ⬆️
serverless-aws-sdk-sns 63.11% <ø> (+4.25%) ⬆️
serverless-aws-sdk-sqs 63.56% <ø> (+4.28%) ⬆️
serverless-aws-sdk-stepfunctions 58.10% <ø> (+3.63%) ⬆️
serverless-aws-sdk-util 54.58% <ø> (+4.06%) ⬆️
serverless-bucket-0 56.83% <ø> (+4.20%) ⬆️
serverless-bucket-1 62.78% <ø> (+4.89%) ⬆️
test-optimization-cucumber 70.15% <ø> (-0.04%) ⬇️
test-optimization-cypress 64.45% <ø> (+0.05%) ⬆️
test-optimization-jest 71.61% <ø> (+<0.01%) ⬆️
test-optimization-mocha 71.66% <ø> (+0.03%) ⬆️
test-optimization-playwright-playwright-atr 59.31% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-efd 59.97% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-final-status 59.58% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-impacted-tests 59.76% <ø> (+0.18%) ⬆️
test-optimization-playwright-playwright-reporting 60.72% <ø> (-0.07%) ⬇️
test-optimization-playwright-playwright-test-management 60.83% <ø> (-0.05%) ⬇️
test-optimization-playwright-playwright-test-span 59.35% <ø> (-0.08%) ⬇️
test-optimization-selenium 58.48% <ø> (-0.09%) ⬇️
test-optimization-testopt 61.47% <ø> (+0.10%) ⬆️
test-optimization-vitest 72.40% <ø> (+0.02%) ⬆️
test-optimization-vitest-browser 58.31% <ø> (-0.02%) ⬇️
test-optimization-webdriverio 64.92% <ø> (+0.13%) ⬆️

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

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant