Skip to content

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

Open
pabloerhard wants to merge 4 commits intomasterfrom
pabloerhard/enable-non-native-runtime-metrics
Open

fix(metrics): prevent native metrics from loading when not needed#7942
pabloerhard wants to merge 4 commits intomasterfrom
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.49 MB
Deduped: 6.33 MB
No deduping: 6.33 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.69% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ccb057f | 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-08 13:53:11

Comparing candidate commit ccb057f in PR branch pabloerhard/enable-non-native-runtime-metrics with baseline commit dba55f5 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 230 metrics, 30 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.
⚠️ Please upload report for BASE (master@dba55f5). Learn more about missing BASE report.
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7942   +/-   ##
=========================================
  Coverage          ?   74.24%           
=========================================
  Files             ?      769           
  Lines             ?    36080           
  Branches          ?        0           
=========================================
  Hits              ?    26788           
  Misses            ?     9292           
  Partials          ?        0           
Flag Coverage Δ
aiguard-macos 39.44% <100.00%> (?)
aiguard-ubuntu 39.56% <100.00%> (?)
aiguard-windows 39.23% <100.00%> (?)
apm-capabilities-tracing-macos 49.56% <100.00%> (?)
apm-capabilities-tracing-ubuntu 49.47% <100.00%> (?)
apm-capabilities-tracing-windows 49.34% <100.00%> (?)
apm-integrations-child-process 38.77% <100.00%> (?)
apm-integrations-couchbase-18 37.52% <100.00%> (?)
apm-integrations-couchbase-eol 38.04% <100.00%> (?)
apm-integrations-oracledb 37.87% <100.00%> (?)
appsec-express 55.37% <100.00%> (?)
appsec-fastify 51.71% <100.00%> (?)
appsec-graphql 51.87% <100.00%> (?)
appsec-kafka 44.48% <100.00%> (?)
appsec-ldapjs 44.11% <100.00%> (?)
appsec-lodash 43.71% <100.00%> (?)
appsec-macos 58.08% <100.00%> (?)
appsec-mongodb-core 48.89% <100.00%> (?)
appsec-mongoose 49.55% <100.00%> (?)
appsec-mysql 51.07% <100.00%> (?)
appsec-node-serialize 43.29% <100.00%> (?)
appsec-passport 47.75% <100.00%> (?)
appsec-postgres 50.70% <100.00%> (?)
appsec-sourcing 42.54% <100.00%> (?)
appsec-stripe 44.73% <100.00%> (?)
appsec-template 43.45% <100.00%> (?)
appsec-ubuntu 58.17% <100.00%> (?)
appsec-windows 57.89% <100.00%> (?)
instrumentations-instrumentation-bluebird 32.33% <100.00%> (?)
instrumentations-instrumentation-body-parser 40.63% <100.00%> (?)
instrumentations-instrumentation-child_process 38.07% <100.00%> (?)
instrumentations-instrumentation-cookie-parser 34.36% <100.00%> (?)
instrumentations-instrumentation-express 34.68% <100.00%> (?)
instrumentations-instrumentation-express-mongo-sanitize 34.49% <100.00%> (?)
instrumentations-instrumentation-express-session 40.27% <100.00%> (?)
instrumentations-instrumentation-fs 32.01% <100.00%> (?)
instrumentations-instrumentation-generic-pool 29.41% <ø> (?)
instrumentations-instrumentation-http 39.99% <100.00%> (?)
instrumentations-instrumentation-knex 32.40% <100.00%> (?)
instrumentations-instrumentation-mongoose 33.51% <100.00%> (?)
instrumentations-instrumentation-multer 40.38% <100.00%> (?)
instrumentations-instrumentation-mysql2 38.41% <100.00%> (?)
instrumentations-instrumentation-passport 44.16% <100.00%> (?)
instrumentations-instrumentation-passport-http 43.84% <100.00%> (?)
instrumentations-instrumentation-passport-local 44.37% <100.00%> (?)
instrumentations-instrumentation-pg 37.84% <100.00%> (?)
instrumentations-instrumentation-promise 32.26% <100.00%> (?)
instrumentations-instrumentation-promise-js 32.27% <100.00%> (?)
instrumentations-instrumentation-q 32.31% <100.00%> (?)
instrumentations-instrumentation-url 32.23% <100.00%> (?)
instrumentations-instrumentation-when 32.28% <100.00%> (?)
llmobs-ai 41.38% <100.00%> (?)
llmobs-anthropic 40.85% <100.00%> (?)
llmobs-bedrock 39.33% <100.00%> (?)
llmobs-google-genai 39.88% <100.00%> (?)
llmobs-langchain 39.45% <100.00%> (?)
llmobs-openai 44.12% <100.00%> (?)
llmobs-vertex-ai 40.14% <100.00%> (?)
platform-core 31.47% <ø> (?)
platform-esbuild 34.42% <ø> (?)
platform-instrumentations-misc 34.11% <ø> (?)
platform-shimmer 37.56% <ø> (?)
platform-unit-guardrails 32.89% <ø> (?)
platform-webpack 19.85% <0.00%> (?)
plugins-azure-durable-functions 25.74% <ø> (?)
plugins-azure-event-hubs 25.90% <ø> (?)
plugins-azure-service-bus 25.26% <ø> (?)
plugins-bullmq 43.60% <100.00%> (?)
plugins-cassandra 38.02% <100.00%> (?)
plugins-cookie 26.96% <ø> (?)
plugins-cookie-parser 26.75% <ø> (?)
plugins-crypto 26.73% <ø> (?)
plugins-dd-trace-api 38.43% <100.00%> (?)
plugins-express-mongo-sanitize 26.89% <ø> (?)
plugins-express-session 26.70% <ø> (?)
plugins-fastify 42.36% <100.00%> (?)
plugins-fetch 38.51% <100.00%> (?)
plugins-fs 38.76% <100.00%> (?)
plugins-generic-pool 25.94% <ø> (?)
plugins-google-cloud-pubsub 45.68% <100.00%> (?)
plugins-grpc 41.01% <100.00%> (?)
plugins-handlebars 26.94% <ø> (?)
plugins-hapi 40.27% <100.00%> (?)
plugins-hono 40.60% <100.00%> (?)
plugins-ioredis 38.60% <100.00%> (?)
plugins-knex 26.57% <ø> (?)
plugins-langgraph 37.99% <100.00%> (?)
plugins-ldapjs 24.43% <ø> (?)
plugins-light-my-request 26.30% <ø> (?)
plugins-limitd-client 32.61% <100.00%> (?)
plugins-lodash 26.03% <ø> (?)
plugins-mariadb 39.61% <100.00%> (?)
plugins-memcached 38.34% <100.00%> (?)
plugins-microgateway-core 39.34% <100.00%> (?)
plugins-moleculer 40.63% <100.00%> (?)
plugins-mongodb 39.28% <100.00%> (?)
plugins-mongodb-core 39.12% <100.00%> (?)
plugins-mongoose 38.92% <100.00%> (?)
plugins-multer 26.70% <ø> (?)
plugins-mysql 39.45% <100.00%> (?)
plugins-mysql2 39.41% <100.00%> (?)
plugins-node-serialize 27.00% <ø> (?)
plugins-opensearch 37.75% <100.00%> (?)
plugins-passport-http 26.76% <ø> (?)
plugins-postgres 35.54% <100.00%> (?)
plugins-process 26.73% <ø> (?)
plugins-pug 26.96% <ø> (?)
plugins-redis 39.04% <100.00%> (?)
plugins-router 43.36% <100.00%> (?)
plugins-sequelize 25.55% <ø> (?)
plugins-test-and-upstream-amqp10 38.62% <100.00%> (?)
plugins-test-and-upstream-amqplib 44.36% <100.00%> (?)
plugins-test-and-upstream-apollo 39.24% <100.00%> (?)
plugins-test-and-upstream-avsc 38.70% <100.00%> (?)
plugins-test-and-upstream-bunyan 33.94% <100.00%> (?)
plugins-test-and-upstream-connect 40.93% <100.00%> (?)
plugins-test-and-upstream-graphql 40.28% <100.00%> (?)
plugins-test-and-upstream-koa 40.66% <100.00%> (?)
plugins-test-and-upstream-protobufjs 38.92% <100.00%> (?)
plugins-test-and-upstream-rhea 44.37% <100.00%> (?)
plugins-undici 39.36% <100.00%> (?)
plugins-url 26.73% <ø> (?)
plugins-valkey 38.30% <100.00%> (?)
plugins-vm 26.73% <ø> (?)
plugins-winston 34.13% <100.00%> (?)
plugins-ws 42.12% <100.00%> (?)
profiling-macos 40.65% <100.00%> (?)
profiling-ubuntu 41.21% <100.00%> (?)
profiling-windows 42.29% <100.00%> (?)
serverless-azure-functions-client 25.62% <ø> (?)
serverless-azure-functions-eventhubs 25.62% <ø> (?)
serverless-azure-functions-servicebus 25.62% <ø> (?)

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.

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
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