Skip to content

fix: always send telemetry for not instrumented code#6910

Merged
BridgeAR merged 29 commits intomasterfrom
BridgeAR/2025-11-13-further-instrumentation-improvements
Apr 9, 2026
Merged

fix: always send telemetry for not instrumented code#6910
BridgeAR merged 29 commits intomasterfrom
BridgeAR/2025-11-13-further-instrumentation-improvements

Conversation

@BridgeAR
Copy link
Copy Markdown
Member

This makes sure not instrumented code will always send out the
proper telemetry. Formerly, it would rely on any part of the file
being instrumented. Now, we properly check by version again. To
guarantee it is only logging it once, it is send with a timeout or
before the service ends in case that happens earlier.

It also fixes DD_TRACE_DISABLED_INSTRUMENTATIONS to work for
prefixed and unprefixed Node automatically in case either is
deactivated. Before, both would have to be deactivated.

In addition, it simplifies code, adds some JSDoc and makes sure
the Node.js version is added to Node.js modules in the telemetry /
failures.

This also fixes a couple of tests that were not properly checking
the behavior as some state was captured in the instrumentation.

This is based on another PR.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 13, 2025

Codecov Report

❌ Patch coverage is 83.41969% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.72%. Comparing base (9ed88dc) to head (0ff8dab).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...g-instrumentations/src/helpers/bundler-register.js 8.00% 23 Missing ⚠️
...s/datadog-instrumentations/src/helpers/register.js 90.00% 5 Missing ⚠️
...kages/datadog-instrumentations/src/helpers/hook.js 77.77% 2 Missing ⚠️
packages/dd-trace/src/require-package-json.js 75.00% 1 Missing ⚠️
packages/dd-trace/src/ritm.js 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6910      +/-   ##
==========================================
- Coverage   73.85%   73.72%   -0.14%     
==========================================
  Files         773      773              
  Lines       35959    36383     +424     
