Sentry-javascript: how to using without sentry

Created on 21 Jul 2017  Â·  4Comments  Â·  Source: getsentry/sentry-javascript

I want to use not a sentry, but a graylog as a backend. But I can not figure out how to properly configure ravenjs to untie it from sentry.

You have the setTransport method and it looks like it is used for this.
But you do not have an example of use and documentation. Please help to understand, and provide a working example.

Most helpful comment

Ok, thanks for your reply. I already figured it out.
I will voice the solution for the descendants:
___PUBLIC_DSN___ is just a string with a certain format.
You can use the string username@servername/somepath as ___PUBLIC_DSN___.
It is important that the validator can properly parry it. Because otherwise it will not work, and an error will be thrown.

The finished example will look something like this:

import Raven from 'raven-js';
Raven.config('username@servername/somepath').install();
Raven.debug = true;

Raven.setTransport(function(data) {
    const messages = data.data.exception.values.reduce((memo, exception) => {
        var message = `${exception.type}: ${exception.value}`;
        var stack = exception.stacktrace.frames.reduce((acc, frame) => {
            acc += `\t${frame.function} (${frame.filename}:${frame.lineno}:${frame.colno})\n`;
            return acc;
        }, '');
        memo.push(message + '\n' + stack);
        return memo;
    }, []);

    const browserTime = (new Date).toISOString();

    fetch('http://localhost:1234/report', {
        method: 'post',
        body: JSON.stringify({
            messages,
            browserTime,
            sessionDuration: data.data.extra['session:duration'],

        }),
    })
        .then(data.onSuccess)
        .catch(data.onError);
});

Raven.setUserContext({
    email: '[email protected]',
    id: 5,
});

I took it from my project and did not check it, but you can always contact me here for clarification

Thank you for attention :-P

All 4 comments

I'd recommend looking at the source code.

Here's Raven's XHR transport. And here's what arguments it is passed.

but... is possible using without Sentry ?

@jt3k – I mean, sure. You can send the data elsewhere and log it with some other tool/service. But you're going to have to figure this out yourself.

Closing because this is a usage question and not an issue with Raven.js.

Ok, thanks for your reply. I already figured it out.
I will voice the solution for the descendants:
___PUBLIC_DSN___ is just a string with a certain format.
You can use the string username@servername/somepath as ___PUBLIC_DSN___.
It is important that the validator can properly parry it. Because otherwise it will not work, and an error will be thrown.

The finished example will look something like this:

import Raven from 'raven-js';
Raven.config('username@servername/somepath').install();
Raven.debug = true;

Raven.setTransport(function(data) {
    const messages = data.data.exception.values.reduce((memo, exception) => {
        var message = `${exception.type}: ${exception.value}`;
        var stack = exception.stacktrace.frames.reduce((acc, frame) => {
            acc += `\t${frame.function} (${frame.filename}:${frame.lineno}:${frame.colno})\n`;
            return acc;
        }, '');
        memo.push(message + '\n' + stack);
        return memo;
    }, []);

    const browserTime = (new Date).toISOString();

    fetch('http://localhost:1234/report', {
        method: 'post',
        body: JSON.stringify({
            messages,
            browserTime,
            sessionDuration: data.data.extra['session:duration'],

        }),
    })
        .then(data.onSuccess)
        .catch(data.onError);
});

Raven.setUserContext({
    email: '[email protected]',
    id: 5,
});

I took it from my project and did not check it, but you can always contact me here for clarification

Thank you for attention :-P

Was this page helpful?
0 / 5 - 0 ratings