Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/src/client/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function handleErrorWithSentry(handleError?: HandleClientError): HandleCl

captureException(input.error, {
mechanism: {
type: 'sveltekit',
type: 'auto.function.sveltekit.handle_error',
handled: !!handleError,
},
});
Expand Down
5 changes: 1 addition & 4 deletions packages/sveltekit/src/client/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ function sendErrorToSentry(e: unknown): unknown {

captureException(objectifiedErr, {
mechanism: {
type: 'sveltekit',
type: 'auto.function.sveltekit.load',
handled: false,
data: {
function: 'load',
},
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/src/server-common/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function handleErrorWithSentry(handleError?: HandleServerError): HandleSe

captureException(input.error, {
mechanism: {
type: 'sveltekit',
type: 'auto.function.sveltekit.handle_error',
handled: !!handleError,
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/src/server-common/serverRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function wrapServerRouteWithSentry<T extends RequestEvent>(
() => wrappingTarget.apply(thisArg, args),
);
} catch (e) {
sendErrorToSentry(e, 'serverRoute');
sendErrorToSentry(e, 'server_route');
throw e;
} finally {
await flushIfServerless();
Expand Down
7 changes: 2 additions & 5 deletions packages/sveltekit/src/server-common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
},
},
});

Expand Down
10 changes: 4 additions & 6 deletions packages/sveltekit/test/client/handleError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand All @@ -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);
});
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/test/client/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/test/server-common/handle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
}
});
Expand Down
10 changes: 4 additions & 6 deletions packages/sveltekit/test/server-common/handleError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HandleServerError> {
return {
message: 'Whoops!',
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/test/server-common/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
});
});
Expand Down
7 changes: 5 additions & 2 deletions packages/sveltekit/test/server-common/serverRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
});

Expand All @@ -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,
},
},
);
});
Expand Down