==========================================
+ Hits        26558    26823     +265     
- Misses       9401     9560     +159     
Flag Coverage Δ
aiguard-macos 35.62% <73.71%> (-0.87%) ⬇️
aiguard-ubuntu 35.72% <73.71%> (-0.87%) ⬇️
aiguard-windows 35.53% <73.71%> (-0.85%) ⬇️
apm-capabilities-tracing-macos 47.91% <80.97%> (-0.93%) ⬇️
apm-capabilities-tracing-ubuntu 47.99% <80.97%> (-0.89%) ⬇️
apm-capabilities-tracing-windows 47.78% <80.97%> (-0.88%) ⬇️
apm-integrations-child-process 35.27% <73.71%> (-0.86%) ⬇️
apm-integrations-couchbase-18 34.25% <75.42%> (-0.82%) ⬇️
apm-integrations-couchbase-eol 34.33% <75.42%> (-0.79%) ⬇️
apm-integrations-oracledb 34.32% <76.53%> (-0.80%) ⬇️
appsec-express 51.90% <78.60%> (-1.03%) ⬇️
appsec-fastify 48.45% <78.26%> (-0.96%) ⬇️
appsec-graphql 48.71% <77.29%> (-1.02%) ⬇️
appsec-kafka 41.30% <75.00%> (-0.87%) ⬇️
appsec-ldapjs 40.65% <76.11%> (-0.84%) ⬇️
appsec-lodash 40.67% <74.44%> (-0.84%) ⬇️
appsec-macos 55.81% <76.37%> (-1.04%) ⬇️
appsec-mongodb-core 45.23% <76.63%> (-0.89%) ⬇️
appsec-mongoose 45.79% <76.63%> (-0.94%) ⬇️
appsec-mysql 47.92% <77.41%> (-0.93%) ⬇️
appsec-node-serialize 39.86% <76.11%> (-0.82%) ⬇️
appsec-passport 43.70% <74.86%> (-1.00%) ⬇️
appsec-postgres 47.62% <76.63%> (-0.94%) ⬇️
appsec-sourcing 39.34% <76.11%> (-0.81%) ⬇️
appsec-stripe 41.51% <77.59%> (-0.89%) ⬇️
appsec-template 40.03% <76.66%> (-0.82%) ⬇️
appsec-ubuntu 55.88% <76.37%> (-1.05%) ⬇️
appsec-windows 55.71% <76.37%> (-1.02%) ⬇️
instrumentations-instrumentation-bluebird 29.15% <69.14%> (-0.85%) ⬇️
instrumentations-instrumentation-body-parser 36.90% <77.04%> (-0.83%) ⬇️
instrumentations-instrumentation-child_process 34.66% <73.71%> (-0.85%) ⬇️
instrumentations-instrumentation-cookie-parser 31.12% <71.03%> (-0.81%) ⬇️
instrumentations-instrumentation-express 31.33% <71.03%> (-0.89%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 31.24% <71.03%> (-0.81%) ⬇️
instrumentations-instrumentation-express-session 36.54% <77.04%> (-0.86%) ⬇️
instrumentations-instrumentation-fs 28.83% <67.42%> (-0.81%) ⬇️
instrumentations-instrumentation-generic-pool 31.12% <69.32%> (-0.32%) ⬇️
instrumentations-instrumentation-http 36.11% <75.41%> (-0.84%) ⬇️
instrumentations-instrumentation-knex 29.13% <69.14%> (-0.89%) ⬇️
instrumentations-instrumentation-mongoose 30.29% <70.39%> (-0.83%) ⬇️
instrumentations-instrumentation-multer 36.68% <77.04%> (-0.83%) ⬇️
instrumentations-instrumentation-mysql2 34.59% <76.13%> (-0.89%) ⬇️
instrumentations-instrumentation-passport 40.40% <74.86%> (-0.92%) ⬇️
instrumentations-instrumentation-passport-http 40.10% <74.86%> (-0.92%) ⬇️
instrumentations-instrumentation-passport-local 40.59% <74.86%> (-0.93%) ⬇️
instrumentations-instrumentation-pg 34.12% <75.42%> (-0.87%) ⬇️
instrumentations-instrumentation-promise 29.09% <69.14%> (-0.84%) ⬇️
instrumentations-instrumentation-promise-js 29.09% <69.14%> (-0.85%) ⬇️
instrumentations-instrumentation-q 29.12% <69.14%> (-0.85%) ⬇️
instrumentations-instrumentation-url 29.08% <67.42%> (-0.82%) ⬇️
instrumentations-instrumentation-when 29.10% <69.14%> (-0.85%) ⬇️
llmobs-ai 38.46% <75.42%> (+0.09%) ⬆️
llmobs-anthropic 37.73% <77.09%> (-0.23%) ⬇️
llmobs-bedrock 37.01% <78.57%> (-0.23%) ⬇️
llmobs-google-genai 37.57% <77.09%> (-0.07%) ⬇️
llmobs-langchain 37.60% <78.57%> (+0.47%) ⬆️
llmobs-openai 41.49% <77.09%> (+0.17%) ⬆️
llmobs-vertex-ai 37.67% <77.09%> (-0.14%) ⬇️
platform-core 31.10% <10.71%> (+0.27%) ⬆️
platform-esbuild 33.97% <10.71%> (+0.22%) ⬆️
platform-instrumentations-misc 40.97% <10.71%> (+0.08%) ⬆️
platform-shimmer 37.00% <10.71%> (+0.19%) ⬆️
platform-unit-guardrails 32.49% <10.71%> (+0.25%) ⬆️
platform-webpack 20.79% <69.61%> (-0.17%) ⬇️
plugins-azure-durable-functions 25.87% <19.44%> (+0.49%) ⬆️
plugins-azure-event-hubs 26.03% <19.44%> (+0.49%) ⬆️
plugins-azure-service-bus 25.40% <19.44%> (+0.48%) ⬆️
plugins-bullmq 39.82% <75.42%> (-0.97%) ⬇️
plugins-cassandra 34.46% <77.22%> (-0.80%) ⬇️
plugins-cookie 27.06% <19.44%> (+0.49%) ⬆️
plugins-cookie-parser 26.85% <19.44%> (+0.49%) ⬆️
plugins-crypto 26.55% <10.71%> (+0.33%) ⬆️
plugins-dd-trace-api 34.65% <73.71%> (-0.83%) ⬇️
plugins-express-mongo-sanitize 26.99% <19.44%> (+0.49%) ⬆️
plugins-express-session 26.81% <19.44%> (+0.49%) ⬆️
plugins-fastify 38.58% <78.68%> (-0.94%) ⬇️
plugins-fetch 35.03% <75.40%> (-0.75%) ⬇️
plugins-fs 34.91% <73.71%> (-0.82%) ⬇️
plugins-generic-pool 25.92% <19.44%> (+0.34%) ⬆️
plugins-google-cloud-pubsub 42.18% <77.90%> (-0.93%) ⬇️
plugins-grpc 37.27% <77.34%> (-0.86%) ⬇️
plugins-handlebars 27.03% <19.44%> (+0.49%) ⬆️
plugins-hapi 36.50% <77.09%> (-0.83%) ⬇️
plugins-hono 36.76% <77.34%> (-0.85%) ⬇️
plugins-ioredis 34.86% <75.42%> (-0.84%) ⬇️
plugins-knex 26.67% <19.44%> (+0.46%) ⬆️
plugins-langgraph 34.33% <75.42%> (-0.84%) ⬇️
plugins-ldapjs 24.45% <19.44%> (+0.33%) ⬆️
plugins-light-my-request 26.41% <19.44%> (+0.48%) ⬆️
plugins-limitd-client 29.36% <69.14%> (-0.90%) ⬇️
plugins-lodash 26.00% <19.44%> (+0.34%) ⬆️
plugins-mariadb 35.71% <76.57%> (-0.88%) ⬇️
plugins-memcached 34.52% <75.42%> (-0.83%) ⬇️
plugins-microgateway-core 35.60% <77.09%> (-0.85%) ⬇️
plugins-moleculer 37.24% <77.09%> (-0.88%) ⬇️
plugins-mongodb 35.64% <76.53%> (-0.82%) ⬇️
plugins-mongodb-core 35.35% <75.42%> (-0.84%) ⬇️
plugins-mongoose 35.37% <76.53%> (-0.76%) ⬇️
plugins-multer 26.81% <19.44%> (+0.49%) ⬆️
plugins-mysql 35.58% <75.42%> (-0.86%) ⬇️
plugins-mysql2 35.57% <76.13%> (-0.86%) ⬇️
plugins-node-serialize 27.10% <19.44%> (+0.49%) ⬆️
plugins-opensearch 34.23% <77.09%> (-0.79%) ⬇️
plugins-passport-http 26.85% <19.44%> (+0.48%) ⬆️
plugins-postgres 33.64% <75.42%> (-0.78%) ⬇️
plugins-process 26.55% <10.71%> (+0.33%) ⬆️
plugins-pug 27.06% <19.44%> (+0.49%) ⬆️
plugins-redis 35.06% <75.42%> (-0.94%) ⬇️
plugins-router 39.16% <76.53%> (-0.93%) ⬇️
plugins-sequelize 25.68% <21.62%> (+0.49%) ⬆️
plugins-test-and-upstream-amqp10 34.88% <75.42%> (-0.84%) ⬇️
plugins-test-and-upstream-amqplib 39.94% <75.42%> (-0.97%) ⬇️
plugins-test-and-upstream-apollo 35.82% <77.59%> (-0.79%) ⬇️
plugins-test-and-upstream-avsc 34.75% <69.14%> (-0.97%) ⬇️
plugins-test-and-upstream-bunyan 30.51% <69.14%> (-0.86%) ⬇️
plugins-test-and-upstream-connect 37.07% <76.53%> (-0.86%) ⬇️
plugins-test-and-upstream-graphql 36.40% <75.42%> (-0.87%) ⬇️
plugins-test-and-upstream-koa 36.69% <77.09%> (-0.88%) ⬇️
plugins-test-and-upstream-protobufjs 34.96% <69.14%> (-0.97%) ⬇️
plugins-test-and-upstream-rhea 40.02% <75.42%> (-1.00%) ⬇️
plugins-undici 35.81% <77.83%> (-0.87%) ⬇️
plugins-url 26.55% <10.71%> (+0.33%) ⬆️
plugins-valkey 34.54% <75.42%> (-0.82%) ⬇️
plugins-vm 26.55% <10.71%> (+0.33%) ⬆️
plugins-winston 30.97% <70.94%> (-0.71%) ⬇️
plugins-ws 38.12% <77.09%> (-0.90%) ⬇️
profiling-macos 37.11% <66.28%> (-1.04%) ⬇️
profiling-ubuntu 37.27% <66.28%> (-1.04%) ⬇️
profiling-windows 38.66% <70.28%> (-0.96%) ⬇️
serverless-azure-functions-client 25.75% <19.44%> (+0.49%) ⬆️
serverless-azure-functions-eventhubs 25.75% <19.44%> (+0.49%) ⬆️
serverless-azure-functions-servicebus 25.75% <19.44%> (+0.49%) ⬆️

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.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Nov 13, 2025

Benchmarks

Benchmark execution time: 2026-04-09 17:56:15

Comparing candidate commit 0ff8dab in PR branch BridgeAR/2025-11-13-further-instrumentation-improvements with baseline commit 9ed88dc in branch master.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 13, 2025

Overall package size

Self size: 5.47 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-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Nov 13, 2025

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 77.72%
Overall Coverage: 68.24% (-0.04%)

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

This improves our instrumentations in multiple ways:

- Add JSDoc to many methods that it is easier to work with.
- Fix multiple type errors.
- Remove code that was only used in testing such as `unhook()`.
- Fix small issues in esbuild instrumentation where a module might
  not return a moduleExports object.
- Improve code to run slightly faster (these are not hot code paths).
- Automatically instruments unprefixed Node.js modules when defining
  a instrumentation for a module. This removes the need for much special
  handling (duplicating the instrumentation, using the symbol to detect
  already instrumented calls, etc.).
- Fix using an array as file for some modules. This did not cause any
  issues, but it was not correct.
- Removed unused isIitm arguments in instrumentations.
This is supported by ritm, we just do not utilize it and do not
need it as such.
This makes sure not instrumented code will always send out the
proper telemetry. Formerly, it would rely on any part of the file
being instrumented. Now, we properly check by version again. To
guarantee it is only logging it once, it is send with a timeout or
before the service ends in case that happens earlier.

It also fixes DD_TRACE_DISABLED_INSTRUMENTATIONS to work for
prefixed and unprefixed Node automatically in case either is
deactivated. Before, both would have to be deactivated.

In addition, it simplifies code, adds some JSDoc and makes sure
the Node.js version is added to Node.js modules in the telemetry /
failures.

This also fixes a couple of tests that were not properly checking
the behavior as some state was captured in the instrumentation.
@BridgeAR BridgeAR force-pushed the BridgeAR/2025-11-13-further-instrumentation-improvements branch from 71731fa to 21af9f5 Compare November 20, 2025 04:04
@pabloerhard pabloerhard force-pushed the BridgeAR/2025-11-13-further-instrumentation-improvements branch from f62fe6c to a218578 Compare November 25, 2025 21:51
Comment thread packages/datadog-esbuild/index.js Outdated
try {
loadChannel.publish({ name, version: payload.version, file })
payload.module = hook(payload.module, payload.version)
payload.module = hook(payload.module, payload.version) ?? payload.module
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note: we might have to pass through if iitm is used or not for prisma

Comment thread packages/datadog-instrumentations/src/helpers/instrument.js Outdated
Comment thread packages/datadog-instrumentations/src/helpers/register.js Outdated
Comment thread eslint.config.mjs Outdated
@BridgeAR BridgeAR marked this pull request as ready for review February 27, 2026 12:44
@BridgeAR BridgeAR requested review from a team as code owners February 27, 2026 12:44
@BridgeAR BridgeAR requested review from ida613 and shreyamalpani and removed request for a team February 27, 2026 12:44
@pabloerhard pabloerhard requested a review from a team as a code owner March 2, 2026 15:24
Comment thread packages/datadog-esbuild/index.js Outdated
Comment on lines +187 to +188
args.path.startsWith('@') &&
!args.importer.includes('node_modules/')) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
args.path.startsWith('@') &&
!args.importer.includes('node_modules/')) {
args.path.startsWith('@') &&
!args.importer.includes('node_modules/')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had added that change :/ adding it back.

return !version || !ranges || ranges.some(range => satisfies(version, range))
}
globalThis[Symbol.for('dd-trace')]?.beforeExitHandlers.add(logAbortedIntegrations)
channel('dd-trace:exporter:first-flush').subscribe(logAbortedIntegrations)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Using a DC channel will work, while I wonder why we not just use a plain method that we export.

