-
Notifications
You must be signed in to change notification settings - Fork 905
feat: add Sentry error tracking to all Next.js apps #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||
| import * as Sentry from "@sentry/nextjs"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { env } from "@/env"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Sentry.init({ | ||||||||||||||||||||||||||||
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_ADMIN, | ||||||||||||||||||||||||||||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||||||||||||||||||||||||||||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_ADMIN, | ||||||||||||||||||||||||||||
| tracesSampleRate: | ||||||||||||||||||||||||||||
| env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" ? 0.1 : 1.0, | ||||||||||||||||||||||||||||
| sendDefaultPii: true, | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Privacy concern: Enabling Consider:
🔎 Recommended configuration Sentry.init({
dsn: env.NEXT_PUBLIC_SENTRY_DSN_ADMIN,
environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_ADMIN,
tracesSampleRate: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" ? 0.1 : 1.0,
- sendDefaultPii: true,
+ sendDefaultPii: false,
debug: false,
+ beforeSend(event) {
+ // Scrub sensitive data if needed
+ return event;
+ },
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| debug: false, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import * as Sentry from "@sentry/nextjs"; | ||
|
|
||
| import { env } from "@/env"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_ADMIN, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_ADMIN, | ||
| tracesSampleRate: | ||
| env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" ? 0.1 : 1.0, | ||
| sendDefaultPii: true, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review PII transmission for compliance requirements. The 🤖 Prompt for AI Agents |
||
| debug: false, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| "use client"; | ||
|
|
||
| import * as Sentry from "@sentry/nextjs"; | ||
| import NextError from "next/error"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| export default function GlobalError({ | ||
| error, | ||
| }: { | ||
| error: Error & { digest?: string }; | ||
| }) { | ||
| useEffect(() => { | ||
| Sentry.captureException(error); | ||
| }, [error]); | ||
|
|
||
| return ( | ||
| <html lang="en"> | ||
| <body> | ||
| <NextError statusCode={0} /> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import * as Sentry from "@sentry/nextjs"; | ||
| import { POSTHOG_COOKIE_NAME } from "@superset/shared/constants"; | ||
| import posthog from "posthog-js"; | ||
|
|
||
|
|
@@ -21,3 +22,15 @@ posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, { | |
| }); | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.init({ | ||
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_ADMIN, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_ADMIN, | ||
| tracesSampleRate: | ||
| env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" ? 0.1 : 1.0, | ||
| sendDefaultPii: true, | ||
| debug: false, | ||
| }); | ||
|
Comment on lines
+26
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review PII transmission for compliance requirements. The 🤖 Prompt for AI Agents |
||
|
|
||
| export const onRouterTransitionStart = Sentry.captureRouterTransitionStart; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import * as Sentry from "@sentry/nextjs"; | ||
|
|
||
| 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"); | ||
| } | ||
| } | ||
|
|
||
| export const onRequestError = Sentry.captureRequestError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
import-in-the-middleto a valid version—2.0.1 does not exist.The latest version of
import-in-the-middleis 2.0.0, not 2.0.1 as specified in package.json. This will cause installation failures. @sentry/nextjs@10.32.1 is the latest version and is current. require-in-the-middle@8.0.1 is the latest version and has no known vulnerabilities.🤖 Prompt for AI Agents