Skip to content

Commit fbd9853

Browse files
committed
Add extra info on page crashing errors to identify them in Sentry dashboard (#5068)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR enhances error handling in the application by integrating `Sentry` with additional context for captured exceptions, specifically tagging the errors and providing extra information about the crashed page and router. ### Detailed summary - In `global-error.tsx`, modified `Sentry.captureException` to use `Sentry.withScope` for better error context. - Added tags and extra data (e.g., `crashedPage`, `boundary`, `router`) to the captured exceptions. - In `_error.tsx`, implemented similar changes for handling errors with `contextData`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent b01faac commit fbd9853

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

apps/dashboard/src/app/global-error.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ export default function GlobalError({
1313
// legitimate usecase
1414
// eslint-disable-next-line no-restricted-syntax
1515
useEffect(() => {
16-
Sentry.captureException(error);
16+
Sentry.withScope((scope) => {
17+
scope.setTag("page-crashed", "true");
18+
scope.setLevel("fatal");
19+
Sentry.captureException(error, {
20+
extra: {
21+
crashedPage: true,
22+
boundary: "global",
23+
router: "app",
24+
},
25+
});
26+
});
1727
}, [error]);
1828

1929
return (

apps/dashboard/src/pages/_error.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ CustomErrorComponent.getInitialProps = async (contextData) => {
2323
// time to send the error before the lambda exits
2424
await Sentry.captureUnderscoreErrorException(contextData);
2525

26+
if (contextData.err instanceof Error) {
27+
Sentry.withScope((scope) => {
28+
scope.setTag("page-crashed", "true");
29+
scope.setLevel("fatal");
30+
Sentry.captureException(contextData.err, {
31+
extra: {
32+
crashedPage: true,
33+
boundary: "global",
34+
router: "pages",
35+
},
36+
});
37+
});
38+
}
39+
2640
// This will contain the status code of the response
2741
return NextErrorComponent.getInitialProps(contextData);
2842
};

0 commit comments

Comments
 (0)