Skip to content

feat(http): refactor node:http client instrumentation for portability#20393

Open
isaacs wants to merge 8 commits intodevelopfrom
isaacschlueter/portable-http-integration-client
Open

feat(http): refactor node:http client instrumentation for portability#20393
isaacs wants to merge 8 commits intodevelopfrom
isaacschlueter/portable-http-integration-client

Conversation

@isaacs
Copy link
Copy Markdown
Member

@isaacs isaacs commented Apr 20, 2026

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.

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

Closes #issue_link_here

@isaacs isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 1f9cef2 to 5ab332a Compare April 20, 2026 01:47
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.88 kB - -
@sentry/browser - with treeshaking flags 24.35 kB - -
@sentry/browser (incl. Tracing) 43.81 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 45.5 kB - -
@sentry/browser (incl. Tracing, Profiling) 48.73 kB - -
@sentry/browser (incl. Tracing, Replay) 82.98 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.5 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 87.67 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 99.93 kB - -
@sentry/browser (incl. Feedback) 42.7 kB - -
@sentry/browser (incl. sendFeedback) 30.55 kB - -
@sentry/browser (incl. FeedbackAsync) 35.55 kB - -
@sentry/browser (incl. Metrics) 27.16 kB - -
@sentry/browser (incl. Logs) 27.29 kB - -
@sentry/browser (incl. Metrics & Logs) 27.98 kB - -
@sentry/react 27.62 kB - -
@sentry/react (incl. Tracing) 46.05 kB - -
@sentry/vue 30.71 kB - -
@sentry/vue (incl. Tracing) 45.62 kB - -
@sentry/svelte 25.89 kB - -
CDN Bundle 28.55 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing) 44.94 kB - -
CDN Bundle (incl. Logs, Metrics) 29.93 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 46.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.89 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing, Replay) 81.96 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 83.02 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 87.46 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 88.55 kB +0.01% +4 B 🔺
CDN Bundle - uncompressed 83.4 kB - -
CDN Bundle (incl. Tracing) - uncompressed 134.3 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.55 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 137.72 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 211.12 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 251.75 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 255.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 264.66 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 268.05 kB - -
@sentry/nextjs (client) 48.58 kB - -
@sentry/sveltekit (client) 44.22 kB - -
@sentry/node-core 58.67 kB +1.13% +650 B 🔺
@sentry/node 167.19 kB -4.4% -7.69 kB 🔽
@sentry/node - without tracing 93.74 kB -4.32% -4.22 kB 🔽
@sentry/aws-serverless 107.7 kB -6.51% -7.5 kB 🔽

View base workflow run

@isaacs isaacs force-pushed the isaacschlueter/portable-http-integration-client branch 3 times, most recently from 18b93f6 to fd04ed5 Compare April 20, 2026 16:31
This was implemented for the portable Express integration, but others
will need the same functionality, so make it a reusable util.
isaacs added a commit that referenced this pull request Apr 20, 2026
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.
@isaacs isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 0877c6e to 1963717 Compare April 20, 2026 19:00
@isaacs isaacs marked this pull request as ready for review April 20, 2026 19:00
@isaacs isaacs requested review from andreiborza and mydea April 20, 2026 19:00
Comment thread packages/core/src/integrations/http/client-subscriptions.ts
isaacs added a commit that referenced this pull request Apr 20, 2026
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.
@isaacs isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 1963717 to 3e7001c Compare April 20, 2026 19:06
Comment thread packages/core/src/integrations/http/client-subscriptions.ts
Comment thread packages/core/src/integrations/http/instrument-outgoing-request.ts Outdated
isaacs added 2 commits April 20, 2026 13:12
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.
@isaacs isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 0307e3a to 640f8f0 Compare April 20, 2026 20:12
Comment thread packages/core/src/integrations/http/client-subscriptions.ts
Comment thread packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts Outdated
Comment thread packages/core/src/integrations/http/client-subscriptions.ts
Comment thread packages/node-core/src/light/integrations/httpIntegration.ts
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1b8377c. Configure here.

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant