Skip to content

fix(metrics): prevent native metrics from loading when not needed#7942

Merged
pabloerhard merged 11 commits into
masterfrom
pabloerhard/enable-non-native-runtime-metrics
Apr 13, 2026
Merged

fix(metrics): prevent native metrics from loading when not needed#7942
pabloerhard merged 11 commits into
masterfrom
pabloerhard/enable-non-native-runtime-metrics

Conversation

@pabloerhard
Copy link
Copy Markdown
Contributor

What does this PR do?

This PR prevents native runtime metrics from loading when event loop metrics and gc metrics are disabled, falling back to the JS implementation with out loading the native module.

Motivation

Additional Notes

@pabloerhard pabloerhard requested a review from a team as a code owner April 7, 2026 17:00
@pabloerhard pabloerhard requested review from ida613 and removed request for a team April 7, 2026 17:00
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

Overall package size

Self size: 5.48 MB
Deduped: 6.32 MB
No deduping: 6.32 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

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

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Apr 7, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 68.24% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 65b7c53 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@pabloerhard pabloerhard requested a review from rochdev April 7, 2026 17:09
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Apr 7, 2026

Benchmarks

Benchmark execution time: 2026-04-13 14:47:18

Comparing candidate commit 65b7c53 in PR branch pabloerhard/enable-non-native-runtime-metrics with baseline commit b4740a3 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 232 metrics, 28 unstable metrics.

nativeMetrics = null
// Only load native metrics when at least one native-backed feature is enabled.
// This avoids loading native code unnecessarily, which can crash in some environments.
if (trackEventLoop || trackGc) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While that makes sense, it hinders our ability to debug issues unless it's paired with a new option to override this behaviour. Because of this, I would say to add the option in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case, should we keep the trackEventLoop || trackGc flag? Since nativeMetrics does more than just event loop and GC metrics, and both of those can be disabled while native metrics still provide some type of value, I don’t see why we should keep using these flags as part of the conditional (This seems like a design mistake on my part from the beginning)

I think it should only use the option to decide wether to load the native add on or not, and not the paired condition.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm yeah I guess for now let's remove the optimization and focus only on the option, we can always re-evaluate later.

@pabloerhard pabloerhard requested a review from a team as a code owner April 7, 2026 21:03
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.82%. Comparing base (b4740a3) to head (65b7c53).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7942      +/-   ##
==========================================
- Coverage   73.82%   73.82%   -0.01%     
==========================================
  Files         773      773              
  Lines       35983    35985       +2     
==========================================
+ Hits        26566    26567       +1     
- Misses       9417     9418       +1     
Flag Coverage Δ
aiguard-macos 36.42% <ø> (-0.09%) ⬇️
aiguard-ubuntu 36.53% <ø> (-0.09%) ⬇️
aiguard-windows 36.33% <ø> (-0.09%) ⬇️
apm-capabilities-tracing-macos 48.43% <100.00%> (+<0.01%) ⬆️
apm-capabilities-tracing-ubuntu 48.46% <100.00%> (+<0.01%) ⬆️
apm-capabilities-tracing-windows 48.25% <100.00%> (+<0.01%) ⬆️
apm-integrations-child-process 36.06% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-18 34.98% <ø> (-0.09%) ⬇️
apm-integrations-couchbase-eol 35.03% <ø> (-0.09%) ⬇️
apm-integrations-oracledb 35.03% <ø> (-0.09%) ⬇️
appsec-express 52.79% <ø> (-0.10%) ⬇️
appsec-fastify 49.27% <ø> (-0.07%) ⬇️
appsec-graphql 49.62% <ø> (+0.02%) ⬆️
appsec-kafka 42.09% <ø> (-0.08%) ⬇️
appsec-ldapjs 41.39% <ø> (-0.08%) ⬇️
appsec-lodash 41.42% <ø> (-0.08%) ⬇️
appsec-macos 56.75% <ø> (-0.07%) ⬇️
appsec-mongodb-core 46.04% <ø> (-0.07%) ⬇️
appsec-mongoose 46.60% <ø> (-0.07%) ⬇️
appsec-mysql 48.73% <ø> (-0.07%) ⬇️
appsec-node-serialize 40.59% <ø> (-0.08%) ⬇️
appsec-passport 44.55% <ø> (-0.08%) ⬇️
appsec-postgres 48.41% <ø> (+0.03%) ⬆️
appsec-sourcing 40.05% <ø> (-0.08%) ⬇️
appsec-stripe 42.31% <ø> (-0.08%) ⬇️
appsec-template 40.75% <ø> (-0.08%) ⬇️
appsec-ubuntu 56.82% <ø> (-0.07%) ⬇️
appsec-windows 56.64% <ø> (-0.05%) ⬇️
instrumentations-instrumentation-bluebird 29.79% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 37.64% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 35.44% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 31.73% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express 31.95% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 31.85% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 37.27% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-fs 29.46% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 31.14% <ø> (ø)
instrumentations-instrumentation-http 36.88% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-knex 29.76% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 30.88% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-multer 37.42% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 35.38% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport 41.17% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport-http 40.86% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport-local 41.36% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-pg 34.90% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-promise 29.72% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise-js 29.73% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-q 29.76% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-url 29.72% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-when 29.74% <ø> (-0.10%) ⬇️
llmobs-ai 38.38% <ø> (-0.09%) ⬇️
llmobs-anthropic 37.84% <ø> (-0.09%) ⬇️
llmobs-bedrock 37.11% <ø> (-0.08%) ⬇️
llmobs-google-genai 37.53% <ø> (-0.08%) ⬇️
llmobs-langchain 37.10% <ø> (+0.03%) ⬆️
llmobs-openai 41.22% <ø> (-0.08%) ⬇️
llmobs-vertex-ai 37.63% <ø> (-0.15%) ⬇️
platform-core 31.10% <ø> (ø)
platform-esbuild 33.97% <ø> (ø)
platform-instrumentations-misc 40.97% <ø> (ø)
platform-shimmer 37.00% <ø> (ø)
platform-unit-guardrails 32.49% <ø> (ø)
platform-webpack 20.84% <ø> (ø)
plugins-azure-durable-functions 25.87% <ø> (ø)
plugins-azure-event-hubs 26.03% <ø> (ø)
plugins-azure-service-bus 25.40% <ø> (ø)
plugins-bullmq 40.60% <ø> (-0.22%) ⬇️
plugins-cassandra 35.17% <ø> (-0.09%) ⬇️
plugins-cookie 27.06% <ø> (ø)
plugins-cookie-parser 26.85% <ø> (ø)
plugins-crypto 26.55% <ø> (ø)
plugins-dd-trace-api 35.42% <ø> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.99% <ø> (ø)
plugins-express-session 26.81% <ø> (ø)
plugins-fastify 39.35% <ø> (-0.09%) ⬇️
plugins-fetch 35.71% <ø> (-0.09%) ⬇️
plugins-fs 35.67% <ø> (-0.10%) ⬇️
plugins-generic-pool 25.92% <ø> (ø)
plugins-google-cloud-pubsub 43.02% <ø> (-0.08%) ⬇️
plugins-grpc 38.02% <ø> (-0.09%) ⬇️
plugins-handlebars 27.03% <ø> (ø)
plugins-hapi 37.23% <ø> (-0.09%) ⬇️
plugins-hono 37.50% <ø> (-0.09%) ⬇️
plugins-ioredis 35.61% <ø> (-0.09%) ⬇️
plugins-knex 26.67% <ø> (ø)
plugins-langgraph 35.05% <ø> (-0.09%) ⬇️
plugins-ldapjs 24.45% <ø> (ø)
plugins-light-my-request 26.41% <ø> (ø)
plugins-limitd-client 30.00% <ø> (-0.10%) ⬇️
plugins-lodash 26.00% <ø> (ø)
plugins-mariadb 36.48% <ø> (-0.09%) ⬇️
plugins-memcached 35.26% <ø> (-0.09%) ⬇️
plugins-microgateway-core 36.31% <ø> (-0.09%) ⬇️
plugins-moleculer 38.03% <ø> (-0.09%) ⬇️
plugins-mongodb 36.37% <ø> (-0.09%) ⬇️
plugins-mongodb-core 36.07% <ø> (-0.09%) ⬇️
plugins-mongoose 36.01% <ø> (-0.17%) ⬇️
plugins-multer 26.81% <ø> (ø)
plugins-mysql 36.35% <ø> (-0.09%) ⬇️
plugins-mysql2 36.33% <ø> (-0.09%) ⬇️
plugins-node-serialize 27.10% <ø> (ø)
plugins-opensearch 35.05% <ø> (+0.04%) ⬆️
plugins-passport-http 26.85% <ø> (ø)
plugins-postgres 34.32% <ø> (-0.09%) ⬇️
plugins-process 26.55% <ø> (ø)
plugins-pug 27.06% <ø> (ø)
plugins-redis 35.82% <ø> (-0.08%) ⬇️
plugins-router 39.98% <ø> (-0.09%) ⬇️
plugins-sequelize 25.68% <ø> (ø)
plugins-test-and-upstream-amqp10 35.63% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-amqplib 40.83% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-apollo 36.50% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-avsc 35.52% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-bunyan 31.16% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 37.83% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-graphql 37.17% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-koa 37.44% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-protobufjs 35.73% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-rhea 40.91% <ø> (-0.09%) ⬇️
plugins-undici 36.52% <ø> (-0.09%) ⬇️
plugins-url 26.55% <ø> (ø)
plugins-valkey 35.28% <ø> (-0.10%) ⬇️
plugins-vm 26.55% <ø> (ø)
plugins-winston 31.60% <ø> (+0.04%) ⬆️
plugins-ws 38.92% <ø> (-0.09%) ⬇️
profiling-macos 37.94% <ø> (-0.09%) ⬇️
profiling-ubuntu 38.10% <ø> (-0.09%) ⬇️
profiling-windows 39.47% <ø> (-0.09%) ⬇️
serverless-azure-functions-client 25.75% <ø> (ø)
serverless-azure-functions-eventhubs 25.75% <ø> (ø)
serverless-azure-functions-servicebus 25.75% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

