Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to report console.error with Sentry?

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.

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 ?

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

like image 987
Jurosh Avatar asked May 31 '18 22:05

Jurosh


People also ask

How do you log errors Sentry?

The most common form of capturing is to capture errors. What can be captured as an error varies by platform. In general, if you have something that looks like an exception, it can be captured. For some SDKs, you can also omit the argument to captureException and Sentry will attempt to capture the current exception.

What is a console error?

The console. error() method in HTML is used to display an error message on the console. The console. error() method is used for testing purpose. The error message is sent as a parameter to the console.

What is Sentry error?

What is Sentry? Sentry is Open-source error tracking that helps developers to monitor, fix crashes in real time. Don't forget about boosting the efficiency, improving user experience. Sentry has support for JavaScript, React, Node, Python, PHP, Ruby, Java and other programming languages.


1 Answers

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/configuration/integrations/plugin/#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.

like image 89
Marc Schmid Avatar answered Sep 18 '22 14:09

Marc Schmid