@@ -3,6 +3,7 @@ import { getClient } from '../currentScopes';
33import type { HandlerDataFetch } from '../types/instrument' ;
44import type { WebFetchHeaders } from '../types/webfetchapi' ;
55import { isError , isObjectLike , isRequest } from '../utils/is' ;
6+ import { isBrowser } from '../utils/isBrowser' ;
67import { addNonEnumerableProperty , fill } from '../utils/object' ;
78import { supportsNativeFetch } from '../utils/supports' ;
89import { timestampInSeconds } from '../utils/time' ;
@@ -20,13 +21,10 @@ type FetchResource = string | { toString(): string } | { url: string };
2021 * Use at your own risk, this might break without changelog notice, only used internally.
2122 * @hidden
2223 */
23- export function addFetchInstrumentationHandler (
24- handler : ( data : HandlerDataFetch ) => void ,
25- skipNativeFetchCheck ?: boolean ,
26- ) : ( ) => void {
24+ export function addFetchInstrumentationHandler ( handler : ( data : HandlerDataFetch ) => void ) : ( ) => void {
2725 const type = 'fetch' ;
2826 const removeHandler = addHandler ( type , handler ) ;
29- maybeInstrument ( type , ( ) => instrumentFetch ( undefined , skipNativeFetchCheck ) ) ;
27+ maybeInstrument ( type , ( ) => instrumentFetch ( ) ) ;
3028 return removeHandler ;
3129}
3230
@@ -46,8 +44,12 @@ export function addFetchEndInstrumentationHandler(handler: (data: HandlerDataFet
4644 return removeHandler ;
4745}
4846
49- function instrumentFetch ( onFetchResolved ?: ( response : Response ) => void , skipNativeFetchCheck : boolean = false ) : void {
50- if ( skipNativeFetchCheck && ! supportsNativeFetch ( ) ) {
47+ function instrumentFetch ( onFetchResolved ?: ( response : Response ) => void ) : void {
48+ // The native-fetch check is only meaningful in the browser: it probes for `[native code]` and
49+ // falls back to an iframe DOM check to detect a polyfilled/wrapped `fetch` (which we don't want to
50+ // double-instrument alongside XHR). Outside the browser there is no DOM, and `fetch` may be
51+ // legitimately wrapped by the host (e.g. Next.js on Bun), so we always patch the global there.
52+ if ( isBrowser ( ) && ! supportsNativeFetch ( ) ) {
5153 return ;
5254 }
5355
0 commit comments