feat(http): refactor node:http client instrumentation for portability#20393
feat(http): refactor node:http client instrumentation for portability#20393
Conversation
1f9cef2 to
5ab332a
Compare
size-limit report 📦
|
18b93f6 to
fd04ed5
Compare
This was implemented for the portable Express integration, but others will need the same functionality, so make it a reusable util.
Refactor the `node:http` outgoing request instrumentation so that it can be applied to non-Node.js environments by patching the http module. Also, refactor so that the diagnostics_channel and monkeypatching paths can share code, and so that light and normal node-core instrumentations can share more of the functionality as well. To facilitate this, some portable minimal types are vendored in from the `node:http` module.
0877c6e to
1963717
Compare
Refactor the `node:http` outgoing request instrumentation so that it can be applied to non-Node.js environments by patching the http module. Also, refactor so that the diagnostics_channel and monkeypatching paths can share code, and so that light and normal node-core instrumentations can share more of the functionality as well. To facilitate this, some portable minimal types are vendored in from the `node:http` module.
1963717 to
3e7001c
Compare
Refactor the `node:http` outgoing request instrumentation so that it can be applied to non-Node.js environments by patching the http module. Also, refactor so that the diagnostics_channel and monkeypatching paths can share code, and so that light and normal node-core instrumentations can share more of the functionality as well. To facilitate this, some portable minimal types are vendored in from the `node:http` module.
0307e3a to
640f8f0
Compare
…ent instrumentation (#20393)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1b8377c. Configure here.
| type IncomingHttpHeaders = http.IncomingHttpHeaders; | ||
| type OutgoingHttpHeaders = http.OutgoingHttpHeaders; | ||
| const FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL = | ||
| (NODE_VERSION.major === 18 && NODE_VERSION.minor >= 7) || NODE_VERSION.major >= 20; |
There was a problem hiding this comment.
Wrong Node version check breaks HTTP instrumentation on Node 20
High Severity
FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL checks for Node 18.7+ or 20+, but the http.client.request.created diagnostics channel (used via HTTP_ON_CLIENT_REQUEST) was only added in Node 22.12.0. On Node 20 and 21, this evaluates to true, causing the code to subscribe to a non-existent diagnostics channel instead of falling back to monkey-patching via patchHttpModuleClient. The subscription silently succeeds but never fires, so no outgoing HTTP spans, breadcrumbs, or trace propagation headers are produced. The old code correctly checked for Node 22.12+ / 23.2+ / 24+. Multiple test comments in the repo also confirm: "This test requires Node.js 22+ because it depends on the http.client.request.created".
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 1b8377c. Configure here.
There was a problem hiding this comment.
This is untrue. Verified empirically.
All 4 of http.{server,client}.{request.start,response.finish} landed on node/main on nodejs/node@b20838a207c, and then backported to node v18.7.0 on nodejs/node@8c97f634013. It's only the http.client.request.error and http.server.request.error channels that were added later. However, since we add an errorMonitor listener to the request object, this case is covered.


Refactor the
node:httpoutgoing request instrumentation so that it canbe applied to non-Node.js environments by patching the http module.
Also, refactor so that the diagnostics_channel and monkeypatching paths
can share code, and so that light and normal node-core instrumentations
can share more of the functionality as well.
To facilitate this, some portable minimal types are vendored in from the
node:httpmodule.yarn lint) & (yarn test).Closes #issue_link_here