Disabling Sentry/Raven for localhost in Angular

Preventing Sentry making requests on localhost

Posted on June 19, 2017

You can prevent Sentry logging errors by blacklisting localhost from within the Sentry admin area. Despite this your local dev environment will still try and post errors will which fail. I’ve prevented these requests locally by adding a simple conditional checking for localhost in window.location.href.

I’m yet to find a nicer way of doing this so let me know if you’ve found a way in the raven config.

if ( !window.location.href.indexOf( 'localhost' ) ) {
	Raven
		.config( 'https://3dd6a04eaf6c46ba8410edcf0a85f154@sentry.io/161185', {
			ignoreUrls: [ 'http://localhost:4200/' ]
		} )
		.install();
}