瀏覽代碼

Manual sentry integration?

main
Steve Ruiz 4 年之前
父節點
當前提交
12349b7129
共有 7 個文件被更改,包括 106 次插入50 次删除
  1. 1
    0
      .gitignore
  2. 71
    17
      next.config.js
  3. 2
    0
      pages/_app.tsx
  4. 0
    14
      sentry.client.config.js
  5. 0
    5
      sentry.properties
  6. 0
    14
      sentry.server.config.js
  7. 32
    0
      utils/sentry.ts

+ 1
- 0
.gitignore 查看文件

@@ -1,4 +1,5 @@
1 1
 # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+*.DS_Store
2 3
 
3 4
 # dependencies
4 5
 /node_modules

+ 71
- 17
next.config.js 查看文件

@@ -1,20 +1,74 @@
1 1
 const withPWA = require('next-pwa')
2
-const { withSentryConfig } = require('@sentry/nextjs')
2
+const SentryWebpackPlugin = require('@sentry/webpack-plugin')
3 3
 
4
-const SentryWebpackPluginOptions = {
5
-  silent: process.env.NODE_ENV === 'development',
6
-}
4
+const {
5
+  NEXT_PUBLIC_SENTRY_DSN: SENTRY_DSN,
6
+  SENTRY_ORG,
7
+  SENTRY_PROJECT,
8
+  SENTRY_AUTH_TOKEN,
9
+  NODE_ENV,
10
+  VERCEL_GIT_COMMIT_SHA,
11
+  SUPABASE_KEY,
12
+  SUPABASE_URL,
13
+  GA_MEASUREMENT_ID,
14
+} = process.env
7 15
 
8
-module.exports = withSentryConfig(
9
-  withPWA({
10
-    future: {
11
-      webpack5: true,
12
-    },
13
-    pwa: {
14
-      dest: 'public',
15
-      scope: '/',
16
-      disable: process.env.NODE_ENV === 'development',
17
-    },
18
-  }),
19
-  SentryWebpackPluginOptions
20
-)
16
+process.env.SENTRY_DSN = SENTRY_DSN
17
+
18
+const basePath = ''
19
+
20
+module.exports = withPWA({
21
+  future: {
22
+    webpack5: true,
23
+  },
24
+  pwa: {
25
+    dest: 'public',
26
+    scope: '/',
27
+    disable: process.env.NODE_ENV === 'development',
28
+  },
29
+
30
+  productionBrowserSourceMaps: true,
31
+  env: {
32
+    NEXT_PUBLIC_COMMIT_SHA: VERCEL_GIT_COMMIT_SHA,
33
+    SUPABASE_KEY: SUPABASE_KEY,
34
+    SUPABASE_URL: SUPABASE_URL,
35
+    GA_MEASUREMENT_ID: GA_MEASUREMENT_ID,
36
+  },
37
+  webpack: (config, options) => {
38
+    if (!options.isServer) {
39
+      config.resolve.alias['@sentry/node'] = '@sentry/browser'
40
+    }
41
+
42
+    config.plugins.push(
43
+      new options.webpack.DefinePlugin({
44
+        'process.env.NEXT_IS_SERVER': JSON.stringify(
45
+          options.isServer.toString()
46
+        ),
47
+      })
48
+    )
49
+
50
+    if (
51
+      SENTRY_DSN &&
52
+      SENTRY_ORG &&
53
+      SENTRY_PROJECT &&
54
+      SENTRY_AUTH_TOKEN &&
55
+      VERCEL_GIT_COMMIT_SHA &&
56
+      NODE_ENV === 'production'
57
+    ) {
58
+      config.plugins.push(
59
+        new SentryWebpackPlugin({
60
+          include: '.next',
61
+          ignore: ['node_modules'],
62
+          stripPrefix: ['webpack://_N_E/'],
63
+          urlPrefix: `~${basePath}/_next`,
64
+          release: VERCEL_GIT_COMMIT_SHA,
65
+          authToken: SENTRY_AUTH_TOKEN,
66
+          org: SENTRY_PROJECT,
67
+          project: SENTRY_ORG,
68
+        })
69
+      )
70
+    }
71
+    return config
72
+  },
73
+  basePath,
74
+})

