Skip to content

Commit f9afaaa

Browse files
authored
Implement sentry (#3)
1 parent c3ebebb commit f9afaaa

File tree

10 files changed

+2644
-170
lines changed

10 files changed

+2644
-170
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# URL of the finder API
2-
NEXT_PUBLIC_URL_FINDER_API_URL=""
2+
NEXT_PUBLIC_URL_FINDER_API_URL=""
3+
4+
NEXT_PUBLIC_SENTRY_DSN=
5+
NEXT_PUBLIC_SENTRY_ORG=
6+
NEXT_PUBLIC_SENTRY_PROJECT=
7+
NEXT_PUBLIC_SENTRY_AUTH_TOKEN=
8+
NEXT_PUBLIC_SENTRY_ENV=

.github/workflows/build-docker-image.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ jobs:
5858
- name: Create env file
5959
run: |
6060
echo "NEXT_PUBLIC_URL_FINDER_API_URL='${{ vars.NEXT_PUBLIC_URL_FINDER_API_URL }}'" >> .env
61+
echo "NEXT_PUBLIC_SENTRY_DSN='${{ vars.NEXT_PUBLIC_SENTRY_DSN }}'" >> .env
62+
echo "NEXT_PUBLIC_SENTRY_ORG='${{ vars.NEXT_PUBLIC_SENTRY_ORG }}'" >> .env
63+
echo "NEXT_PUBLIC_SENTRY_PROJECT='${{ vars.NEXT_PUBLIC_SENTRY_PROJECT }}'" >> .env
64+
echo "NEXT_PUBLIC_SENTRY_ENV='${{ vars.NEXT_PUBLIC_SENTRY_ENV }}'" >> .env
65+
66+
echo "NEXT_PUBLIC_SENTRY_AUTH_TOKEN='${{ secrets.NEXT_PUBLIC_SENTRY_AUTH_TOKEN }}'" >> .env
6167
6268
- name: Build tag
6369
uses: docker/build-push-action@v6

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ yarn-error.log*
4040
# typescript
4141
*.tsbuildinfo
4242
next-env.d.ts
43+
44+
# Sentry Config File
45+
.env.sentry-build-plugin

app/global-error.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import * as Sentry from "@sentry/nextjs";
4+
import NextError from "next/error";
5+
import { useEffect } from "react";
6+
7+
export default function GlobalError({
8+
error,
9+
}: {
10+
error: Error & { digest?: string };
11+
}) {
12+
useEffect(() => {
13+
Sentry.captureException(error);
14+
}, [error]);
15+
16+
return (
17+
<html>
18+
<body>
19+
<NextError statusCode={0} />
20+
</body>
21+
</html>
22+
);
23+
}

instrumentation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from "@sentry/nextjs";
2+
3+
export async function register() {
4+
if (process.env.NEXT_RUNTIME === "nodejs") {
5+
await import("./sentry.server.config");
6+
}
7+
}
8+
9+
export const onRequestError = Sentry.captureRequestError;

next.config.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1+
import { withSentryConfig } from "@sentry/nextjs";
12
import type { NextConfig } from "next";
23

34
const nextConfig: NextConfig = {
45
output: "standalone",
56
reactStrictMode: true,
67
};
78

8-
export default nextConfig;
9+
export default withSentryConfig(nextConfig, {
10+
// For all available options, see:
11+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
12+
authToken: process.env.NEXT_PUBLIC_SENTRY_AUTH_TOKEN,
13+
org: process.env.NEXT_PUBLIC_SENTRY_ORG,
14+
project: process.env.NEXT_PUBLIC_SENTRY_PROJECT,
15+
16+
// Only print logs for uploading source maps in CI
17+
silent: !process.env.CI,
18+
19+
// For all available options, see:
20+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
21+
22+
// Upload a larger set of source maps for prettier stack traces (increases build time)
23+
widenClientFileUpload: true,
24+
25+
// Automatically annotate React components to show their full name in breadcrumbs and session replay
26+
reactComponentAnnotation: {
27+
enabled: true,
28+
},
29+
30+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
31+
// This can increase your server load as well as your hosting bill.
32+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
33+
// side errors will fail.
34+
tunnelRoute: "/monitoring",
35+
36+
// Automatically tree-shake Sentry logger statements to reduce bundle size
37+
disableLogger: true,
38+
39+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
40+
// See the following for more information:
41+
// https://docs.sentry.io/product/crons/
42+
// https://vercel.com/docs/cron-jobs
43+
automaticVercelMonitors: true,
44+
});

0 commit comments

Comments
 (0)