How to report console.error with Sentry?

后端 未结 5 1286
孤独总比滥情好
孤独总比滥情好 2021-02-12 20:23

I have application where some critical issues are reported with console.error but are not thrown so application might continue to run - possibly in cri

5条回答
  •  走了就别回头了
    2021-02-12 20:57

    As user @kumar303 mentioned in his comment to the question ... you can use the JS console integration Sentry.Integrations.CaptureConsole.

    See https://docs.sentry.io/platforms/javascript/?platform=browsernpm#captureconsole for documentation.

    At the end you JS code to setup Sentry looks as follows:

    import * as Sentry from '@sentry/browser';
    import { CaptureConsole } from '@sentry/integrations';
    
    Sentry.init({
      dsn: 'https://your-sentry-server-dsn',
      integrations: [
        new CaptureConsole({
          levels: ['error']
        })
      ],
      release: '1.0.0',
      environment: 'prod',
      maxBreadcrumbs: 50
    })
    

    If then someone calls console.error a new event will sent to sentry.

提交回复
热议问题