Skip to content

ref(node): Move node-fetch instrumentation away from InstrumentBase#21778

Open
mydea wants to merge 2 commits into
developfrom
fn/undici-no-otel
Open

ref(node): Move node-fetch instrumentation away from InstrumentBase#21778
mydea wants to merge 2 commits into
developfrom
fn/undici-no-otel

Conversation

@mydea

@mydea mydea commented Jun 25, 2026

Copy link
Copy Markdown
Member

This streamlines and de-otelifies the undici instrumentation in node package.

Note that there is still a OTEL instrumentation (channel based, but still) in node-core which can be updated in a separate follow up step.

This also updates to use sentry/conventions and drop any config we hard coded so far, streamlining this. Also, unsubscribe code was removed and other things we do not need were removed.

@mydea mydea self-assigned this Jun 25, 2026

@cursor cursor Bot 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 cc1a55a. Configure here.

Comment thread packages/node/src/integrations/node-fetch/undici-instrumentation.ts
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.47 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.97 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.76 kB - -
@sentry/browser (incl. Tracing, Replay) 85.22 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB +0.01% +1 B 🔺
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.63 kB - -
@sentry/vue (incl. Tracing) 47.84 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.89 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.4 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB - -
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.69 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 77.28 kB - -
@sentry/core/browser 63.63 kB - -
@sentry/node-core 61.51 kB +0.01% +1 B 🔺
@sentry/node 122.3 kB -0.29% -350 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.4 kB - -
@sentry/node - without tracing 73.2 kB -0.47% -344 B 🔽
@sentry/aws-serverless 84 kB -0.4% -333 B 🔽
@sentry/cloudflare (withSentry) - minified 180.31 kB - -
@sentry/cloudflare (withSentry) 446.24 kB - -

View base workflow run

@mydea mydea force-pushed the fn/undici-no-otel branch from cc1a55a to 1adc6ce Compare June 25, 2026 11:40
@mydea mydea marked this pull request as ready for review June 25, 2026 12:06
@mydea mydea requested a review from a team as a code owner June 25, 2026 12:06
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team June 25, 2026 12:06
Comment on lines -27 to -32
breadcrumbs?: boolean;

/**
* If set to false, do not emit any spans.
* This will ensure that the default UndiciInstrumentation from OpenTelemetry is not setup,
* only the Sentry-specific instrumentation for breadcrumbs & trace propagation is applied.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The tracePropagation: false option is ignored by the new instrumentUndici function, causing trace headers to be injected unconditionally for span instrumentation.
Severity: MEDIUM

Suggested Fix

Update the UndiciInstrumentationConfig type to include the tracePropagation option. Pass this option from the nativeNodeFetchIntegration options into instrumentUndici(). Finally, modify instrumentUndici() and its helper injectTracePropagationHeaders() to respect the tracePropagation flag and only inject headers when it is not false.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/node/src/integrations/node-fetch/index.ts#L27-L32

Potential issue: The new undici span instrumentation does not honor the
`tracePropagation: false` option. The `instrumentUndici()` function, which handles span
instrumentation, is called without the `tracePropagation` option and has no mechanism to
receive it. As a result, its internal `injectTracePropagationHeaders()` function is
always called, leading to trace headers being unconditionally injected for outgoing
requests when spans are enabled. This is a regression from previous behavior where the
option was respected, and it contradicts the user's explicit configuration.

Also affects:

  • packages/node/src/integrations/node-fetch/undici-instrumentation.ts:385~411

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +84 to +86
if (_channelSubs.length) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: In multi-client setups, only the first nativeNodeFetchIntegration configuration is respected; subsequent configurations for the integration are silently ignored.
Severity: MEDIUM

Suggested Fix

Remove the module-level singleton that makes the instrumentation idempotent with a 'first-call-wins' configuration. The integration's state should not be stored in a global, process-wide variable. Instead, configuration should be managed on a per-client basis to ensure that each Sentry client's nativeNodeFetchIntegration options are respected independently.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/node/src/integrations/node-fetch/undici-instrumentation.ts#L84-L86

Potential issue: The `instrumentUndici()` function is designed to be idempotent, using a
module-level singleton that latches onto the configuration from the first call. In a
multi-client scenario where multiple Sentry clients are initialized in the same process
with different `nativeNodeFetchIntegration` options, the configuration for all but the
first client will be silently ignored. This 'first-call-wins' behavior can lead to
unexpected outcomes, such as trace propagation being enabled when a subsequent client
configuration intended to disable it.

Did we get this right? 👍 / 👎 to inform future reviews.

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