-
Notifications
You must be signed in to change notification settings - Fork 3
NextJS Sentry Integration #1701
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ebee393
configure sentry, fix error pages
ChristopherChudzicki d13cc86
add env vars to CI
ChristopherChudzicki d0f9183
add global styles to global-error
ChristopherChudzicki 0fa1b8e
TEMPORARY self destruct button
ChristopherChudzicki 3f85f0f
cleanup
ChristopherChudzicki c2e7e9c
cleanup error boundary, other misc cleanup
ChristopherChudzicki 88f04d0
remove a few useless things
ChristopherChudzicki 1ac605a
add a simple test i guess
ChristopherChudzicki 855af10
remove intentional error triggers
ChristopherChudzicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,3 +34,6 @@ yarn-error.log* | |
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
|
|
||
| # Sentry Config File | ||
| .env.sentry-build-plugin | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ const processFeatureFlags = () => { | |
|
|
||
| /** @type {import('next').NextConfig} */ | ||
| const nextConfig = { | ||
| productionBrowserSourceMaps: true, | ||
| async rewrites() { | ||
| return [ | ||
| /* Images moved from /static, though image paths are sometimes | ||
|
|
@@ -99,4 +100,32 @@ const nextConfig = { | |
| }, | ||
| } | ||
|
|
||
| module.exports = nextConfig | ||
| // Injected content via Sentry wizard below | ||
|
|
||
| const { withSentryConfig } = require("@sentry/nextjs") | ||
|
|
||
| module.exports = withSentryConfig(nextConfig, { | ||
|
Contributor
Author
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. This, and a lot of stuff below, was injected automatically by |
||
| // For all available options, see: | ||
| // https://github.com/getsentry/sentry-webpack-plugin#options | ||
|
|
||
| org: "mit-office-of-digital-learning", | ||
| project: "open-next", | ||
|
|
||
| // Only print logs for uploading source maps in CI | ||
| silent: !process.env.CI, | ||
|
|
||
| // For all available options, see: | ||
| // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ | ||
|
|
||
| // Upload a larger set of source maps for prettier stack traces (increases build time) | ||
| widenClientFileUpload: true, | ||
|
|
||
| // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. | ||
| // This can increase your server load as well as your hosting bill. | ||
| // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- | ||
| // side errors will fail. | ||
| // tunnelRoute: "/monitoring", | ||
|
|
||
| // Automatically tree-shake Sentry logger statements to reduce bundle size | ||
| disableLogger: true, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Added by @sentry/wizard | ||
| // This file configures the initialization of Sentry on the client. | ||
| // The config you add here will be used whenever a users loads a page in their browser. | ||
| // https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
|
||
| import * as Sentry from "@sentry/nextjs" | ||
|
|
||
| Sentry.init({ | ||
| dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, | ||
| release: process.env.NEXT_PUBLIC_VERSION, | ||
| environment: process.env.NEXT_PUBLIC_SENTRY_ENV, | ||
| profilesSampleRate: Number( | ||
| process.env.NEXT_PUBLIC_SENTRY_PROFILES_SAMPLE_RATE, | ||
| ), | ||
| tracesSampleRate: Number(process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE), | ||
| tracePropagationTargets: process.env.NEXT_PUBLIC_MITOL_API_BASE_URL | ||
| ? [process.env.NEXT_PUBLIC_MITOL_API_BASE_URL] | ||
| : [], | ||
| // Add optional integrations for additional features | ||
| integrations: [ | ||
| Sentry.browserTracingIntegration(), | ||
| Sentry.browserProfilingIntegration(), | ||
| ], | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Added by @sentry/wizard | ||
| // This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on). | ||
| // The config you add here will be used whenever one of the edge features is loaded. | ||
| // Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally. | ||
| // https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
|
||
| import * as Sentry from "@sentry/nextjs" | ||
|
|
||
| Sentry.init({ | ||
| dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, | ||
| release: process.env.NEXT_PUBLIC_VERSION, | ||
| environment: process.env.NEXT_PUBLIC_SENTRY_ENV, | ||
| // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. | ||
| tracesSampleRate: 1, | ||
|
|
||
| // Setting this option to true will print useful information to the console while you're setting up Sentry. | ||
| debug: false, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Added by @sentry/wizard | ||
| // This file configures the initialization of Sentry on the server. | ||
| // The config you add here will be used whenever the server handles a request. | ||
| // https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
|
||
| import * as Sentry from "@sentry/nextjs" | ||
|
|
||
| Sentry.init({ | ||
| dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, | ||
| release: process.env.NEXT_PUBLIC_VERSION, | ||
| environment: process.env.NEXT_PUBLIC_SENTRY_ENV, | ||
| // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. | ||
| tracesSampleRate: 1, | ||
|
|
||
| // Setting this option to true will print useful information to the console while you're setting up Sentry. | ||
| debug: false, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from "react" | ||
| import { renderWithProviders, screen } from "@/test-utils" | ||
| import { HOME } from "@/common/urls" | ||
| import ErrorPage from "./error" | ||
| import { ForbiddenError } from "@/common/permissions" | ||
|
|
||
| test("The error page shows error message", () => { | ||
| const error = new Error("Ruh roh") | ||
| renderWithProviders(<ErrorPage error={error} />) | ||
| screen.getByRole("heading", { name: "Something went wrong." }) | ||
| screen.getByText("Ruh roh") | ||
| const homeLink = screen.getByRole("link", { name: "Home" }) | ||
| expect(homeLink).toHaveAttribute("href", HOME) | ||
| }) | ||
|
|
||
| test("The NotFoundPage loads with a link that directs to HomePage", () => { | ||
| const error = new ForbiddenError("You can't do that") | ||
| renderWithProviders(<ErrorPage error={error} />, { user: {} }) | ||
| screen.getByRole("heading", { name: "Not Allowed" }) | ||
| const homeLink = screen.getByRole("link", { name: "Home" }) | ||
| expect(homeLink).toHaveAttribute("href", HOME) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| "use client" | ||
| /* | ||
| * Fallback error UI for errors within page content. | ||
| * | ||
| * Notes: | ||
| * - DOES use root layout | ||
| * | ||
| * See for more: | ||
| * https://nextjs.org/docs/app/building-your-application/routing/error-handling#handling-errors-in-root-layouts | ||
| */ | ||
|
|
||
| import React, { useEffect } from "react" | ||
| import * as Sentry from "@sentry/nextjs" | ||
| import FallbackErrorPage from "@/app-pages/ErrorPage/FallbackErrorPage" | ||
| import { ForbiddenError } from "@/common/permissions" | ||
| import ForbiddenPage from "@/app-pages/ErrorPage/ForbiddenPage" | ||
| const Error = ({ error }: { error: Error }) => { | ||
| useEffect(() => { | ||
| Sentry.captureException(error) | ||
| }, [error]) | ||
|
|
||
| if (error instanceof ForbiddenError) { | ||
| return <ForbiddenPage /> | ||
| } | ||
|
|
||
| return <FallbackErrorPage error={error} /> | ||
| } | ||
|
|
||
| export default Error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,34 @@ | ||
| "use client" | ||
|
|
||
| /* This is the catch-all error page that receives errors from server rendered root layout | ||
| * components and metadata. | ||
| * It is only enabled in production so that in development we see the Next.js error overlay. | ||
| * It is passed an error object as an argument, though this has been stripped of everything except | ||
| * the message and a digest for server logs correlation; to prevent leaking anything to the client | ||
| /* | ||
| * Fallback error UI for errors within root layout. | ||
| * (error.tsx is the fallback error page for UI within page content.) | ||
| * | ||
| * Notes: | ||
| * - does NOT use root layout (since error occured there!) | ||
| * - therefore, must definie its own HTML tags and providers | ||
| * Must define its own HTML tag | ||
| * - NOT used in development mode | ||
| * | ||
| * https://nextjs.org/docs/app/building-your-application/routing/error-handling#handling-errors-in-root-layouts | ||
| */ | ||
| import React, { useEffect } from "react" | ||
| import * as Sentry from "@sentry/nextjs" | ||
| import FallbackErrorPage from "@/app-pages/ErrorPage/FallbackErrorPage" | ||
| import { MITLearnGlobalStyles, ThemeProvider } from "ol-components" | ||
|
|
||
| import React from "react" | ||
| import GlobalErrorPage from "@/app-pages/ErrorPage/GlobalErrorPage" | ||
|
|
||
| const GlobalError = ({ error }: { error: Error }) => { | ||
| return <GlobalErrorPage error={error} /> | ||
| export default function GlobalError({ error }: { error: Error }) { | ||
| useEffect(() => { | ||
| Sentry.captureException(error) | ||
| }, [error]) | ||
| return ( | ||
| <html lang="en"> | ||
| <body> | ||
| <ThemeProvider> | ||
| <MITLearnGlobalStyles /> | ||
| <FallbackErrorPage error={error} /> | ||
| </ThemeProvider> | ||
| </body> | ||
| </html> | ||
| ) | ||
| } | ||
|
|
||
| export default GlobalError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
From docs
Seems like silly obfuscation to me.
Anyway, our source is public. I think keeping the source maps public will mean we don't need to upload them to sentry, but we'll only know for sure after we deploy it.