-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(node-core): Move node fetch instrumentation into node-core #21873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,19 @@ | ||
| import type { IntegrationFn } from '@sentry/core'; | ||
| import { defineIntegration } from '@sentry/core'; | ||
| import { generateInstrumentOnce } from '../../otel/instrument'; | ||
| import { SentryNodeFetchInstrumentation } from './SentryNodeFetchInstrumentation'; | ||
|
|
||
| const INTEGRATION_NAME = 'NodeFetch'; | ||
|
|
||
| interface NodeFetchOptions { | ||
| /** | ||
| * Whether breadcrumbs should be recorded for requests. | ||
| * Defaults to true | ||
| */ | ||
| breadcrumbs?: boolean; | ||
|
|
||
| /** | ||
| * Whether to inject trace propagation headers (sentry-trace, baggage, traceparent) into outgoing fetch requests. | ||
| * | ||
| * @default `true` | ||
| */ | ||
| tracePropagation?: boolean; | ||
|
|
||
| /** | ||
| * Do not capture spans or breadcrumbs for outgoing fetch requests to URLs where the given callback returns `true`. | ||
| * This controls both span & breadcrumb creation - spans will be non recording if tracing is disabled. | ||
| */ | ||
| ignoreOutgoingRequests?: (url: string) => boolean; | ||
| } | ||
|
|
||
| const instrumentSentryNodeFetch = generateInstrumentOnce( | ||
| `${INTEGRATION_NAME}.sentry`, | ||
| SentryNodeFetchInstrumentation, | ||
| (options: NodeFetchOptions) => { | ||
| return options; | ||
| }, | ||
| ); | ||
| import type { NodeFetchOptions } from './types'; | ||
| import { instrumentUndici } from './undici-instrumentation'; | ||
|
|
||
| const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { | ||
| return { | ||
| name: 'NodeFetch' as const, | ||
| setupOnce() { | ||
| instrumentSentryNodeFetch(options); | ||
| instrumentUndici(options); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| }, | ||
| }; | ||
| }) satisfies IntegrationFn; | ||
|
|
||
| /** | ||
| * Instrument outgoing fetch requests made through the native node `fetch` API. | ||
| * This emits (depending on the integration options) spans and breadcrumbs, as well as injecting trace propagation headers into the request. | ||
| */ | ||
| export const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { instrumentUndici, type NodeFetchOptions } from '@sentry/node-core'; | ||
| import type { NodeClientOptions } from '../types'; | ||
| import type { IntegrationFn } from '@sentry/core'; | ||
| import { defineIntegration, getClient, hasSpansEnabled } from '@sentry/core'; | ||
|
|
||
| /** | ||
| * This is a variant of the node-core integration where the default for spans is different. | ||
| * In v11, this will be the only implementation. | ||
| */ | ||
| const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { | ||
| return { | ||
| name: 'NodeFetch' as const, | ||
| setupOnce() { | ||
| const clientOptions = getClient()?.getOptions(); | ||
| instrumentUndici({ | ||
| ...options, | ||
| spans: _shouldInstrumentSpans(options, clientOptions), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/getsentry/sentry-javascript/pull/21873/changes#r3504416417
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, in normal node setup we want to generally enable this, while in node-core it should always be opt-in to maintain the current behavior (where spans are never emitted) |
||
| }); | ||
| }, | ||
| }; | ||
| }) satisfies IntegrationFn; | ||
|
|
||
| /** | ||
| * Instrument outgoing fetch requests made through the native node `fetch` API. | ||
| * This emits (depending on the integration options) spans and breadcrumbs, as well as injecting trace propagation headers into the request. | ||
| */ | ||
| export const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration); | ||
|
|
||
| function _shouldInstrumentSpans(options: NodeFetchOptions, clientOptions: Partial<NodeClientOptions> = {}): boolean { | ||
| // If `spans` is passed in, it takes precedence | ||
| // Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true` or spans are not enabled | ||
| return options.spans ?? (!clientOptions.skipOpenTelemetrySetup && hasSpansEnabled(clientOptions)); | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed public fetch helper exports
Medium Severity
This change drops
addFetchRequestBreadcrumbandaddTracePropagationHeadersToFetchRequestfrom the@sentry/node-corepackage entry without a deprecation period, which is a breaking public API removal for anyone importing those helpers from the main export.Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit d4e9512. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was just added in the base-stack PR so should be fine