This cuts through all layers, I am just not sure if I find this elegant or not ideal 😆
Maybe someone else might want to chime in? @bengl @rochdev @watson

Copy link
Copy Markdown
Contributor

@pabloerhard pabloerhard Mar 27, 2026

Choose a reason for hiding this comment

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

Do we want to refactor this? Before conflicts keep growing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggestion after speaking with @bengl: let's use the way that requires the minimum changes for now since this provides actual value, no matter if it is implemented one way or the other.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's keep this as is for now, and refactor later if/when we decide to cull the single-use diagnostics channel pattern.

Copy link
Copy Markdown
Member Author

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

LGTM, I can just not approve the PR alone

@BridgeAR BridgeAR merged commit e92e7f0 into master Apr 9, 2026
845 of 846 checks passed
@BridgeAR BridgeAR deleted the BridgeAR/2025-11-13-further-instrumentation-improvements branch April 9, 2026 19:21
dd-octo-sts Bot pushed a commit that referenced this pull request Apr 10, 2026
* chore: improve instrumentation hooks

This improves our instrumentations in multiple ways:

- Add JSDoc to many methods that it is easier to work with.
- Fix multiple type errors.
- Remove code that was only used in testing such as `unhook()`.
- Fix small issues in esbuild instrumentation where a module might
  not return a moduleExports object.
