Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I log everything with sentry/raven-js

I'm working on an existing project, with a lot of webpages. My task is to introduce logging og client script errors, usingsentr/raven-js.

In the docs, it says that i need to wrap the functions that I need to track in try/catch blocks - this is familiar to me, since I usually work in C#. But I don't wat to edit alle pages to wrap ALL javascript functions in try/catch. Is there a way to log ALL errors?

I tried something with window.onError = Raven.process, but I didn't get any logentries.

Can someone show me a what I'm missing? My setup is this:

var options = {
    logger: 'my-test-logger',
    whitelistUrls: [
        /localhost/,
        /localhost:2109/
    ]
};
Raven.config('https://<public-key-removed>@app.getsentry.com/<project-key-removed>', options).install();
window.onerror = Raven.process;
like image 267
jand187 Avatar asked Feb 04 '14 08:02

jand187


People also ask

How does sentry work on JavaScript?

js is the official browser JavaScript client for Sentry. It automatically reports uncaught JavaScript exceptions triggered from a browser environment, and provides a rich API for reporting your own errors.

What is https ingest Sentry io?

Sentry.io is a SaaS error tracker, used by multiple websites to report broken JavaScript behaviour.

What is Raven min js?

Raven. js is a tiny standalone JavaScript client for Sentry. It can be used to report errors from a web browser. The quality of reporting will heavily depend on the environment the data is submitted from.


2 Answers

My setup was correct, except for the line:

window.onerror = Raven.process

For some reason I couldn't provoke any error to fire the logging event, but once I managed to simulate a real error, the logging worked just fine. The line:

Raven.config('https://@app.getsentry.com/', options).install();

does catch all errors.

like image 57
jand187 Avatar answered Sep 17 '22 23:09

jand187


It is important to realize that raven does not capture errors you trigger with the console. You need to put some error generating code directly in the page, or do something like this from the console:

window.setTimeout(function(){ foo() });

Also, i think that doing:

window.onerror = Raven.process

Is unnecessary, Raven already does that for you, in a much more advanced way.

like image 42
deweydb Avatar answered Sep 20 '22 23:09

deweydb