|
1 | 1 | import type { BaseClient } from '@sentry/core';
|
2 | 2 | import { getCurrentHub, trace } from '@sentry/core';
|
3 | 3 | import type { Breadcrumbs, BrowserTracing } from '@sentry/svelte';
|
4 |
| -import { captureException } from '@sentry/svelte'; |
| 4 | +import { captureException, WINDOW } from '@sentry/svelte'; |
5 | 5 | import type { ClientOptions, SanitizedRequestData } from '@sentry/types';
|
6 | 6 | import {
|
7 | 7 | addExceptionMechanism,
|
@@ -133,12 +133,14 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
|
133 | 133 | apply: (wrappingTarget, thisArg, args: Parameters<LoadEvent['fetch']>) => {
|
134 | 134 | const [input, init] = args;
|
135 | 135 | const rawUrl = getFetchUrl(args);
|
136 |
| - const urlObject = new URL(rawUrl); |
| 136 | + |
| 137 | + const urlObject = new URL(rawUrl, WINDOW.document.baseURI); |
| 138 | + |
137 | 139 | const requestData: SanitizedRequestData = {
|
138 | 140 | url: getSanitizedUrlString(urlObject),
|
139 | 141 | 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) }), |
142 | 144 | };
|
143 | 145 |
|
144 | 146 | // TODO: extract this to a util function (and use it in breadcrumbs integration as well)
|
@@ -180,14 +182,13 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
|
180 | 182 | name: `${requestData.method} ${requestData.url}`, // this will become the description of the span
|
181 | 183 | op: 'http.client',
|
182 | 184 | data: requestData,
|
183 |
| - parentSpanId: activeSpan && activeSpan.spanId, |
184 | 185 | },
|
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]); |
187 | 188 | if (span) {
|
188 |
| - span.setHttpStatus(fetchResult.status); |
| 189 | + promise.then(res => span.setHttpStatus(res.status)).catch(_ => span.setStatus('internal_error')); |
189 | 190 | }
|
190 |
| - return fetchResult; |
| 191 | + return promise; |
191 | 192 | },
|
192 | 193 | );
|
193 | 194 | } else {
|
|
0 commit comments