Skip to content

Commit 6820e24

Browse files
committed
set span status
1 parent 3c41470 commit 6820e24

File tree

1 file changed

+10
-9
lines changed
  • packages/sveltekit/src/client

1 file changed

+10
-9
lines changed

packages/sveltekit/src/client/load.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BaseClient } from '@sentry/core';
22
import { getCurrentHub, trace } from '@sentry/core';
33
import type { Breadcrumbs, BrowserTracing } from '@sentry/svelte';
4-
import { captureException } from '@sentry/svelte';
4+
import { captureException, WINDOW } from '@sentry/svelte';
55
import type { ClientOptions, SanitizedRequestData } from '@sentry/types';
66
import {
77
addExceptionMechanism,
@@ -133,12 +133,14 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
133133
apply: (wrappingTarget, thisArg, args: Parameters<LoadEvent['fetch']>) => {
134134
const [input, init] = args;
135135
const rawUrl = getFetchUrl(args);
136-
const urlObject = new URL(rawUrl);
136+
137+
const urlObject = new URL(rawUrl, WINDOW.document.baseURI);
138+
137139
const requestData: SanitizedRequestData = {
138140
url: getSanitizedUrlString(urlObject),
139141
method: getFetchMethod(args),
140-
'http.query': urlObject.search,
141-
'http.fragment': urlObject.hash,
142+
...(urlObject.search && { 'http.query': urlObject.search.substring(1) }),
143+
...(urlObject.hash && { 'http.hash': urlObject.hash.substring(1) }),
142144
};
143145

144146
// TODO: extract this to a util function (and use it in breadcrumbs integration as well)
@@ -180,14 +182,13 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
180182
name: `${requestData.method} ${requestData.url}`, // this will become the description of the span
181183
op: 'http.client',
182184
data: requestData,
183-
parentSpanId: activeSpan && activeSpan.spanId,
184185
},
185-
async span => {
186-
const fetchResult: Response = await wrappingTarget.apply(thisArg, [input, patchedInit]);
186+
span => {
187+
const promise: Promise<Response> = wrappingTarget.apply(thisArg, [input, patchedInit]);
187188
if (span) {
188-
span.setHttpStatus(fetchResult.status);
189+
promise.then(res => span.setHttpStatus(res.status)).catch(_ => span.setStatus('internal_error'));
189190
}
190-
return fetchResult;
191+
return promise;
191192
},
192193
);
193194
} else {

0 commit comments

Comments
 (0)