vue项目配置方式

  1. yarn add @sentry/browser @sentry/integrations

react参考

https://zhuanlan.zhihu.com/p/210765546

实践配置

main.js

  1. import * as Sentry from '@sentry/browser'
  2. import * as Integrations from '@sentry/integrations
  3. Sentry.init({
  4. dsn: 'https://9c2fccbc9da746a3824f15a4f4c64990@sentry.priv-shield.com/4',
  5. environment: process.env.NODE_ENV,
  6. integrations: [new Integrations.Vue({ Vue, attachProps: true, logErrors: true })]
  7. })

image.png

sentry 文档补充

https://github.com/getsentry/sentry-javascript

  1. import { init, captureMessage } from '@sentry/browser';
  2. init({
  3. dsn: '__DSN__',
  4. environment: process.env.NODE_ENV,
  5. // ...
  6. });
  7. captureMessage('Hello, world!');

Vue3

https://docs.sentry.io/platforms/javascript/guides/vue/

  1. import { createApp } from "vue";
  2. import { createRouter } from "vue-router";
  3. import * as Sentry from "@sentry/vue";
  4. import { BrowserTracing } from "@sentry/tracing";
  5. const app = createApp({
  6. // ...
  7. });
  8. const router = createRouter({
  9. // ...
  10. });
  11. Sentry.init({
  12. app,
  13. dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  14. integrations: [
  15. new BrowserTracing({
  16. routingInstrumentation: Sentry.vueRouterInstrumentation(router),
  17. tracingOrigins: ["localhost", "my-site-url.com", /^\//],
  18. }),
  19. ],
  20. // Set tracesSampleRate to 1.0 to capture 100%
  21. // of transactions for performance monitoring.
  22. // We recommend adjusting this value in production
  23. tracesSampleRate: 1.0,
  24. });
  25. app.use(router);
  26. app.mount("#app");