- Improve code to run slightly faster (these are not hot code paths).
- Automatically instruments unprefixed Node.js modules when defining
  a instrumentation for a module. This removes the need for much special
  handling (duplicating the instrumentation, using the symbol to detect
  already instrumented calls, etc.).
- Fix using an array as file for some modules. This did not cause any
  issues, but it was not correct.
- Removed unused isIitm arguments in instrumentations.
- Removed unused ritm code.
- Removed HOOK_SYMBOL code.

* fix: always send telemetry for not instrumented code

This makes sure not instrumented code will always send out the
proper telemetry. Formerly, it would rely on any part of the file
being instrumented. Now, we properly check by version again. To
guarantee it is only logging it once, it is send the data on the
first flush or before the service ends in case that happens earlier.

It also fixes DD_TRACE_DISABLED_INSTRUMENTATIONS to work for
prefixed and unprefixed Node automatically in case either is
deactivated. Before, both would have to be deactivated.

In addition, it simplifies code, adds some JSDoc and makes sure
the Node.js version is added to Node.js modules in the telemetry /
failures.

This also fixes a couple of tests that were not properly checking
the behavior as some state was captured in the instrumentation.

---------

Co-authored-by: Pablo Erhard <pabloerhard02@gmail.com>
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Apr 10, 2026
juan-fernandez pushed a commit that referenced this pull request Apr 10, 2026
* chore: improve instrumentation hooks

