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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ test('should send error for faulty click handlers', async ({ page }) => {

expect(errorEvent).toBeDefined();

const frames = errorEvent?.exception?.values?.[0]?.stacktrace?.frames;
const exception = errorEvent?.exception?.values?.[0];

expect(exception?.mechanism).toEqual({
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
data: {
handler: expect.any(String), // the handler name varies in CI and locally
target: 'EventTarget',
},
});

const frames = exception?.stacktrace?.frames;
await test.step('error should have a non-url-encoded top frame in route with parameter', () => {
if (process.env.TEST_ENV === 'development') {
// In dev mode we want to check local source mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('Should report an error event for errors thrown in getServerSideProps', asy
exception: {
values: [
{
mechanism: { handled: false, type: 'generic' },
mechanism: { handled: false, type: 'auto.function.nextjs.wrapped' },
type: 'Error',
value: 'getServerSideProps Error',
stacktrace: {
Expand Down Expand Up @@ -110,7 +110,7 @@ test('Should report an error event for errors thrown in getServerSideProps in pa
exception: {
values: [
{
mechanism: { handled: false, type: 'generic' },
mechanism: { handled: false, type: 'auto.function.nextjs.wrapped' },
type: 'Error',
value: 'custom page extension error',
stacktrace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('Should report an error event for errors thrown in pages router api routes'
function: 'withSentry',
},
handled: false,
type: 'instrument',
type: 'auto.http.nextjs.api_handler',
},
stacktrace: { frames: expect.arrayContaining([]) },
type: 'Error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Should capture an error thrown in a server component', async ({ page }) =>
exception: {
values: [
{
mechanism: { handled: false, type: 'generic' },
mechanism: { handled: false, type: 'auto.function.nextjs.server_component' },
type: 'Error',
value: 'RSC error',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ test('Should capture errors from nested server components when `Sentry.captureRe
router_path: '/nested-rsc-error/[param]',
request_path: '/nested-rsc-error/123',
});

expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: 'auto.function.nextjs.on_request_error',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ test('Should capture errors for crashing streaming promises in server components
router_path: '/streaming-rsc-error/[param]',
request_path: '/streaming-rsc-error/123',
});

expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: 'auto.function.nextjs.on_request_error',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ test('Sends a client-side exception to Sentry', async ({ page }) => {
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
});

expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: nextjsMajor >= 15 ? 'auto.browser.global_handlers.onerror' : 'auto.browser.browserapierrors.addEventListener',
...(nextjsMajor < 15 && {
data: {
handler: expect.any(String), // the handler name varies in CI and locally
target: 'EventTarget',
},
}),
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ test('Should record exceptions for faulty edge server components', async ({ page
expect(errorEvent.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();

expect(errorEvent.transaction).toBe(`Page Server Component (/edge-server-components/error)`);

expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: 'auto.function.nextjs.server_component',
});
});

test('Should record transaction for edge server components', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ test('should capture orpc error', async ({ page }) => {
}),
],
});

// orpc errors are captured manually by the orpc middleware (user-land)
expect(orpcError.exception?.values?.[0]?.mechanism).toEqual({
handled: true,
type: 'generic',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ test('Will capture error for SSR rendering error with a connected trace (Functio
// TODO(lforst): Reuse SSR request span isolation scope to fix the following two assertions
// expect(ssrTransaction.tags?.['my-isolated-tag']).toBe(true);
// expect(ssrTransaction.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();

expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: 'auto.function.nextjs.page_function',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ test('should capture error with trpc context', async ({ page }) => {
expect(trpcError.contexts?.trpc?.procedure_type).toEqual('mutation');
expect(trpcError.contexts?.trpc?.procedure_path).toBe('post.throwError');
expect(trpcError.contexts?.trpc?.input).toEqual({ name: 'I love dogs' });

expect(trpcError.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: 'auto.rpc.trpc.middleware',
exception_id: 1,
parent_id: 0,
source: 'cause',
});
});

test('should create transaction with trpc input for error', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ test('Should capture errors from server components', async ({ page }) => {
const errorEvent = await errorEventPromise;

expect(errorEvent).toBeDefined();
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
handled: false,
type: 'auto.function.nextjs.on_request_error',
});
});
1 change: 1 addition & 0 deletions packages/nextjs/src/common/captureRequestError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function captureRequestError(error: unknown, request: RequestInfo, errorC
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.on_request_error',
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function captureUnderscoreErrorException(contextOrProps: ContextOrP
// is what passing a string to `captureException` will wind up doing)
captureException(err || `_error.js called with falsy error (${err})`, {
mechanism: {
type: 'instrument',
type: 'auto.function.nextjs.underscore_error',
handled: false,
data: {
function: '_error.getInitialProps',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz

captureException(objectifiedErr, {
mechanism: {
type: 'instrument',
type: 'auto.http.nextjs.api_handler',
handled: false,
data: {
wrapped_handler: wrappingTarget.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function wrapPageComponentWithSentry(pageComponent: FunctionComponent | C
captureException(e, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.page_class',
},
});
throw e;
Expand Down Expand Up @@ -77,6 +78,7 @@ export function wrapPageComponentWithSentry(pageComponent: FunctionComponent | C
captureException(e, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.page_function',
},
});
throw e;
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/src/common/utils/wrapperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export function withErrorInstrumentation<F extends (...args: any[]) => any>(
return await origFunction.apply(this, origFunctionArguments);
} catch (e) {
// TODO: Extract error logic from `withSentry` in here or create a new wrapper with said logic or something like that.
captureException(e, { mechanism: { handled: false } });
captureException(e, {
// TODO: check if origFunction.name actually returns the correct name or minified garbage
// in this case, we can add another argument to this wrapper with the respective function name
mechanism: { handled: false, type: 'auto.function.nextjs.wrapped', data: { function: origFunction.name } },
});
throw e;
}
};
Expand Down Expand Up @@ -99,7 +103,7 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
try {
return await origFunction(...origFunctionArgs);
} catch (e) {
captureException(e, { mechanism: { handled: false } });
captureException(e, { mechanism: { handled: false, type: 'auto.function.nextjs.data_fetcher' } });
throw e;
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/src/common/withServerActionInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getClient,
getIsolationScope,
handleCallbackErrors,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
SPAN_STATUS_ERROR,
startSpan,
Expand Down Expand Up @@ -116,6 +117,7 @@ async function withServerActionInstrumentationImplementation<A extends (...args:
forceTransaction: true,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.server_action',
},
},
async span => {
Expand All @@ -130,6 +132,7 @@ async function withServerActionInstrumentationImplementation<A extends (...args:
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_action',
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
captureException(err, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.generation_function',
data: {
function: generationFunctionIdentifier,
},
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/common/wrapMiddlewareWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
op: 'http.server.middleware',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: spanSource,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.wrapMiddlewareWithSentry',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.wrap_middleware',
...headerAttributes,
},
},
Expand All @@ -108,7 +108,7 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
error => {
captureException(error, {
mechanism: {
type: 'instrument',
type: 'auto.function.nextjs.wrap_middleware',
handled: false,
},
});
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.route_handler',
},
});
}
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/src/common/wrapServerComponentWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
name: `${componentType} Server Component (${componentRoute})`,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.server_component',
'sentry.nextjs.ssr.function.type': componentType,
'sentry.nextjs.ssr.function.route': componentRoute,
},
Expand All @@ -136,6 +136,7 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
op: op,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.wrapApiHandlerWithSentry',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.wrap_api_handler',
...headerAttributes,
},
},
Expand All @@ -89,7 +89,7 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
error => {
captureException(error, {
mechanism: {
type: 'instrument',
type: 'auto.function.nextjs.wrap_api_handler',
handled: false,
},
});
Expand Down