Skip to content

Commit 72e8bec

Browse files
JPeer264claude
andcommitted
fixup! fix(bun, node): Fix channel GC, http.server spans and fetch spans on Bun
Drop the fetch fallback of nativeNodeFetchIntegration. Its module-level createFetchIntegration() call added about 2.5 KB gzip to every @sentry/node bundle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e6e2594 commit 72e8bec

5 files changed

Lines changed: 34 additions & 90 deletions

File tree

‎dev-packages/bun-integration-tests/node-suites/excludes.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ const NODE_ONLY = [
1010
'suites/thread-blocked-native/test.ts',
1111
];
1212

13-
// Bun's `fetch` does not use undici, so `nativeNodeFetchIntegration` patches the global `fetch`
14-
// there. That fallback does not support `requestHook`, `responseHook` and `headersToSpanAttributes`,
15-
// and its breadcrumb and span data differ from the undici instrumentation in these suites. Some of
16-
// them also send outgoing `node:http` requests (JS-3507).
17-
const FETCH_FALLBACK_DIFFERENCES = [
18-
'suites/tracing/double-baggage/spans-parent/test.ts',
13+
// `@sentry/node` instruments `fetch` through undici's diagnostics channels, which Bun's `fetch`
14+
// does not publish. `@sentry/bun` has its own `fetchIntegration` for this.
15+
const NO_FETCH_INSTRUMENTATION = [
16+
'suites/tracing/double-baggage/**',
17+
'suites/tracing/http-client-span-streamed/test.ts',
18+
'suites/tracing/http-client-spans/fetch-basic-streamed/test.ts',
19+
'suites/tracing/http-client-spans/fetch-basic/test.ts',
20+
'suites/tracing/http-client-spans/fetch-error/test.ts',
1921
'suites/tracing/http-client-spans/fetch-forward-request-hook/test.ts',
2022
'suites/tracing/http-client-spans/fetch-headers-to-span-attributes/test.ts',
2123
'suites/tracing/http-client-spans/fetch-strip-query/test.ts',
2224
'suites/tracing/no-parent-span-client-report/test.ts',
2325
'suites/tracing/requests/fetch-breadcrumbs/test.ts',
2426
'suites/tracing/requests/fetch-no-trace-propagation/test.ts',
27+
'suites/tracing/requests/fetch-no-tracing-no-spans/test.ts',
28+
'suites/tracing/requests/fetch-no-tracing/test.ts',
2529
'suites/tracing/requests/fetch-sampled-no-active-span/test.ts',
30+
'suites/tracing/requests/fetch-unsampled/test.ts',
2631
'suites/tracing/requests/traceparent/test.ts',
32+
'suites/tracing/sample-rand-propagation/test.ts',
33+
'suites/tracing/sample-rate-propagation/**',
2734
];
2835

2936
// JS-3507: Bun 1.3.14 (the CI version) does not instrument outgoing `node:http` requests. These
@@ -124,7 +131,7 @@ const NOT_TRIAGED = [
124131
export const NODE_SUITES_EXCLUDE = [
125132
'**/node_modules/**',
126133
...NODE_ONLY,
127-
...FETCH_FALLBACK_DIFFERENCES,
134+
...NO_FETCH_INSTRUMENTATION,
128135
...NO_OUTGOING_HTTP_INSTRUMENTATION,
129136
...NO_AUTO_INSTRUMENTATION,
130137
...NOT_TRIAGED,

‎dev-packages/bun-integration-tests/vite.config.mts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ export default defineConfig({
6969
'suites/public-api/logs/test.ts',
7070
// `@sentry/bun` has `bunRuntimeMetricsIntegration` instead of `nodeRuntimeMetricsIntegration`.
7171
'suites/node-runtime-metrics/test.ts',
72-
// `@sentry/bun` instruments `fetch` with its own `fetchIntegration`, which uses another span
73-
// origin, and it does not export `nativeNodeFetchIntegration`.
74-
'suites/tracing/http-client-spans/fetch-basic/test.ts',
75-
'suites/tracing/http-client-spans/fetch-error/test.ts',
76-
'suites/tracing/requests/fetch-no-tracing-no-spans/test.ts',
7772
],
7873
env: {
7974
RUNTIME: 'bun',

‎dev-packages/deno-integration-tests/node-suites/excludes.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@
44
// Node-only features: ANR and native thread watchdogs, child process and worker thread breadcrumbs.
55
const NODE_ONLY = ['suites/anr/test.ts', 'suites/breadcrumbs/**', 'suites/thread-blocked-native/test.ts'];
66

7-
// Deno's `fetch` does not use undici, so `nativeNodeFetchIntegration` patches the global `fetch`
8-
// there. That fallback does not support `requestHook`, `responseHook` and `headersToSpanAttributes`,
9-
// and its breadcrumb and span data differ from the undici instrumentation in these suites.
10-
const FETCH_FALLBACK_DIFFERENCES = [
7+
// `@sentry/node` instruments `fetch` through undici's diagnostics channels, which Deno's `fetch`
8+
// does not publish. `@sentry/deno` has its own `fetchIntegration` for this. These suites check
9+
// spans, breadcrumbs or headers of outgoing `fetch` requests.
10+
const NO_FETCH_INSTRUMENTATION = [
11+
'suites/tracing/double-baggage/**',
12+
'suites/tracing/http-client-span-streamed/test.ts',
13+
'suites/tracing/http-client-spans/fetch-basic-streamed/test.ts',
14+
'suites/tracing/http-client-spans/fetch-basic/test.ts',
15+
'suites/tracing/http-client-spans/fetch-error/test.ts',
1116
'suites/tracing/http-client-spans/fetch-forward-request-hook/test.ts',
1217
'suites/tracing/http-client-spans/fetch-headers-to-span-attributes/test.ts',
1318
'suites/tracing/http-client-spans/fetch-strip-query/test.ts',
19+
'suites/tracing/ignoreSpans-streamed/continued-trace-child/test.ts',
1420
'suites/tracing/ignoreSpans-streamed/continued-trace-http-client/test.ts',
21+
'suites/tracing/ignoreSpans-streamed/continued-trace-segment/test.ts',
22+
'suites/tracing/no-parent-span-client-report/test.ts',
1523
'suites/tracing/requests/fetch-breadcrumbs/test.ts',
1624
'suites/tracing/requests/fetch-no-trace-propagation/test.ts',
25+
'suites/tracing/requests/fetch-no-tracing-no-spans/test.ts',
26+
'suites/tracing/requests/fetch-no-tracing/test.ts',
1727
'suites/tracing/requests/fetch-sampled-no-active-span/test.ts',
28+
'suites/tracing/requests/fetch-unsampled/test.ts',
29+
'suites/tracing/requests/traceparent/test.ts',
30+
'suites/tracing/sample-rand-propagation/test.ts',
31+
'suites/tracing/sample-rate-propagation/**',
1832
];
1933

2034
// In the ESM tests Deno cannot find `PrismaClient`, a CommonJS export of `@prisma/client`.
@@ -51,7 +65,7 @@ const FLAKY = ['suites/tracing/tracePropagationTargets/**'];
5165
export const NODE_SUITES_EXCLUDE = [
5266
'**/node_modules/**',
5367
...NODE_ONLY,
54-
...FETCH_FALLBACK_DIFFERENCES,
68+
...NO_FETCH_INSTRUMENTATION,
5569
...PRISMA_ESM_INTEROP,
5670
...NOT_TRIAGED,
5771
...FLAKY,

‎packages/node/src/integrations/node-fetch/index.ts‎

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,19 @@
11
import type { IntegrationFn } from '@sentry/core';
2-
import { createFetchIntegration, debug, defineIntegration, getClient, hasSpansEnabled } from '@sentry/core';
3-
import { DEBUG_BUILD } from '../../debug-build';
2+
import { defineIntegration, getClient, hasSpansEnabled } from '@sentry/core';
43
import type { NodeClientOptions } from '../../types';
54
import type { NodeFetchOptions } from './types';
65
import { instrumentUndici } from './undici-instrumentation';
76

8-
// Created once, because it holds the in-flight spans that every instance of the integration shares.
9-
const globalFetchIntegration = createFetchIntegration({
10-
name: 'NodeFetch',
11-
spanOrigin: 'auto.http.node_fetch',
12-
});
13-
14-
/**
15-
* Bun's and Deno's `fetch` do not use undici, so the undici diagnostics channels never fire there.
16-
* On these runtimes the integration patches the global `fetch` instead.
17-
*/
18-
function isFetchWithoutUndici(): boolean {
19-
const globalAny = globalThis as { Bun?: unknown; Deno?: unknown };
20-
return typeof globalAny.Bun !== 'undefined' || typeof globalAny.Deno !== 'undefined';
21-
}
22-
237
const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {
24-
const { ignoreOutgoingRequests, spans } = options;
25-
const fetchFallback = globalFetchIntegration({
26-
breadcrumbs: options.breadcrumbs,
27-
tracePropagation: options.tracePropagation,
28-
shouldCreateSpanForRequest: url => spans !== false && !ignoreOutgoingRequests?.(url),
29-
});
30-
318
return {
329
name: 'NodeFetch' as const,
3310
setupOnce() {
34-
if (isFetchWithoutUndici()) {
35-
if (DEBUG_BUILD && (options.requestHook || options.responseHook || options.headersToSpanAttributes)) {
36-
debug.warn(
37-
'[NodeFetch] `requestHook`, `responseHook` and `headersToSpanAttributes` are not supported on Bun and Deno.',
38-
);
39-
}
40-
fetchFallback.setupOnce?.();
41-
return;
42-
}
43-
4411
const clientOptions = getClient()?.getOptions();
4512
instrumentUndici({
4613
...options,
4714
spans: _shouldInstrumentSpans(options, clientOptions),
4815
});
4916
},
50-
setup(client) {
51-
if (isFetchWithoutUndici()) {
52-
fetchFallback.setup?.(client);
53-
}
54-
},
5517
};
5618
}) satisfies IntegrationFn;
5719

‎packages/node/test/integrations/nodeFetch.test.ts‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)