Skip to content

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

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

feat(http): refactor node:http client instrumentation for portability#20393
isaacs wants to merge 3 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.

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 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 26.16 kB - -
@sentry/browser - with treeshaking flags 24.63 kB - -
@sentry/browser (incl. Tracing) 44.13 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.34 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.08 kB - -
@sentry/browser (incl. Tracing, Replay) 83.48 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.96 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 88.15 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 100.8 kB - -
@sentry/browser (incl. Feedback) 43.4 kB - -
@sentry/browser (incl. sendFeedback) 30.96 kB - -
@sentry/browser (incl. FeedbackAsync) 36.14 kB - -
@sentry/browser (incl. Metrics) 27.44 kB - -
@sentry/browser (incl. Logs) 27.59 kB - -
@sentry/browser (incl. Metrics & Logs) 28.28 kB - -
@sentry/react 27.9 kB - -
@sentry/react (incl. Tracing) 46.36 kB - -
@sentry/vue 31.03 kB - -
@sentry/vue (incl. Tracing) 45.96 kB - -
@sentry/svelte 26.18 kB - -
CDN Bundle 28.84 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing) 46.91 kB - -
CDN Bundle (incl. Logs, Metrics) 30.27 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 48.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.35 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay) 84.07 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.14 kB -0.01% -3 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 89.86 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 90.95 kB -0.02% -13 B 🔽
CDN Bundle - uncompressed 84.55 kB - -
CDN Bundle (incl. Tracing) - uncompressed 140.16 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 88.75 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 143.62 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 212.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 257.96 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 261.41 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 271.66 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 275.1 kB - -
@sentry/nextjs (client) 48.85 kB - -
@sentry/sveltekit (client) 44.58 kB - -
@sentry/node-core 59.66 kB +1.04% +610 B 🔺
@sentry/node 162.89 kB -4.38% -7.45 kB 🔽
@sentry/node - without tracing 71.82 kB -25.89% -25.09 kB 🔽
@sentry/aws-serverless 106.5 kB -6.37% -7.25 kB 🔽
@sentry/cloudflare (withSentry) - minified 164.97 kB +0.01% +4 B 🔺
@sentry/cloudflare (withSentry) 417.12 kB +0.01% +21 B 🔺

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
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 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 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 Outdated
Comment thread packages/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 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 Outdated
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
Comment thread packages/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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 1b8377c to 1a8d51e Compare April 20, 2026 21:52
Comment thread packages/core/src/integrations/http/client-subscriptions.ts
Comment thread packages/node-core/src/utils/outgoingHttpRequest.ts
Comment thread packages/core/src/integrations/http/client-subscriptions.ts Outdated
Comment thread packages/core/src/integrations/http/client-subscriptions.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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 645dc0e to e88e5f5 Compare April 28, 2026 16:10
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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from e88e5f5 to ddd2987 Compare April 28, 2026 16:13
@isaacs isaacs marked this pull request as draft April 28, 2026 16:15
Comment thread packages/core/src/integrations/http/inject-trace-propagation-headers.ts Outdated
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.

There are 2 total unresolved issues (including 1 from previous review).

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 ddd2987. Configure here.

Comment thread packages/core/src/integrations/http/client-subscriptions.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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 24f03e6 to eac6329 Compare April 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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from aacfec1 to edb38de Compare April 28, 2026 20:04
Comment thread packages/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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from edb38de to 0c11611 Compare April 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 isaacs force-pushed the isaacschlueter/portable-http-integration-client branch from 0c11611 to 76df64d Compare April 28, 2026 21:24
@isaacs isaacs requested a review from JPeer264 April 28, 2026 22:34
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 left a comment

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)

const baggageEntry = `${encodeURIComponent(objectKey)}=${encodeURIComponent(objectValue)}`;
const newBaggageHeader = currentIndex === 0 ? baggageEntry : `${baggageHeader},${baggageEntry}`;
if (newBaggageHeader.length > MAX_BAGGAGE_STRING_LENGTH) {
/* v8 ignore start */
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.

q: Why exactly is this needed?

isaacs added 3 commits April 29, 2026 09:42
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 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.

4 participants