Prechádzať zdrojové kódy

feat: 更新sentry环境变量

sunxiao 1 týždeň pred
rodič
commit
2d877dded5
5 zmenil súbory, kde vykonal 39 pridanie a 25 odobranie
  1. 3 2
      .env.development
  2. 5 1
      .env.jms
  3. 5 1
      .env.production
  4. 22 17
      src/main.js
  5. 4 4
      vite.config.js

+ 3 - 2
.env.development

@@ -11,5 +11,6 @@ VITE_AUDIO_BASE_URL = https://pbx.fuxicarbon.com/
 
 VITE_HS_CTI_BASE_URL = pbx.fuxicarbon.com
 
-# VITE_APP_BASE_API =  http://192.168.40.21:8001/
-
+# sentry 配置
+VITE_SENTRY_DSN = https://f49d441715062cdbbaa361797e0452e7@sentry.fuxicarbon.com/4
+VITE_SENTRY_AUTH_TOKEN = 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

+ 5 - 1
.env.jms

@@ -13,4 +13,8 @@ VITE_AUDIO_BASE_URL = https://jms.sqlibra.com/
 VITE_HS_CTI_BASE_URL = jms.sqlibra.com 
 
 # 是否在打包时开启压缩,支持 gzip 和 brotli
-VITE_BUILD_COMPRESS = gzip
+VITE_BUILD_COMPRESS = gzip
+
+# sentry 配置
+VITE_SENTRY_DSN = https://f49d441715062cdbbaa361797e0452e7@sentry.fuxicarbon.com/4
+VITE_SENTRY_AUTH_TOKEN = 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

+ 5 - 1
.env.production

@@ -13,4 +13,8 @@ VITE_AUDIO_BASE_URL = https://pbx.fuxicarbon.com/
 VITE_HS_CTI_BASE_URL = pbx.fuxicarbon.com
 
 # 是否在打包时开启压缩,支持 gzip 和 brotli
-VITE_BUILD_COMPRESS = gzip
+VITE_BUILD_COMPRESS = gzip
+
+# sentry 配置
+VITE_SENTRY_DSN = https://f49d441715062cdbbaa361797e0452e7@sentry.fuxicarbon.com/4
+VITE_SENTRY_AUTH_TOKEN = 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

+ 22 - 17
src/main.js

@@ -71,21 +71,24 @@ app.component('ImagePreview', ImagePreview)
 app.component('RightToolbar', RightToolbar)
 app.component('Editor', Editor)
 
-Sentry.init({
-  app,
-  dsn: "https://f49d441715062cdbbaa361797e0452e7@sentry.fuxicarbon.com/4",
-  integrations: [
-    Sentry.browserTracingIntegration({ router }),
-    Sentry.replayIntegration(),
-  ],
-  // Tracing
-  tracesSampleRate: 1.0, //  Capture 100% of the transactions
-  // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
-  tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
-  // Session Replay
-  replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
-  replaysOnErrorSampleRate: 1.0, // I
-});
+if ( import.meta.env.VITE_APP_ENV  === 'production' ) {
+  Sentry.init({
+    app,
+    dsn: import.meta.env.VITE_SENTRY_DSN,
+    integrations: [
+      Sentry.browserTracingIntegration({ router }),
+      Sentry.replayIntegration(),
+    ],
+    // Tracing
+    tracesSampleRate: 1.0, //  Capture 100% of the transactions
+    // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
+    tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
+    // Session Replay
+    replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
+    replaysOnErrorSampleRate: 1.0, // I
+  });
+}
+
 
 app.use(router)
 app.use(store)
@@ -102,8 +105,10 @@ app.use(ElementPlus, {
   size: Cookies.get('size') || 'default'
 })
 app.config.errorHandler = (err, instance, info) => {
-  console.error("Vue Error: ", err);
-  Sentry.captureException(err);
+  if ( import.meta.env.VITE_APP_ENV  === 'production'  ) {
+    console.error("Vue Error: ", err);
+    Sentry.captureException(err);
+  }
 };
 
 app.mount('#app')

+ 4 - 4
vite.config.js

@@ -6,7 +6,7 @@ import { sentryVitePlugin } from '@sentry/vite-plugin'
 // https://vitejs.dev/config/
 export default defineConfig(({ mode, command }) => {
   const env = loadEnv(mode, process.cwd())
-  const { VITE_APP_ENV } = env
+  const { VITE_APP_ENV, VITE_SENTRY_AUTH_TOKEN } = env;
   return {
     // 部署生产环境和开发环境下的URL。
     // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
@@ -15,15 +15,15 @@ export default defineConfig(({ mode, command }) => {
     base: VITE_APP_ENV === 'production' ? '/' : '/',
     plugins: [
       createVitePlugins(env, command === 'build'),
-      sentryVitePlugin({
+      VITE_APP_ENV === 'production' ? sentryVitePlugin({
         url: 'https://sentry.fuxicarbon.com',  // 你的 Sentry 服务器地址
         org: 'sentry',  // 你的组织名称
         project: 'test-vue',  // 你的 Sentry 项目名称
         release: 'sentry001',  // 👈 修正格式,release 需要是 string
-        authToken: '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',  
+        authToken: VITE_SENTRY_AUTH_TOKEN,  
         include: './dist',  // 👈 确保匹配你的 `dist` 目录
         ignore: ['node_modules', 'dist/**/*.html'],  // 忽略 node_modules 和 HTML
-      }),
+      }) : null,
     ],
     build: {
       sourcemap: true, // 开启 Source Map