Skip to content

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

Merged
isaacs merged 5 commits into
developfrom
isaacschlueter/portable-http-integration-client
May 5, 2026
Merged

feat(http): refactor node:http client instrumentation for portability#20393
isaacs merged 5 commits into
developfrom
isaacschlueter/portable-http-integration-client

Conversation

@isaacs

@isaacsisaacs commented Apr 20, 2026

Copy link
Copy Markdown
Member

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.

Notes on test changes:

  • The test changes are mostly owing to the fact that more versions are covered by some of the conditions, so the test gets un-indented, because it was previously conditionalTest on a node version.
  • The origin span data changes from the vague (and now incorrect) auto.http.otel.http to auto.http.client for client spans. This also affects a lot of the tests.

Otherwise, all prior behavior should be unchanged, which is reflected in the integration and unit tests.

@isaacs
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 1f9cef2 to 5ab332aCompareApril 20, 2026 01:47
@github-actions

github-actionsBot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser26.31 kB--
@sentry/browser - with treeshaking flags24.8 kB--
@sentry/browser (incl. Tracing)44.2 kB--
@sentry/browser (incl. Tracing + Span Streaming)46.42 kB--
@sentry/browser (incl. Tracing, Profiling)49.16 kB--
@sentry/browser (incl. Tracing, Replay)83.58 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags73.04 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)88.26 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)100.87 kB--
@sentry/browser (incl. Feedback)43.47 kB--
@sentry/browser (incl. sendFeedback)31.12 kB--
@sentry/browser (incl. FeedbackAsync)36.21 kB--
@sentry/browser (incl. Metrics)27.62 kB--
@sentry/browser (incl. Logs)27.75 kB--
@sentry/browser (incl. Metrics & Logs)28.45 kB--
@sentry/react28.05 kB--
@sentry/react (incl. Tracing)46.42 kB--
@sentry/vue31.18 kB--
@sentry/vue (incl. Tracing)46.04 kB--
@sentry/svelte26.34 kB--
CDN Bundle28.91 kB-0.02%-3 B 🔽
CDN Bundle (incl. Tracing)46.95 kB-0.02%-5 B 🔽
CDN Bundle (incl. Logs, Metrics)30.34 kB+0.01%+2 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics)48.06 kB-0.01%-3 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics)69.41 kB-0.01%-3 B 🔽
CDN Bundle (incl. Tracing, Replay)84.11 kB-0.01%-2 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)85.16 kB+0.01%+2 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback)89.91 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)90.99 kB-0.03%-25 B 🔽
CDN Bundle - uncompressed84.72 kB--
CDN Bundle (incl. Tracing) - uncompressed140.31 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed88.92 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed143.77 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed212.86 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed258.11 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed261.56 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed271.81 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed275.25 kB--
@sentry/nextjs (client)48.92 kB--
@sentry/sveltekit (client)44.67 kB--
@sentry/node-core59.82 kB+1.19%+700 B 🔺
@sentry/node163.37 kB-4.22%-7.19 kB 🔽
@sentry/node - without tracing72.29 kB-25.6%-24.87 kB 🔽
@sentry/aws-serverless106.97 kB-6.15%-7 kB 🔽
@sentry/cloudflare (withSentry) - minified165.2 kB--
@sentry/cloudflare (withSentry)417.71 kB--

View base workflow run

@isaacs
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch 3 times, most recently from 18b93f6 to fd04ed5CompareApril 20, 2026 16:31
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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 0877c6e to 1963717CompareApril 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 mydeaApril 20, 2026 19:00
Comment threadpackages/core/src/integrations/http/client-subscriptions.ts Outdated
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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 1963717 to 3e7001cCompareApril 20, 2026 19:06
Comment threadpackages/core/src/integrations/http/client-subscriptions.ts Outdated
Comment threadpackages/core/src/integrations/http/instrument-outgoing-request.ts Outdated
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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 0307e3a to 640f8f0CompareApril 20, 2026 20:12
Comment threadpackages/core/src/integrations/http/client-subscriptions.ts Outdated
Comment threadpackages/node-core/src/integrations/http/SentryHttpInstrumentation.ts Outdated
Comment threadpackages/core/src/integrations/http/client-subscriptions.ts
Comment threadpackages/node-core/src/light/integrations/httpIntegration.ts
Comment threadpackages/node-core/src/integrations/http/SentryHttpInstrumentation.ts Outdated
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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 1b8377c to 1a8d51eCompareApril 20, 2026 21:52
Comment threadpackages/core/src/integrations/http/client-subscriptions.ts
Comment threadpackages/node-core/src/utils/outgoingHttpRequest.ts
isaacs added a commit that referenced this pull request Apr 28, 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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 24f03e6 to eac6329CompareApril 28, 2026 18:33
@isaacs
isaacs marked this pull request as ready for review April 28, 2026 19:44
isaacs added a commit that referenced this pull request Apr 28, 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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from aacfec1 to edb38deCompareApril 28, 2026 20:04
Comment threadpackages/node-core/src/light/integrations/httpIntegration.ts
isaacs added a commit that referenced this pull request Apr 28, 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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from edb38de to 0c11611CompareApril 28, 2026 20:34
isaacs added a commit that referenced this pull request Apr 28, 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
isaacsforce-pushed the isaacschlueter/portable-http-integration-client branch from 0c11611 to 76df64dCompareApril 28, 2026 21:24
@isaacs
isaacs requested a review from JPeer264April 28, 2026 22:34

@JPeer264JPeer264 left a comment

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.

Amazing changes. LGTM.

@@ -0,0 +1,86 @@
import { createTestServer } from '@sentry-internal/test-utils';

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.

Extremely nice that there are tests for this scenario. Maybe it makes sense to display a warning in our docs too: https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/http/ (not sure if this is the best place to put it)

Comment threadpackages/core/src/utils/baggage.ts Outdated
Comment threadpackages/core/src/integrations/http/inject-trace-propagation-headers.ts Outdated
Comment threadpackages/core/src/integrations/http/client-patch.ts
Comment threadpackages/core/src/integrations/http/client-subscriptions.ts Outdated
Comment threadpackages/core/src/integrations/http/get-request-url.ts Outdated
Comment threadpackages/core/src/utils/url.ts Outdated
Comment threadpackages/core/src/integrations/http/get-request-url.ts
Comment threadpackages/core/src/integrations/http/get-request-url.ts

@cursorcursorBot left a comment

Copy link
Copy Markdown

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 616a2a0. Configure here.

Comment threadpackages/core/src/integrations/http/get-request-url.ts
@isaacs

Copy link
Copy Markdown
MemberAuthor

So, I added a commit to check for the OTel double-wrapping, which seems to work in any case I could think to test it. It dodges the timing issue by just checking and warning at run-time, and only prints a warning once, so it should be relatively polite. I think this is ready to merge at this point.

isaacs added 5 commits May 4, 2026 07:02
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.
Sign up for freeto 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.

5 participants

@isaacs@mydea@JPeer264@github-advanced-security@andreiborza