如何使用Sentry报告console

如何使用Sentry报告console

本文介绍了如何使用Sentry报告console.error?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中一些严重问题报告为 console.error ,但没有被抛出,因此应用程序可能会继续运行-可能处于残废状态。

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

还必须报告 console.error 问题,但哨兵(Raven )库仅将抛出的异常发送到服务器。

It's necessary to report also console.error issues, but Sentry (Raven) library send to server only thrown exceptions.

有人知道如何很好地解决这个问题吗?

Does someone knows how to solve this nicely ?

(理想情况下,无需重写所有 console.error 调用,因为某些供应商库可能仍会将输出仅写入控制台中)

(ideally without need to rewrite all console.error calls, cause also some vendor libraries might still write output just into console)

推荐答案

作为@ kumar303用户,他在对该问题的评论中提到...您可以使用JS控制台集成 Sentry.Integrations.CaptureConsole

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

请参见用于文档

最后,用于设置Sentry的JS代码如下:

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

Sentry.init({
  dsn: 'https://your-sentry-server-dsn',
  integrations: [
    new Integrations.CaptureConsole({
      levels: ['error']
    })
  ],
  release: '1.0.0',
  environment: 'prod',
  maxBreadcrumbs: 50
})

如果有人打电话给 console.error 一个新事件将发送到哨兵。

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

这篇关于如何使用Sentry报告console.error?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 11:46