99 getSanitizedUrlString ,
1010 objectify ,
1111 parseFetchArgs ,
12+ parseUrl ,
1213 stringMatchesSomePattern ,
1314} from '@sentry/utils' ;
1415import type { LoadEvent } from '@sveltejs/kit' ;
@@ -107,12 +108,12 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
107108
108109 const browserTracingIntegration =
109110 client . getIntegrationById && ( client . getIntegrationById ( 'BrowserTracing' ) as BrowserTracing | undefined ) ;
110- const breadcrumbsIntegration = client . getIntegrationById ( 'BreadCrumbs ' ) as Breadcrumbs | undefined ;
111+ const breadcrumbsIntegration = client . getIntegrationById ( 'Breadcrumbs ' ) as Breadcrumbs | undefined ;
111112
112113 const browserTracingOptions = browserTracingIntegration && browserTracingIntegration . options ;
113114
114115 const shouldTraceFetch = browserTracingOptions && browserTracingOptions . traceFetch ;
115- const shouldAddFetchBreadcrumbs = breadcrumbsIntegration && breadcrumbsIntegration . options . fetch ;
116+ const shouldAddFetchBreadcrumb = breadcrumbsIntegration && breadcrumbsIntegration . options . fetch ;
116117
117118 /* Identical check as in BrowserTracing, just that we also need to verify that BrowserTracing is actually installed */
118119 const shouldCreateSpan =
@@ -132,7 +133,8 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
132133 apply : ( wrappingTarget , thisArg , args : Parameters < LoadEvent [ 'fetch' ] > ) => {
133134 const [ input , init ] = args ;
134135 const { url : rawUrl , method } = parseFetchArgs ( args ) ;
135- const urlObject = new URL ( rawUrl ) ;
136+ const urlObject = parseUrl ( rawUrl ) ;
137+
136138 const requestData : SanitizedRequestData = {
137139 url : getSanitizedUrlString ( urlObject ) ,
138140 method,
@@ -156,6 +158,7 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
156158 // only attach headers if we should create a span
157159 if ( attachHeaders && createSpan ) {
158160 const dsc = activeTransaction . getDynamicSamplingContext ( ) ;
161+
159162 const headers = addTracingHeadersToFetchRequest (
160163 input as string | Request ,
161164 dsc ,
@@ -173,6 +176,8 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
173176
174177 let fetchPromise : Promise < Response > ;
175178
179+ const patchedFetchArgs = [ input , patchedInit ] ;
180+
176181 if ( createSpan ) {
177182 fetchPromise = trace (
178183 {
@@ -181,18 +186,18 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
181186 data : requestData ,
182187 } ,
183188 span => {
184- const promise : Promise < Response > = wrappingTarget . apply ( thisArg , [ input , patchedInit ] ) ;
189+ const promise : Promise < Response > = wrappingTarget . apply ( thisArg , patchedFetchArgs ) ;
185190 if ( span ) {
186191 promise . then ( res => span . setHttpStatus ( res . status ) ) . catch ( _ => span . setStatus ( 'internal_error' ) ) ;
187192 }
188193 return promise ;
189194 } ,
190195 ) ;
191196 } else {
192- fetchPromise = wrappingTarget . apply ( thisArg , [ input , patchedInit ] ) ;
197+ fetchPromise = wrappingTarget . apply ( thisArg , patchedFetchArgs ) ;
193198 }
194199
195- if ( shouldAddFetchBreadcrumbs ) {
200+ if ( shouldAddFetchBreadcrumb ) {
196201 addFetchBreadcrumb ( fetchPromise , requestData , args ) ;
197202 }
198203
0 commit comments