@@ -108,7 +108,8 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
108108
109109 const browserTracingIntegration =
110110 client . getIntegrationById && ( client . getIntegrationById ( 'BrowserTracing' ) as BrowserTracing | undefined ) ;
111- const breadcrumbsIntegration = client . getIntegrationById ( 'Breadcrumbs' ) as Breadcrumbs | undefined ;
111+ const breadcrumbsIntegration =
112+ client . getIntegrationById && ( client . getIntegrationById ( 'Breadcrumbs' ) as Breadcrumbs | undefined ) ;
112113
113114 const browserTracingOptions = browserTracingIntegration && browserTracingIntegration . options ;
114115
@@ -133,22 +134,23 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
133134 apply : ( wrappingTarget , thisArg , args : Parameters < LoadEvent [ 'fetch' ] > ) => {
134135 const [ input , init ] = args ;
135136 const { url : rawUrl , method } = parseFetchArgs ( args ) ;
136- const urlObject = parseUrl ( rawUrl ) ;
137-
138- const requestData : SanitizedRequestData = {
139- url : getSanitizedUrlString ( urlObject ) ,
140- method,
141- 'http.query' : urlObject . search ,
142- 'http.fragment' : urlObject . hash ,
143- } ;
144137
145138 // TODO: extract this to a util function (and use it in breadcrumbs integration as well)
146139 if ( rawUrl . match ( / s e n t r y _ k e y / ) ) {
147140 // We don't create spans or breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
148141 return wrappingTarget . apply ( thisArg , args ) ;
149142 }
150143
151- const patchedInit : RequestInit = { ...init } || { } ;
144+ const urlObject = parseUrl ( rawUrl ) ;
145+
146+ const requestData : SanitizedRequestData = {
147+ url : getSanitizedUrlString ( urlObject ) ,
148+ method,
149+ ...( urlObject . search && { 'http.query' : urlObject . search . substring ( 1 ) } ) ,
150+ ...( urlObject . hash && { 'http.hash' : urlObject . hash . substring ( 1 ) } ) ,
151+ } ;
152+
153+ const patchedInit : RequestInit = { ...init } ;
152154 const activeSpan = getCurrentHub ( ) . getScope ( ) . getSpan ( ) ;
153155 const activeTransaction = activeSpan && activeSpan . transaction ;
154156
0 commit comments