fix: always send telemetry for not instrumented code#6910
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-04-09 17:56:15 Comparing candidate commit 0ff8dab in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 230 metrics, 30 unstable metrics. |
Overall package sizeSelf size: 5.47 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 |
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 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.
71731fa to
21af9f5
Compare
f62fe6c to
a218578
Compare
| try { | ||
| loadChannel.publish({ name, version: payload.version, file }) | ||
| payload.module = hook(payload.module, payload.version) | ||
| payload.module = hook(payload.module, payload.version) ?? payload.module |
There was a problem hiding this comment.
Note: we might have to pass through if iitm is used or not for prisma
| args.path.startsWith('@') && | ||
| !args.importer.includes('node_modules/')) { |
There was a problem hiding this comment.
| args.path.startsWith('@') && | |
| !args.importer.includes('node_modules/')) { | |
| args.path.startsWith('@') && | |
| !args.importer.includes('node_modules/')) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Do we want to refactor this? Before conflicts keep growing
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Let's keep this as is for now, and refactor later if/when we decide to cull the single-use diagnostics channel pattern.
BridgeAR
left a comment
There was a problem hiding this comment.
LGTM, I can just not approve the PR alone
* 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>
* 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>
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>
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.