Skip to content

Commit 6eb29fe

Browse files
committed
re-activate request object test
1 parent 5f05517 commit 6eb29fe

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

packages/sveltekit/src/client/load.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
154154
const activeSpan = getCurrentHub().getScope().getSpan();
155155
const activeTransaction = activeSpan && activeSpan.transaction;
156156

157-
const attachHeaders = activeTransaction && shouldAttachHeaders(rawUrl);
158157
const createSpan = activeTransaction && shouldCreateSpan(rawUrl);
158+
const attachHeaders = createSpan && activeTransaction && shouldAttachHeaders(rawUrl);
159159

160160
// only attach headers if we should create a span
161-
if (attachHeaders && createSpan) {
161+
if (attachHeaders) {
162162
const dsc = activeTransaction.getDynamicSamplingContext();
163163

164164
const headers = addTracingHeadersToFetchRequest(
@@ -173,9 +173,9 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
173173
| Request['headers'];
174174
},
175175
) as HeadersInit;
176+
176177
patchedInit.headers = headers;
177178
}
178-
179179
let fetchPromise: Promise<Response>;
180180

181181
const patchedFetchArgs = [input, patchedInit];

packages/sveltekit/test/client/load.test.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const mockTrace = vi.fn();
3030

3131
const mockedBrowserTracing = {
3232
options: {
33-
tracePropagationTargets: ['example.com'],
33+
tracePropagationTargets: ['example.com', /^\\/],
3434
traceFetch: true,
3535
shouldCreateSpanForRequest: undefined as undefined | (() => boolean),
3636
},
@@ -227,26 +227,23 @@ describe('wrapLoadWithSentry', () => {
227227
},
228228
},
229229
],
230-
// TODO: This case currently fails because we don't handle the Request API correctly.
231-
// We need to fix this in our core fetch instrumentation and
232-
// and adjust the test here as well, since both instrumentations
233-
// rely on the same `getFetchUrl` and `getFetchMethod` utility functions.
234-
// [
235-
// 'fetch call with a Request object ',
236-
// [{ url: 'api/users?id=123', headers: { 'x-my-header': 'value' } } as unknown as Request],
237-
// {
238-
// op: 'http.client',
239-
// name: 'GET [object Object]',
240-
// data: {
241-
// method: 'GET',
242-
// url: '[object Object]',
243-
// },
244-
// },
245-
// ],
230+
[
231+
'fetch call with a Request object ',
232+
[{ url: '/api/users?id=123', headers: { 'x-my-header': 'value' } } as unknown as Request],
233+
{
234+
op: 'http.client',
235+
name: 'GET /api/users',
236+
data: {
237+
method: 'GET',
238+
url: '/api/users',
239+
'http.query': 'id=123',
240+
},
241+
},
242+
],
246243
])('instruments fetch (%s)', (_, originalFetchArgs, spanCtx) => {
247244
beforeEach(() => {
248245
mockedBrowserTracing.options = {
249-
tracePropagationTargets: ['example.com'],
246+
tracePropagationTargets: ['example.com', /^\//],
250247
traceFetch: true,
251248
shouldCreateSpanForRequest: undefined,
252249
};
@@ -259,7 +256,7 @@ describe('wrapLoadWithSentry', () => {
259256
};
260257
};
261258

262-
it('creates a fetch span and attaches tracing headers if event.fetch was called', async () => {
259+
it('creates a fetch span and attaches tracing headers by default when event.fetch was called', async () => {
263260
const wrappedLoad = wrapLoadWithSentry(load);
264261
await wrappedLoad(MOCK_LOAD_ARGS);
265262

0 commit comments

Comments
 (0)