-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(next): add sentry to payments-next
Because: - Be able to use Sentry in Next.js on both the client and the server This commit: - Add Sentry to payments-next using the installation wizard Closes #FXA-9998
- Loading branch information
1 parent
3ac75ba
commit 54fefd2
Showing
24 changed files
with
1,473 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'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> | ||
<body> | ||
{/* `NextError` is the default Next.js error page component. Its type | ||
definition requires a `statusCode` prop. However, since the App Router | ||
does not expose status codes for errors, we simply pass 0 to render a | ||
generic error message. */} | ||
<NextError statusCode={0} /> | ||
</body> | ||
</html> | ||
); | ||
} |
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,6 +1,6 @@ | ||
{ | ||
"name": "payments-next", | ||
"version": "0.0.1", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"start": "next start" | ||
} | ||
|
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,30 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// 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 { initSentryForNextjsClient } from '@fxa/shared/sentry/client'; | ||
import { version } from './package.json'; | ||
|
||
const DEFAULT_SAMPLE_RATE = '1'; | ||
const DEFAULT_TRACES_SAMPLE_RATE = '1'; | ||
|
||
const sentryConfig = { | ||
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, | ||
env: process.env.NEXT_PUBLIC_SENTRY_ENV, | ||
clientName: process.env.NEXT_PUBLIC_SENTRY_CLIENT_NAME, | ||
sampleRate: parseInt( | ||
process.env.NEXT_PUBLIC_SENTRY_SAMPLE_RATE || DEFAULT_SAMPLE_RATE | ||
), | ||
tracesSampleRate: parseInt( | ||
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || | ||
DEFAULT_TRACES_SAMPLE_RATE | ||
), | ||
}; | ||
|
||
initSentryForNextjsClient({ | ||
release: version, | ||
sentry: sentryConfig, | ||
}); |
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,26 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// 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 { initSentryForNextjsServer } from '@fxa/shared/sentry'; | ||
import { config } from './config'; | ||
import { version } from './package.json'; | ||
|
||
const sentryConfig = { | ||
dsn: config.nextPublicSentryDsn, | ||
env: config.nextPublicSentryEnv, | ||
serverName: config.sentry.serverName, | ||
sampleRate: config.nextPublicSentrySampleRate, | ||
tracesSampleRate: config.nextPublicSentryTracesSampleRate, | ||
}; | ||
|
||
initSentryForNextjsServer( | ||
{ | ||
release: version, | ||
sentry: sentryConfig, | ||
}, | ||
console | ||
); |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export * from './lib/next/client'; |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// 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'; | ||
import { SentryConfigOpts } from '../models/SentryConfigOpts'; | ||
import { buildSentryConfig } from '../config-builder'; | ||
import { Logger } from '../sentry.types'; | ||
import { beforeSend } from '../utils/beforeSend.client'; | ||
|
||
/** | ||
* @@todo - To be worked on in FXA-10398 | ||
*/ | ||
const sentryEnabled = true; | ||
|
||
export function initSentryForNextjsClient( | ||
config: SentryConfigOpts, | ||
log?: Logger | ||
) { | ||
if (!log) { | ||
log = console; | ||
} | ||
|
||
if (!config?.sentry?.dsn) { | ||
log.error('No Sentry dsn provided'); | ||
return; | ||
} | ||
|
||
// We want sentry to be disabled by default... This is because we only emit data | ||
// for users that 'have opted in'. A subsequent call to 'enable' is needed to ensure | ||
// that sentry events only flow under the proper circumstances. | ||
//disable(); | ||
|
||
const opts = buildSentryConfig(config, log); | ||
try { | ||
Sentry.init({ | ||
...opts, | ||
integrations: [ | ||
Sentry.browserTracingIntegration({ | ||
enableInp: true, | ||
}), | ||
], | ||
beforeSend: function (event: Sentry.ErrorEvent) { | ||
return beforeSend(sentryEnabled, opts, event); | ||
}, | ||
}); | ||
} catch (e) { | ||
log.error(e); | ||
} | ||
} |
Oops, something went wrong.