+ 2
- 0
pages/_app.tsx 查看文件

@@ -3,10 +3,12 @@ import { AppProps } from 'next/app'
3 3
 import { globalStyles } from 'styles'
4 4
 import 'styles/globals.css'
5 5
 import { Provider } from 'next-auth/client'
6
+import { init } from 'utils/sentry'
6 7
 
7 8
 function MyApp({ Component, pageProps }: AppProps) {
8 9
   globalStyles()
9 10
   useGtag()
11
+  init()
10 12
 
11 13
   return (
12 14
     <Provider session={pageProps.session}>

+ 0
- 14
sentry.client.config.js 查看文件

@@ -1,14 +0,0 @@
1
-// This file configures the initialization of Sentry on the browser.
2
-// The config you add here will be used whenever a page is visited.
3
-// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4
-
5
-import * as Sentry from '@sentry/nextjs';
6
-
7
-const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
8
-
9
-Sentry.init({
10
-  dsn: SENTRY_DSN || 'https://d88435642612471d93823489a56ae053@o578706.ingest.sentry.io/5824198',
11
-  // Note: if you want to override the automatic release value, do not set a
12
-  // `release` value here - use the environment variable `SENTRY_RELEASE`, so
13
-  // that it will also get attached to your source maps
14
-});

+ 0
- 5
sentry.properties 查看文件

@@ -1,5 +0,0 @@
1
-defaults.url=https://sentry.io/
2
-defaults.org=stephen-ruiz-ltd
3
-defaults.project=tldraw
4
-auth.token=ac78d09cacd9445abb362a84d071534aef34b84d39704b1fa03f271417b07d30
5
-cli.executable=../../../.npm/_npx/a8388072043b4cbc/node_modules/@sentry/cli/bin/sentry-cli

+ 0
- 14
sentry.server.config.js 查看文件

@@ -1,14 +0,0 @@
1
-// This file configures the initialization of Sentry on the server.
2
-// The config you add here will be used whenever the server handles a request.
3
-// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4
-
5
-import * as Sentry from '@sentry/nextjs';
6
-
7
-const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
8
-
9
-Sentry.init({
10
-  dsn: SENTRY_DSN || 'https://d88435642612471d93823489a56ae053@o578706.ingest.sentry.io/5824198',
11
-  // Note: if you want to override the automatic release value, do not set a
12
-  // `release` value here - use the environment variable `SENTRY_RELEASE`, so
13
-  // that it will also get attached to your source maps
14
-});

+ 32
- 0
utils/sentry.ts 查看文件

@@ -0,0 +1,32 @@
1
+import * as Sentry from '@sentry/node'
2
+import { RewriteFrames } from '@sentry/integrations'
3
+
4
+export const init = () => {
5
+  if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
6
+    const integrations = []
7
+    if (
8
+      process.env.NEXT_IS_SERVER === 'true' &&
9
+      process.env.NEXT_PUBLIC_SENTRY_SERVER_ROOT_DIR
10
+    ) {
11
+      integrations.push(
12
+        new RewriteFrames({
13
+          iteratee: (frame) => {
14
+            frame.filename = frame.filename.replace(
15
+              process.env.NEXT_PUBLIC_SENTRY_SERVER_ROOT_DIR,
16
+              'app:///'
17
+            )
18
+            frame.filename = frame.filename.replace('.next', '_next')
19
+            return frame
20
+          },
21
+        })
22
+      )
23
+    }
24
+
25
+    Sentry.init({
26
+      enabled: process.env.NODE_ENV === 'production',
27
+      integrations,
28
+      dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
29
+      release: process.env.NEXT_PUBLIC_COMMIT_SHA,
30
+    })
31
+  }
32
+}

Loading…
取消
儲存