Question

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;
Was it helpful?

Solution

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.

OTHER TIPS

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.

Try the following code to disable logs from raven.js

Raven.config('your dsn', {
  autoBreadcrumbs: {
    console: false
  }
});

Raven will from version 1 log all window.onerror errors by default.

See https://raven-js.readthedocs.org/en/latest/config/index.html#collectwindowerrors

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top