Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Silencing/disabling Sentry with a falsey DSN

Refs #14 #13
  • Loading branch information...
commit b145ee8527f33c59b35fd1f81420e0c4de76979f 1 parent 6425d42
@mattrobenolt mattrobenolt authored
View
7 lib/client.js
@@ -25,12 +25,15 @@ var Client = function Client(dsn, options) {
this.name = options.name || process.env.SENTRY_NAME || require('os').hostname();
this.site = options.site || process.env.SENTRY_SITE;
this.root = options.root || process.cwd();
- if(!process.env.NODE_ENV || !(process.env.NODE_ENV == 'production' || process.env.NODE_ENV == 'test')) {
- console.warn('Warning: Sentry logging is disabled, please set NODE_ENV=production');
+ if(!this.dsn || !process.env.NODE_ENV || !(process.env.NODE_ENV == 'production' || process.env.NODE_ENV == 'test')) {
this._enabled = false;
} else {
this._enabled = true;
}
+ if(this.dsn && !this._enabled) {
+ // we want to be silent only when FALSE is explicitly passed for a DSN value
+ console.warn('Warning: Sentry logging is disabled, please set NODE_ENV=production');
+ }
};
node_util.inherits(Client, events.EventEmitter);
var _ = Client.prototype;
View
4 lib/utils.js
@@ -32,6 +32,10 @@ module.exports.getAuthHeader = function getAuthHeader(signature, timestamp, api_
};
module.exports.parseDSN = function parseDSN(dsn) {
+ if(!dsn) {
+ // Let a falsey value return false explicitly
+ return false;
+ }
try {
var parsed = url.parse(dsn),
response = {
View
28 test/raven.client.js
@@ -5,6 +5,17 @@ var raven = require('../')
var dsn = 'https://public:private@app.getsentry.com/269';
+var _oldConsoleWarn = console.warn;
+function mockConsoleWarn() {
+ console.warn = function() {
+ console.warn._called = true;
+ };
+ console.warn._called = false;
+}
+function restoreConsoleWarn() {
+ console.warn = _oldConsoleWarn;
+}
+
describe('raven.version', function(){
it('should be valid', function(){
raven.version.should.match(/^\d+\.\d+\.\d+(-\w+)?$/);
@@ -19,6 +30,7 @@ describe('raven.version', function(){
describe('raven.Client', function(){
var client;
beforeEach(function(){
+ process.env.NODE_ENV='production';
client = new raven.Client(dsn);
});
@@ -71,6 +83,14 @@ describe('raven.Client', function(){
delete process.env.SENTRY_DSN; // gotta clean up so it doesn't leak into other tests
});
+ it('should be disabled when no DSN specified', function(){
+ mockConsoleWarn();
+ var client = new raven.Client();
+ client._enabled.should.eql(false);
+ console.warn._called.should.eql(false);
+ restoreConsoleWarn();
+ });
+
it('should pull SENTRY_NAME from environment', function(){
process.env.SENTRY_NAME='new_name';
var client = new raven.Client(dsn);
@@ -85,6 +105,14 @@ describe('raven.Client', function(){
delete process.env.SENTRY_SITE;
});
+ it('should be disabled for a falsey DSN', function(){
+ mockConsoleWarn();
+ var client = new raven.Client(false);
+ client._enabled.should.eql(false);
+ console.warn._called.should.eql(false);
+ restoreConsoleWarn();
+ });
+
describe('#getIdent()', function(){
it('should match', function(){
var result = {
View
2  test/raven.parsers.js
@@ -48,7 +48,7 @@ describe('raven.parsers', function(){
var parsed = raven.parsers.parseRequest(mockReq);
parsed.should.have.property('sentry.interfaces.Http');
parsed['sentry.interfaces.Http'].url.should.equal('https://mattrobenolt.com/some/path?key=value');
- parsed['sentry.interfaces.Http'].env.NODE_ENV.should.equal('test');
+ parsed['sentry.interfaces.Http'].env.NODE_ENV.should.equal('production');
});
});
View
5 test/raven.utils.js
@@ -64,6 +64,11 @@ describe('raven.utils', function() {
dsn.should.eql(expected);
});
+ it('should return false for a falsey dns', function(){
+ raven.utils.parseDSN(false).should.eql(false);
+ raven.utils.parseDSN('').should.eql(false);
+ });
+
it('should parse UDP DSN', function(){
var dsn = raven.utils.parseDSN('udp://8769c40cf49c4cc58b51fa45d8e2d166:296768aa91084e17b5ac02d3ad5bc7e7@mysentry.com:1234/some/other/path/269');
var expected = {

0 comments on commit b145ee8

Please sign in to comment.
Something went wrong with that request. Please try again.