add sentry to get fronted error logging

This commit is contained in:
Calli
2024-05-19 17:16:29 +03:00
parent c9a7846793
commit 5cf1605a72
10 changed files with 4678 additions and 136 deletions

19
src/app/global-error.jsx Normal file
View File

@@ -0,0 +1,19 @@
"use client";
import * as Sentry from "@sentry/nextjs";
import Error from "next/error";
import { useEffect } from "react";
/* eslint-disable react/prop-types */
export default function GlobalError({ error }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);
return (
<html>
<body>
<Error />
</body>
</html>
);
}

9
src/instrumentation.ts Normal file
View File

@@ -0,0 +1,9 @@
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('../sentry.server.config');
}
if (process.env.NEXT_RUNTIME === 'edge') {
await import('../sentry.edge.config');
}
}

17
src/pages/_error.jsx Normal file
View File

@@ -0,0 +1,17 @@
import * as Sentry from "@sentry/nextjs";
import Error from "next/error";
/* eslint-disable react/prop-types */
const CustomErrorComponent = (props) => {
return <Error statusCode={props.statusCode} />;
};
CustomErrorComponent.getInitialProps = async (contextData) => {
// In case this is running in a serverless function, await this in order to give Sentry
// time to send the error before the lambda exits
await Sentry.captureUnderscoreErrorException(contextData);
// This will contain the status code of the response
return Error.getInitialProps(contextData);
};
export default CustomErrorComponent;