Sentry-javascript: Re-configuring the client / Changing DSN on the run

Created on 29 Oct 2014  路  8Comments  路  Source: getsentry/sentry-javascript

Short version: Is there a way to change dsn after the initial configuration?

Long version: I am building a cordova/angularjs mobile app and trying to integrate raven-js into it. My use case is that the user will login to one of many servers. Server passes the dsn info on login, and dsn depends on the server that user is connecting to. They can then logout, and login to a different server. Hence, I need to be able to change dsn information on the run. Is this currently possible? I found this pr https://github.com/getsentry/raven-js/pull/233 which seems to explicitly disable this behavior. I am coming from native app development, and am a noob when it comes to js. Is there something obvious I am missing here?

Thanks.

Most helpful comment

A related question I'll ask here to avoid a new issue.

Is it supported to change other config options after the initial config? In particular I want to change serverName as for various reasons that data isn't known at first when we call Raven.config()

Something like

Raven.config(initialConfig);

// later
Raven.config({ serverName: 'foobar'}); // re-config

I'm tempted to use Raven._globalOptions.

All 8 comments

Can you not just call Raven.uninstall(), then Raven.config(...).install() again?

You could actually just chain all of those and I assume it'd work. I've never tested this though.

Raven.uninstall().config(...).install() should do what you're asking for.

Calling Raven.uninstall() does not really work since it does not clear all the global variables that Raven.config() sets up such as globalServer, globalOptions etc. My workaround is manually clearing them in Raven.uninstall() by modifying it the following way:

uninstall: function() {
        TraceKit.report.uninstall();
        isRavenInstalled = false;
        globalServer = undefined;
        globalUser = undefined;
        globalKey = undefined;
        globalProject = undefined;
        globalOptions = {
            logger: 'javascript',
            ignoreErrors: [],
            ignoreUrls: [],
            whitelistUrls: [],
            includePaths: [],
            collectWindowErrors: true,
            tags: {},
            extra: {}
        };
        authQueryString = undefined;
        return Raven;
    }

Would this be the ideal way?

Ah, I see. Yeah, we'd have to effectively have a reset() to reset the state back to original.

+1, we are testing our internal Sentry server and would like to send the same exception to several Sentry servers as backup. It would be nice if the Raven clients did not share global data!

I've given this the 2.0 milestone so we can solve this in a way that makes sense there.

A related question I'll ask here to avoid a new issue.

Is it supported to change other config options after the initial config? In particular I want to change serverName as for various reasons that data isn't known at first when we call Raven.config()

Something like

Raven.config(initialConfig);

// later
Raven.config({ serverName: 'foobar'}); // re-config

I'm tempted to use Raven._globalOptions.

There is now Raven.setDSN that lets you change the DSN mid-page.

Was this page helpful?
0 / 5 - 0 ratings