Specify the release in Sentry.init instead of the webpack plugin

This commit is contained in:
Manav Rathi 2024-02-13 11:25:31 +05:30
parent 80b31ebe3b
commit 8a769ea08b
2 changed files with 29 additions and 13 deletions

View file

@ -52,26 +52,20 @@ const nextConfig = {
},
// Build time Sentry configuration
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
sentry: {
widenClientFileUpload: true,
disableServerWebpackPlugin: true,
},
};
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
const sentryWebpackPluginOptions = {
// Sentry supports automatically deducing this, and if running the
// sentry-cli release propose-version command directly, it can indeed find
// the git SHA, but I've been unable to get that to work here without
// explicitly specifying the git SHA.
release: gitSHA,
};
// withSentryConfig extends the default Next.js usage of webpack to
// 1. Initialize the SDK on client page load (`sentry.client.config.ts`)
// withSentryConfig extends the default Next.js usage of webpack to:
//
// 1. Initialize the SDK on client page load (See `sentry.client.config.ts`)
//
// 2. Upload sourcemaps (using the settings defined in `sentry.properties`)
//
// Irritatingly, it insists that we also provide it (empty)
// sentry.server.config.ts and sentry.edge.config.ts files too, even though we
// are not using those parts.
module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);
module.exports = withSentryConfig(nextConfig, {});

View file

@ -7,9 +7,31 @@ export const initSentry = async (dsn: string) => {
const optedOut = runningInBrowser() && getHasOptedOutOfCrashReports();
if (optedOut) return;
// [Note: Specifying the Sentry release]
//
// Sentry supports automatically deducing the release, and if running the
// `sentry-cli release propose-version` command directly, it can indeed find
// and use the git SHA as the release, but I've been unable to get that
// automated detection to work with the Sentry webpack plugin.
//
// The other recommended approach, and what we were using earlier, is
// specify the release param in the `sentryWebpackPluginOptions` (second)
// argument to `withSentryConfig`. However, we selectively turn off Sentry
// to disable sourcemap uploads when the auth token is not available, and
// Sentry's documentation states that
//
// > Disable SentryWebPackPlugin... Note that [when doing so] you'll also
// > have to explicitly set a `release` value in your `Sentry.init()`.
//
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#disable-sentrywebpackplugin
//
// So we just keep things simple and always specify the release here (and
// only here).
const release = process.env.GIT_SHA;
Sentry.init({
dsn,
environment: process.env.NODE_ENV,
release,
attachStacktrace: true,
autoSessionTracking: false,
tunnel: 'https://sentry-reporter.ente.io',