Skip to content

Commit 73a2388

Browse files
authored
ref(sveltekit): Adjust mechanism of error events (#17646)
mechanism type now follows the trace origin naming scheme closes #17639
1 parent b24a7e6 commit 73a2388

File tree

13 files changed

+24
-32
lines changed

13 files changed

+24
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- ref(remix): Adjust event mechanism of `captureRemixServerException` ([#17629](https://github.com/getsentry/sentry-javascript/pull/17629))
3232
- ref(replay-internal): Add mechanism to error caught by `replayIntegration` in debug mode ([#17606](https://github.com/getsentry/sentry-javascript/pull/17606))
3333
- ref(solid): Add `mechanism` to error captured by `withSentryErrorBoundary` ([#17607](https://github.com/getsentry/sentry-javascript/pull/17607))
34+
- ref(sveltekit): Adjust `mechanism` of error events ([#17646](https://github.com/getsentry/sentry-javascript/pull/17646))
3435
- ref(vue): Adjust mechanism in Vue error handler ([#17647](https://github.com/getsentry/sentry-javascript/pull/17647))
3536

3637
<br/>

dev-packages/e2e-tests/test-applications/sveltekit-2/tests/errors.server.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ test.describe('server-side errors', () => {
7373
value: "'HttpError' captured as exception with keys: body, status",
7474
mechanism: {
7575
handled: false,
76-
data: {
77-
function: 'serverRoute',
78-
},
76+
type: 'auto.function.sveltekit.server_route',
7977
},
8078
stacktrace: { frames: expect.any(Array) },
8179
},

packages/sveltekit/src/client/handleError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function handleErrorWithSentry(handleError?: HandleClientError): HandleCl
3838

3939
captureException(input.error, {
4040
mechanism: {
41-
type: 'sveltekit',
41+
type: 'auto.function.sveltekit.handle_error',
4242
handled: !!handleError,
4343
},
4444
});

packages/sveltekit/src/client/load.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ function sendErrorToSentry(e: unknown): unknown {
2929

3030
captureException(objectifiedErr, {
3131
mechanism: {
32-
type: 'sveltekit',
32+
type: 'auto.function.sveltekit.load',
3333
handled: false,
34-
data: {
35-
function: 'load',
36-
},
3734
},
3835
});
3936

packages/sveltekit/src/server-common/handleError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function handleErrorWithSentry(handleError?: HandleServerError): HandleSe
3636

3737
captureException(input.error, {
3838
mechanism: {
39-
type: 'sveltekit',
39+
type: 'auto.function.sveltekit.handle_error',
4040
handled: !!handleError,
4141
},
4242
});

packages/sveltekit/src/server-common/serverRoute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function wrapServerRouteWithSentry<T extends RequestEvent>(
6262
() => wrappingTarget.apply(thisArg, args),
6363
);
6464
} catch (e) {
65-
sendErrorToSentry(e, 'serverRoute');
65+
sendErrorToSentry(e, 'server_route');
6666
throw e;
6767
} finally {
6868
await flushIfServerless();

packages/sveltekit/src/server-common/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function getTracePropagationData(event: RequestEvent): { sentryTrace: str
2323
*
2424
* @returns an objectified version of @param e
2525
*/
26-
export function sendErrorToSentry(e: unknown, handlerFn: 'handle' | 'load' | 'serverRoute'): object {
26+
export function sendErrorToSentry(e: unknown, handlerFn: 'handle' | 'load' | 'server_route'): object {
2727
// In case we have a primitive, wrap it in the equivalent wrapper class (string -> String, etc.) so that we can
2828
// store a seen flag on it.
2929
const objectifiedErr = objectify(e);
@@ -42,11 +42,8 @@ export function sendErrorToSentry(e: unknown, handlerFn: 'handle' | 'load' | 'se
4242

4343
captureException(objectifiedErr, {
4444
mechanism: {
45-
type: 'sveltekit',
45+
type: `auto.function.sveltekit.${handlerFn}`,
4646
handled: false,
47-
data: {
48-
function: handlerFn,
49-
},
5047
},
5148
});
5249

packages/sveltekit/test/client/handleError.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ const navigationEvent: NavigationEvent = {
2121
url: new URL('http://example.org/users/123'),
2222
};
2323

24-
const captureExceptionEventHint = {
25-
mechanism: { handled: false, type: 'sveltekit' },
26-
};
27-
2824
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(_ => {});
2925

3026
describe('handleError (client)', () => {
@@ -42,7 +38,9 @@ describe('handleError (client)', () => {
4238

4339
expect(returnVal).not.toBeDefined();
4440
expect(mockCaptureException).toHaveBeenCalledTimes(1);
45-
expect(mockCaptureException).toHaveBeenCalledWith(mockError, captureExceptionEventHint);
41+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, {
42+
mechanism: { handled: false, type: 'auto.function.sveltekit.handle_error' },
43+
});
4644
// The default handler logs the error to the console
4745
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
4846
});
@@ -56,7 +54,7 @@ describe('handleError (client)', () => {
5654
expect(returnVal.message).toEqual('Whoops!');
5755
expect(mockCaptureException).toHaveBeenCalledTimes(1);
5856
expect(mockCaptureException).toHaveBeenCalledWith(mockError, {
59-
mechanism: { handled: true, type: 'sveltekit' },
57+
mechanism: { handled: true, type: 'auto.function.sveltekit.handle_error' },
6058
});
6159

6260
// Check that the default handler wasn't invoked

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('wrapLoadWithSentry', () => {
154154

155155
expect(mockCaptureException).toHaveBeenCalledTimes(1);
156156
expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error), {
157-
mechanism: { handled: false, type: 'sveltekit', data: { function: 'load' } },
157+
mechanism: { handled: false, type: 'auto.function.sveltekit.load' },
158158
});
159159
});
160160

packages/sveltekit/test/server-common/handle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ describe('sentryHandle', () => {
317317
} catch (e) {
318318
expect(mockCaptureException).toBeCalledTimes(1);
319319
expect(mockCaptureException).toBeCalledWith(expect.any(Error), {
320-
mechanism: { handled: false, type: 'sveltekit', data: { function: 'handle' } },
320+
mechanism: { handled: false, type: 'auto.function.sveltekit.handle' },
321321
});
322322
}
323323
});

0 commit comments

Comments
 (0)