We should be aware that the monitorEventLoopDelay is somewhat broken in Node.js and even with our fix, it reports bad data. It is not a 1-to-1 fallback due to that and I am hesitant of doing this.

Comment thread packages/dd-trace/src/config/generated-config-types.d.ts Outdated
Comment thread packages/dd-trace/src/config/index.js Outdated
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

Adding the configuration, seems like an easy fix on our side. Being a user, I would probably never use it, if I do not have a strong need for it. Did this come up as a user request somewhere?

The only reason to not use the build-in methods is the broken Node.js behavior. So my suggestion is: let us fix that in Node.js get it backported, if possible (that might not be possible due to the drastic changed output with a fix) and to change the behavior as soon as that is the case.

Comment on lines -55 to -57
// Using no-gc prevents the native gc metrics from being tracked. Not
// passing any options means all metrics are tracked.
// TODO: This is a workaround. We should find a better solution.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be kept in place until it is changed in @datadog/native-metrics :)

Copy link
Copy Markdown
Contributor Author

@pabloerhard pabloerhard Apr 8, 2026

Choose a reason for hiding this comment

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

(Using this thread to respond to the above comment) This is more of a user need than a user request per se. We do have a follow-up Q2 task to fix and backport this to Node.js :)

@pabloerhard pabloerhard requested a review from rochdev April 8, 2026 14:19
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

I am good with adding this by immediately marking it as deprecated and adding a comment about it being removed in future versions by switching everything to built-in as soon as it is fixed on Node.js side

@pabloerhard pabloerhard requested a review from BridgeAR April 8, 2026 20:29
@pabloerhard
Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 Bot commented Apr 13, 2026

View all feedbacks in Devflow UI.

2026-04-13 15:31:53 UTC ℹ️ Start processing command /merge


2026-04-13 15:31:58 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 20m (p90).


2026-04-13 15:49:20 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit 90415cf:

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.

@pabloerhard pabloerhard merged commit 1e438f2 into master Apr 13, 2026
791 of 792 checks passed
@pabloerhard pabloerhard deleted the pabloerhard/enable-non-native-runtime-metrics branch April 13, 2026 15:51
dd-octo-sts Bot pushed a commit that referenced this pull request Apr 14, 2026
)

* prevent native metrics from loading when not needed

* added option to disableNative runtime metrics

* added env and changed option name

* added back comments

* changed native metrics conditional

* added native into config test

* undo changes done by IDE and fixed tests

* fix tests

* set back to only using config
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Apr 14, 2026
dd-octo-sts Bot pushed a commit that referenced this pull request Apr 15, 2026
)

* prevent native metrics from loading when not needed

* added option to disableNative runtime metrics

* added env and changed option name

* added back comments

* changed native metrics conditional

* added native into config test

* undo changes done by IDE and fixed tests

* fix tests

* set back to only using config
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Apr 15, 2026
juan-fernandez pushed a commit that referenced this pull request Apr 21, 2026
)

* prevent native metrics from loading when not needed

* added option to disableNative runtime metrics

* added env and changed option name

* added back comments

* changed native metrics conditional

* added native into config test

* undo changes done by IDE and fixed tests

* fix tests

* set back to only using config
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.

3 participants