9
9
getSanitizedUrlString ,
10
10
objectify ,
11
11
parseFetchArgs ,
12
+ parseUrl ,
12
13
stringMatchesSomePattern ,
13
14
} from '@sentry/utils' ;
14
15
import type { LoadEvent } from '@sveltejs/kit' ;
@@ -107,12 +108,12 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
107
108
108
109
const browserTracingIntegration =
109
110
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 ;
111
112
112
113
const browserTracingOptions = browserTracingIntegration && browserTracingIntegration . options ;
113
114
114
115
const shouldTraceFetch = browserTracingOptions && browserTracingOptions . traceFetch ;
115
- const shouldAddFetchBreadcrumbs = breadcrumbsIntegration && breadcrumbsIntegration . options . fetch ;
116
+ const shouldAddFetchBreadcrumb = breadcrumbsIntegration && breadcrumbsIntegration . options . fetch ;
116
117
117
118
/* Identical check as in BrowserTracing, just that we also need to verify that BrowserTracing is actually installed */
118
119
const shouldCreateSpan =
@@ -132,7 +133,8 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
132
133
apply : ( wrappingTarget , thisArg , args : Parameters < LoadEvent [ 'fetch' ] > ) => {
133
134
const [ input , init ] = args ;
134
135
const { url : rawUrl , method } = parseFetchArgs ( args ) ;
135
- const urlObject = new URL ( rawUrl ) ;
136
+ const urlObject = parseUrl ( rawUrl ) ;
137
+
136
138
const requestData : SanitizedRequestData = {
137
139
url : getSanitizedUrlString ( urlObject ) ,
138
140
method,
@@ -156,6 +158,7 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
156
158
// only attach headers if we should create a span
157
159
if ( attachHeaders && createSpan ) {
158
160
const dsc = activeTransaction . getDynamicSamplingContext ( ) ;
161
+
159
162
const headers = addTracingHeadersToFetchRequest (
160
163
input as string | Request ,
161
164
dsc ,
@@ -173,6 +176,8 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
173
176
174
177
let fetchPromise : Promise < Response > ;
175
178
179
+ const patchedFetchArgs = [ input , patchedInit ] ;
180
+
176
181
if ( createSpan ) {
177
182
fetchPromise = trace (
178
183
{
@@ -181,18 +186,18 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
181
186
data : requestData ,
182
187
} ,
183
188
span => {
184
- const promise : Promise < Response > = wrappingTarget . apply ( thisArg , [ input , patchedInit ] ) ;
189
+ const promise : Promise < Response > = wrappingTarget . apply ( thisArg , patchedFetchArgs ) ;
185
190
if ( span ) {
186
191
promise . then ( res => span . setHttpStatus ( res . status ) ) . catch ( _ => span . setStatus ( 'internal_error' ) ) ;
187
192
}
188
193
return promise ;
189
194
} ,
190
195
) ;
191
196
} else {
192
- fetchPromise = wrappingTarget . apply ( thisArg , [ input , patchedInit ] ) ;
197
+ fetchPromise = wrappingTarget . apply ( thisArg , patchedFetchArgs ) ;
193
198
}
194
199
195
- if ( shouldAddFetchBreadcrumbs ) {
200
+ if ( shouldAddFetchBreadcrumb ) {
196
201
addFetchBreadcrumb ( fetchPromise , requestData , args ) ;
197
202
}
198
203
0 commit comments