This improves our instrumentations in multiple ways:

- Add JSDoc to many methods that it is easier to work with.
- Fix multiple type errors.
- Remove code that was only used in testing such as `unhook()`.
- Fix small issues in esbuild instrumentation where a module might
  not return a moduleExports object.
- Improve code to run slightly faster (these are not hot code paths).
- Automatically instruments unprefixed Node.js modules when defining
  a instrumentation for a module. This removes the need for much special
  handling (duplicating the instrumentation, using the symbol to detect
  already instrumented calls, etc.).
- Fix using an array as file for some modules. This did not cause any
  issues, but it was not correct.
- Removed unused isIitm arguments in instrumentations.
- Removed unused ritm code.
- Removed HOOK_SYMBOL code.

* fix: always send telemetry for not instrumented code

This makes sure not instrumented code will always send out the
proper telemetry. Formerly, it would rely on any part of the file
being instrumented. Now, we properly check by version again. To
guarantee it is only logging it once, it is send the data on the
first flush or before the service ends in case that happens earlier.

It also fixes DD_TRACE_DISABLED_INSTRUMENTATIONS to work for
prefixed and unprefixed Node automatically in case either is
deactivated. Before, both would have to be deactivated.

In addition, it simplifies code, adds some JSDoc and makes sure
the Node.js version is added to Node.js modules in the telemetry /
failures.

This also fixes a couple of tests that were not properly checking
the behavior as some state was captured in the instrumentation.

---------

Co-authored-by: Pablo Erhard <pabloerhard02@gmail.com>
wconti27 added a commit that referenced this pull request Apr 24, 2026
Temporary mitigation for increased before all hook timeouts causing CI
health to drop from >90% to ~70%. Root cause is accumulated agent
instance overhead from #6910; proper fix tracked separately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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