diff --git a/CHANGELOG.md b/CHANGELOG.md
index b470228dcc7b..5d1c10346e25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@
- ref(remix): Adjust event mechanism of `captureRemixServerException` ([#17629](https://github.com/getsentry/sentry-javascript/pull/17629))
- ref(replay-internal): Add mechanism to error caught by `replayIntegration` in debug mode ([#17606](https://github.com/getsentry/sentry-javascript/pull/17606))
- ref(solid): Add `mechanism` to error captured by `withSentryErrorBoundary` ([#17607](https://github.com/getsentry/sentry-javascript/pull/17607))
+ - ref(sveltekit): Adjust `mechanism` of error events ([#17646](https://github.com/getsentry/sentry-javascript/pull/17646))
- ref(vue): Adjust mechanism in Vue error handler ([#17647](https://github.com/getsentry/sentry-javascript/pull/17647))
diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2/tests/errors.server.test.ts b/dev-packages/e2e-tests/test-applications/sveltekit-2/tests/errors.server.test.ts
index fd2e58e9c2a3..0d78c9c7d649 100644
--- a/dev-packages/e2e-tests/test-applications/sveltekit-2/tests/errors.server.test.ts
+++ b/dev-packages/e2e-tests/test-applications/sveltekit-2/tests/errors.server.test.ts
@@ -73,9 +73,7 @@ test.describe('server-side errors', () => {
value: "'HttpError' captured as exception with keys: body, status",
mechanism: {
handled: false,
- data: {
- function: 'serverRoute',
- },
+ type: 'auto.function.sveltekit.server_route',
},
stacktrace: { frames: expect.any(Array) },
},
diff --git a/packages/sveltekit/src/client/handleError.ts b/packages/sveltekit/src/client/handleError.ts
index 14a0a5b4b9cd..d6c50b3519a9 100644
--- a/packages/sveltekit/src/client/handleError.ts
+++ b/packages/sveltekit/src/client/handleError.ts
@@ -38,7 +38,7 @@ export function handleErrorWithSentry(handleError?: HandleClientError): HandleCl
captureException(input.error, {
mechanism: {
- type: 'sveltekit',
+ type: 'auto.function.sveltekit.handle_error',
handled: !!handleError,
},
});
diff --git a/packages/sveltekit/src/client/load.ts b/packages/sveltekit/src/client/load.ts
index bf8cf7cb058e..216d2c373547 100644
--- a/packages/sveltekit/src/client/load.ts
+++ b/packages/sveltekit/src/client/load.ts
@@ -29,11 +29,8 @@ function sendErrorToSentry(e: unknown): unknown {
captureException(objectifiedErr, {
mechanism: {
- type: 'sveltekit',
+ type: 'auto.function.sveltekit.load',
handled: false,
- data: {
- function: 'load',
- },
},
});
diff --git a/packages/sveltekit/src/server-common/handleError.ts b/packages/sveltekit/src/server-common/handleError.ts
index 0ca6597ea864..4a7bce331622 100644
--- a/packages/sveltekit/src/server-common/handleError.ts
+++ b/packages/sveltekit/src/server-common/handleError.ts
@@ -36,7 +36,7 @@ export function handleErrorWithSentry(handleError?: HandleServerError): HandleSe
captureException(input.error, {
mechanism: {
- type: 'sveltekit',
+ type: 'auto.function.sveltekit.handle_error',
handled: !!handleError,
},
});
diff --git a/packages/sveltekit/src/server-common/serverRoute.ts b/packages/sveltekit/src/server-common/serverRoute.ts
index d09233cb3633..3b98ce270f2d 100644
--- a/packages/sveltekit/src/server-common/serverRoute.ts
+++ b/packages/sveltekit/src/server-common/serverRoute.ts
@@ -62,7 +62,7 @@ export function wrapServerRouteWithSentry(
() => wrappingTarget.apply(thisArg, args),
);
} catch (e) {
- sendErrorToSentry(e, 'serverRoute');
+ sendErrorToSentry(e, 'server_route');
throw e;
} finally {
await flushIfServerless();
diff --git a/packages/sveltekit/src/server-common/utils.ts b/packages/sveltekit/src/server-common/utils.ts
index b861bf758697..6fc67dc60612 100644
--- a/packages/sveltekit/src/server-common/utils.ts
+++ b/packages/sveltekit/src/server-common/utils.ts
@@ -23,7 +23,7 @@ export function getTracePropagationData(event: RequestEvent): { sentryTrace: str
*
* @returns an objectified version of @param e
*/
-export function sendErrorToSentry(e: unknown, handlerFn: 'handle' | 'load' | 'serverRoute'): object {
+export function sendErrorToSentry(e: unknown, handlerFn: 'handle' | 'load' | 'server_route'): object {
// In case we have a primitive, wrap it in the equivalent wrapper class (string -> String, etc.) so that we can
// store a seen flag on it.
const objectifiedErr = objectify(e);
@@ -42,11 +42,8 @@ export function sendErrorToSentry(e: unknown, handlerFn: 'handle' | 'load' | 'se
captureException(objectifiedErr, {
mechanism: {
- type: 'sveltekit',
+ type: `auto.function.sveltekit.${handlerFn}`,
handled: false,
- data: {
- function: handlerFn,
- },
},
});
diff --git a/packages/sveltekit/test/client/handleError.test.ts b/packages/sveltekit/test/client/handleError.test.ts
index 810acd865aa2..3511ff62f83b 100644
--- a/packages/sveltekit/test/client/handleError.test.ts
+++ b/packages/sveltekit/test/client/handleError.test.ts
@@ -21,10 +21,6 @@ const navigationEvent: NavigationEvent = {
url: new URL('http://example.org/users/123'),
};
-const captureExceptionEventHint = {
- mechanism: { handled: false, type: 'sveltekit' },
-};
-
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(_ => {});
describe('handleError (client)', () => {
@@ -42,7 +38,9 @@ describe('handleError (client)', () => {
expect(returnVal).not.toBeDefined();
expect(mockCaptureException).toHaveBeenCalledTimes(1);
- expect(mockCaptureException).toHaveBeenCalledWith(mockError, captureExceptionEventHint);
+ expect(mockCaptureException).toHaveBeenCalledWith(mockError, {
+ mechanism: { handled: false, type: 'auto.function.sveltekit.handle_error' },
+ });
// The default handler logs the error to the console
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
});
@@ -56,7 +54,7 @@ describe('handleError (client)', () => {
expect(returnVal.message).toEqual('Whoops!');
expect(mockCaptureException).toHaveBeenCalledTimes(1);
expect(mockCaptureException).toHaveBeenCalledWith(mockError, {
- mechanism: { handled: true, type: 'sveltekit' },
+ mechanism: { handled: true, type: 'auto.function.sveltekit.handle_error' },
});
// Check that the default handler wasn't invoked
diff --git a/packages/sveltekit/test/client/load.test.ts b/packages/sveltekit/test/client/load.test.ts
index 465167265d49..b7d0b58ffe93 100644
--- a/packages/sveltekit/test/client/load.test.ts
+++ b/packages/sveltekit/test/client/load.test.ts
@@ -154,7 +154,7 @@ describe('wrapLoadWithSentry', () => {
expect(mockCaptureException).toHaveBeenCalledTimes(1);
expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error), {
- mechanism: { handled: false, type: 'sveltekit', data: { function: 'load' } },
+ mechanism: { handled: false, type: 'auto.function.sveltekit.load' },
});
});
diff --git a/packages/sveltekit/test/server-common/handle.test.ts b/packages/sveltekit/test/server-common/handle.test.ts
index db1e1fe4811f..fdb4a1103d90 100644
--- a/packages/sveltekit/test/server-common/handle.test.ts
+++ b/packages/sveltekit/test/server-common/handle.test.ts
@@ -317,7 +317,7 @@ describe('sentryHandle', () => {
} catch (e) {
expect(mockCaptureException).toBeCalledTimes(1);
expect(mockCaptureException).toBeCalledWith(expect.any(Error), {
- mechanism: { handled: false, type: 'sveltekit', data: { function: 'handle' } },
+ mechanism: { handled: false, type: 'auto.function.sveltekit.handle' },
});
}
});
diff --git a/packages/sveltekit/test/server-common/handleError.test.ts b/packages/sveltekit/test/server-common/handleError.test.ts
index 6b4b3af992d1..30fa7e78c137 100644
--- a/packages/sveltekit/test/server-common/handleError.test.ts
+++ b/packages/sveltekit/test/server-common/handleError.test.ts
@@ -5,10 +5,6 @@ import { handleErrorWithSentry } from '../../src/server-common/handleError';
const mockCaptureException = vi.spyOn(SentryCore, 'captureException').mockImplementation(() => 'xx');
-const captureExceptionEventHint = {
- mechanism: { handled: false, type: 'sveltekit' },
-};
-
function handleError(_input: { error: unknown; event: RequestEvent }): ReturnType {
return {
message: 'Whoops!',
@@ -73,7 +69,9 @@ describe('handleError (server)', () => {
expect(returnVal).not.toBeDefined();
expect(mockCaptureException).toHaveBeenCalledTimes(1);
- expect(mockCaptureException).toHaveBeenCalledWith(mockError, captureExceptionEventHint);
+ expect(mockCaptureException).toHaveBeenCalledWith(mockError, {
+ mechanism: { handled: false, type: 'auto.function.sveltekit.handle_error' },
+ });
// The default handler logs the error to the console
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
});
@@ -91,7 +89,7 @@ describe('handleError (server)', () => {
expect(returnVal.message).toEqual('Whoops!');
expect(mockCaptureException).toHaveBeenCalledTimes(1);
expect(mockCaptureException).toHaveBeenCalledWith(mockError, {
- mechanism: { handled: true, type: 'sveltekit' },
+ mechanism: { handled: true, type: 'auto.function.sveltekit.handle_error' },
});
// Check that the default handler wasn't invoked
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
diff --git a/packages/sveltekit/test/server-common/load.test.ts b/packages/sveltekit/test/server-common/load.test.ts
index c3200d9a7927..4ec2cf6967c2 100644
--- a/packages/sveltekit/test/server-common/load.test.ts
+++ b/packages/sveltekit/test/server-common/load.test.ts
@@ -150,7 +150,7 @@ describe.each([
expect(mockCaptureException).toHaveBeenCalledTimes(1);
expect(mockCaptureException).toHaveBeenCalledWith(expect.any(Error), {
- mechanism: { handled: false, type: 'sveltekit', data: { function: 'load' } },
+ mechanism: { handled: false, type: 'auto.function.sveltekit.load' },
});
});
});
diff --git a/packages/sveltekit/test/server-common/serverRoute.test.ts b/packages/sveltekit/test/server-common/serverRoute.test.ts
index 046c3673a8c7..2ec3ef2cf2d2 100644
--- a/packages/sveltekit/test/server-common/serverRoute.test.ts
+++ b/packages/sveltekit/test/server-common/serverRoute.test.ts
@@ -85,7 +85,7 @@ describe('wrapServerRouteWithSentry', () => {
}).rejects.toThrowError('Server Route Error');
expect(captureExceptionSpy).toHaveBeenCalledWith(error, {
- mechanism: { type: 'sveltekit', handled: false, data: { function: 'serverRoute' } },
+ mechanism: { type: 'auto.function.sveltekit.server_route', handled: false },
});
});
@@ -101,7 +101,10 @@ describe('wrapServerRouteWithSentry', () => {
expect(captureExceptionSpy).toHaveBeenCalledWith(
{ body: { message: `error(${status}) error` }, status },
{
- mechanism: { type: 'sveltekit', handled: false, data: { function: 'serverRoute' } },
+ mechanism: {
+ type: 'auto.function.sveltekit.server_route',
+ handled: false,
+ },
},
);
});