Search code examples
javascriptloggingwebsentry

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;

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.