forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable sentry features (nodejs#6133)
* feat: enable sentry features * feat: fine-tuned boundaries and filtering * chore: use <anonymous> * chore: add sample rates * feat: error page and boundaries * chore: sample rate and allow urls * chore: attempt to use tunnel * feat: load ondemand * chore: do not provide error details to users * chore: fixed a comment
- Loading branch information
Showing
10 changed files
with
134 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,12 @@ | ||
'use client'; | ||
|
||
import type { FC } from 'react'; | ||
|
||
const ErrorPage: FC<{ error: Error }> = () => ( | ||
<div className="container"> | ||
<h2>500: Internal Server Error</h2> | ||
<h3>This Page has thrown a non-recoverable Error</h3> | ||
</div> | ||
); | ||
|
||
export default ErrorPage; |
This file contains 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 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 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,3 +1,5 @@ | ||
'use client'; | ||
|
||
import type { FC, PropsWithChildren } from 'react'; | ||
|
||
import Footer from '@/components/Footer'; | ||
|
This file contains 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 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 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 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,17 +1,68 @@ | ||
import { SENTRY_DSN, SENTRY_ENABLE } from '@/next.constants.mjs'; | ||
import { | ||
Dedupe, | ||
Breadcrumbs, | ||
HttpContext, | ||
LinkedErrors, | ||
BrowserClient, | ||
getCurrentHub, | ||
defaultStackParser, | ||
makeFetchTransport, | ||
} from '@sentry/nextjs'; | ||
|
||
// This lazy-loads Sentry on the Browser | ||
import('@sentry/nextjs').then(({ init }) => | ||
init({ | ||
// Only run Sentry on Vercel Environment | ||
enabled: SENTRY_ENABLE, | ||
// Tell Sentry where to send events | ||
dsn: SENTRY_DSN, | ||
// Disable Sentry Tracing as we don't need to have it | ||
// as Vercel already does Web Vitals and Performance Measurement on Client-Side | ||
enableTracing: false, | ||
// We only want to capture errors from _next folder on production | ||
// We don't want to capture errors from preview branches here | ||
allowUrls: ['https://nodejs.org/_next'], | ||
}) | ||
); | ||
import { | ||
SENTRY_DSN, | ||
SENTRY_ENABLE, | ||
SENTRY_CAPTURE_RATE, | ||
SENTRY_TUNNEL, | ||
} from '@/next.constants.mjs'; | ||
|
||
// This creates a custom Sentry Client with minimal integrations | ||
export const sentryClient = new BrowserClient({ | ||
// Only run Sentry on Vercel Environment | ||
enabled: SENTRY_ENABLE, | ||
// Provide Sentry's Secret Key | ||
dsn: SENTRY_DSN, | ||
// Sentry's Error Transport Mechanism | ||
transport: makeFetchTransport, | ||
// Sentry's Stack Trace Parser | ||
stackParser: defaultStackParser, | ||
// All supported Integrations by us | ||
integrations: [ | ||
new Dedupe(), | ||
new HttpContext(), | ||
new Breadcrumbs(), | ||
new LinkedErrors(), | ||
], | ||
// We only want to allow ingestion from these pre-selected allowed URLs | ||
// Note that the vercel.app prefix is for our Pull Request Branch Previews | ||
allowUrls: ['https://nodejs.org/', /^https:\/\/.+\.vercel\.app/], | ||
// Percentage of events to send to Sentry (1% of them) (for performance metrics) | ||
tracesSampleRate: SENTRY_CAPTURE_RATE, | ||
// Percentage of events to send to Sentry (1% of them) (for session replays) | ||
replaysSessionSampleRate: SENTRY_CAPTURE_RATE, | ||
// Percentage of events to send to Sentry (1% of them) (for session replays when error happens) | ||
replaysOnErrorSampleRate: 1.0, | ||
// Provides a custom Sentry Tunnel Router | ||
// @note these are components of the Sentry DSN string | ||
// @see @sentry/nextjs/esm/client/tunnelRoute.js | ||
tunnel: SENTRY_TUNNEL(`?o=4506191161786368&p=4506191307735040`), | ||
// Adds custom filtering before sending an Event to Sentry | ||
beforeSend: (event, hint) => { | ||
// Attempts to grab the original Exception before any "magic" happens | ||
const exception = hint.originalException as Error; | ||
|
||
// We only want to capture Errors that have a Stack Trace and that are not Anonymous Errors | ||
return exception?.stack && !exception.stack.includes('<anonymous>') | ||
? event | ||
: null; | ||
}, | ||
}); | ||
|
||
// Attaches this Browser Client to Sentry | ||
getCurrentHub().bindClient(sentryClient); | ||
|
||
// Loads this Dynamically to avoid adding this to the main bundle (initial load) | ||
import('@sentry/nextjs').then(({ Replay, BrowserTracing }) => { | ||
sentryClient.addIntegration(new Replay({ maskAllText: false })); | ||
sentryClient.addIntegration(new BrowserTracing()); | ||
}); |
This file contains 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 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