Roman Tiukh
Roman Tiukh

Reputation: 51

How to automaticaly send ALL errors from javascript to Sentry?

I want to "automatically" sent all errors from my React project to Sentry, and i mean absolutely ALL, from the code, from React, from Promises.

Is it realistic to set it up?

By init:

    import * as Sentry from '@sentry/browser';
    Sentry.init({ dsn: 'https://<key>@sentry.io/<project>' });

Sentry handles only "uncaught exceptions and unhandled rejections"

From docs:

"Automatically Capturing Errors

By including and configuring Sentry, the SDK will automatically attach global handlers to capture uncaught exceptions and unhandled rejections."

https://docs.sentry.io/platforms/javascript/#automatically-capturing-errors

Upvotes: 5

Views: 1517

Answers (1)

Ricardo Gonzalez
Ricardo Gonzalez

Reputation: 1879

You need to create a custom utility that Will call the capture exception method of Sentry. A solution could be to add this method to an ErrorBoundary, and attach the custom method inside the ErrorBoundary, Just take into account that the ErrorBoundary should be your parent Component.

Check a post of the Sentry team that refers to your doubt ErrorBoundary.

Error Boundary Docs

Upvotes: 4

Related Questions