浏览代码

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

Manav Rathi 1 年之前
父节点
当前提交
8a769ea08b
共有 2 个文件被更改,包括 29 次插入13 次删除
  1. 6 12
      packages/shared/next/next.config.base.js
  2. 23 1
      packages/shared/sentry/config/sentry.config.base.ts

+ 6 - 12
packages/shared/next/next.config.base.js

@@ -52,26 +52,20 @@ const nextConfig = {
     },
     },
 
 
     // Build time Sentry configuration
     // Build time Sentry configuration
+    // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
     sentry: {
     sentry: {
         widenClientFileUpload: true,
         widenClientFileUpload: true,
         disableServerWebpackPlugin: 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`)
 // 2. Upload sourcemaps (using the settings defined in `sentry.properties`)
 //
 //
 // Irritatingly, it insists that we also provide it (empty)
 // Irritatingly, it insists that we also provide it (empty)
 // sentry.server.config.ts and sentry.edge.config.ts files too, even though we
 // sentry.server.config.ts and sentry.edge.config.ts files too, even though we
 // are not using those parts.
 // are not using those parts.
-module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);
+module.exports = withSentryConfig(nextConfig, {});

+ 23 - 1
packages/shared/sentry/config/sentry.config.base.ts

@@ -7,9 +7,31 @@ export const initSentry = async (dsn: string) => {
     const optedOut = runningInBrowser() && getHasOptedOutOfCrashReports();
     const optedOut = runningInBrowser() && getHasOptedOutOfCrashReports();
     if (optedOut) return;
     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({
     Sentry.init({
         dsn,
         dsn,
-        environment: process.env.NODE_ENV,
+        release,
         attachStacktrace: true,
         attachStacktrace: true,
         autoSessionTracking: false,
         autoSessionTracking: false,
         tunnel: 'https://sentry-reporter.ente.io',
         tunnel: 'https://sentry-reporter.ente.io',