Skip to content

Commit e003046

Browse files
committed
ref(nextjs): Add more specific mechanisms to captured errors
1 parent 4745177 commit e003046

11 files changed

+20
-6
lines changed

packages/nextjs/src/common/captureRequestError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function captureRequestError(error: unknown, request: RequestInfo, errorC
3838
captureException(error, {
3939
mechanism: {
4040
handled: false,
41+
type: 'nextjs.onRequestError',
4142
},
4243
});
4344

packages/nextjs/src/common/pages-router-instrumentation/_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function captureUnderscoreErrorException(contextOrProps: ContextOrP
4545
// is what passing a string to `captureException` will wind up doing)
4646
captureException(err || `_error.js called with falsy error (${err})`, {
4747
mechanism: {
48-
type: 'instrument',
48+
type: 'nextjs._error',
4949
handled: false,
5050
data: {
5151
function: '_error.getInitialProps',

packages/nextjs/src/common/pages-router-instrumentation/wrapApiHandlerWithSentry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
110110

111111
captureException(objectifiedErr, {
112112
mechanism: {
113-
type: 'instrument',
113+
type: 'nextjs.api',
114114
handled: false,
115115
data: {
116116
wrapped_handler: wrappingTarget.name,

packages/nextjs/src/common/pages-router-instrumentation/wrapPageComponentWithSentry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function wrapPageComponentWithSentry(pageComponent: FunctionComponent | C
4848
captureException(e, {
4949
mechanism: {
5050
handled: false,
51+
type: 'nextjs.page.class',
5152
},
5253
});
5354
throw e;
@@ -77,6 +78,7 @@ export function wrapPageComponentWithSentry(pageComponent: FunctionComponent | C
7778
captureException(e, {
7879
mechanism: {
7980
handled: false,
81+
type: 'nextjs.page.function',
8082
},
8183
});
8284
throw e;

packages/nextjs/src/common/utils/wrapperUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export function withErrorInstrumentation<F extends (...args: any[]) => any>(
2525
return await origFunction.apply(this, origFunctionArguments);
2626
} catch (e) {
2727
// TODO: Extract error logic from `withSentry` in here or create a new wrapper with said logic or something like that.
28-
captureException(e, { mechanism: { handled: false } });
28+
captureException(e, {
29+
// TODO: check if origFunction.name actually returns the correct name or minified garbage
30+
// in this case, we can add another argument to this wrapper with the respective function name
31+
mechanism: { handled: false, type: 'nextjs.wrapped', data: { function: origFunction.name } },
32+
});
2933
throw e;
3034
}
3135
};
@@ -99,7 +103,7 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
99103
try {
100104
return await origFunction(...origFunctionArgs);
101105
} catch (e) {
102-
captureException(e, { mechanism: { handled: false } });
106+
captureException(e, { mechanism: { handled: false, type: 'nextjs' } });
103107
throw e;
104108
}
105109
}

packages/nextjs/src/common/withServerActionInstrumentation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ async function withServerActionInstrumentationImplementation<A extends (...args:
130130
captureException(error, {
131131
mechanism: {
132132
handled: false,
133+
type: 'nextjs.server-action',
133134
},
134135
});
135136
}

packages/nextjs/src/common/wrapGenerationFunctionWithSentry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
138138
captureException(err, {
139139
mechanism: {
140140
handled: false,
141+
type: 'nextjs.generation-function',
142+
data: {
143+
function: generationFunctionIdentifier,
144+
},
141145
},
142146
});
143147
}

packages/nextjs/src/common/wrapMiddlewareWithSentry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
102102
error => {
103103
captureException(error, {
104104
mechanism: {
105-
type: 'instrument',
105+
type: 'nextjs.middleware',
106106
handled: false,
107107
},
108108
});

packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
9090
captureException(error, {
9191
mechanism: {
9292
handled: false,
93+
type: 'nextjs.route-handler',
9394
},
9495
});
9596
}

packages/nextjs/src/common/wrapServerComponentWithSentry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
130130
captureException(error, {
131131
mechanism: {
132132
handled: false,
133+
type: 'nextjs.server-component',
133134
},
134135
});
135136
}

0 commit comments

Comments
 (0)