UNPKG

zcloud-ui

Version:

A Component Library for Vue.js.

68 lines (66 loc) 2.67 kB
/** * sentry 配置文件 * @tiem 2020/10/20 */ import Vue from 'vue'; // import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/vue'; // import { Vue as VueIntegration } from '@sentry/integrations'; import { Integrations } from '@sentry/tracing'; import SentryRRWeb from '@sentry/rrweb'; import { Environment } from 'zcloud-ui/src/config/index'; window.Sentry = Sentry; let integrations = []; // https://docs.sentry.io/platforms/javascript/configuration/options/ option配置 const users = () => { if (Environment.USER_SENTRY && Environment.NODE_ENV === 'production') { if (Environment.USER_SENTRY_RRWEB) { integrations.push(new SentryRRWeb({ checkoutEveryNms: 1 * 60 * 1000 // 只保存最近1分钟的 })); } // integrations.push(new VueIntegration({ Vue, attachProps: true, logErrors: true })); integrations.push(new Integrations.BrowserTracing()); Sentry.init({ Vue, tracingOptions: { trackComponents: true }, dsn: Environment.SENTRY_DSN, beforeSend (event, hint) { let values = event.exception ? (event.exception.values || []) : []; // 排除no catch 错误 if (values && values.length && values[0].type === 'UnhandledRejection') { if (event.extra && event.extra.__serialized__ && event.extra.__serialized__.api && values[0].value.includes('res')) { values[0].value = '请求地址: ' + event.extra.__serialized__.api; values[0].mechanism = { handled: false, type: 'generic' }; values[0].type = '请求返回,发生错误'; } else { return null; } } // // 排除element带来的错误影响 // if (values && values.length && values[0].type === 'Error') { // if (values[0].value === 'ResizeObserver loop limit exceeded') { // return null; // } else { // return event; // } // } return event; }, ignoreErrors: [/ResizeObserver loop limit exceeded/i, /Request failed with status code 405/i, ...Environment.SENTRY_IGNORE], sampleRate: 1, // 采样收集率 0-1之前 sendDefaultPii: true, // 个人身份信息 maxBreadcrumbs: 50, // 面包屑的总量 normalizeDepth: 6, // 上下文数据标准化到给定深度 integrations, // release: Environment.PROJECTNAME + '@' + Environment.RELEASE, release: Environment.RELEASE, logErrors: true, environment: Environment.USER_ENVIRONMENT }); Sentry.setTag('rrweb.active', Environment.USER_SENTRY_RRWEB ? 'yes' : 'no'); } }; export default users;