Skip to content

Commit

Permalink
Merge pull request #15 from mattrobenolt/silent
Browse files Browse the repository at this point in the history
Tell Sentry to shut up, fixes #13 #14
  • Loading branch information
mattrobenolt committed Aug 14, 2012
2 parents 2803ab7 + 42dd98f commit 7b93584
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.4.0 - ...
* Silence and disable Raven/Sentry when using a non-existent or falsey DSN value

# 0.3.0 - 6/23/2012
* Separate transports out into their own module for portability
* Added UDP transport [Fixes #10]
Expand Down
7 changes: 5 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "raven",
"description": "A standalone (Node.js) client for Sentry",
"keywords": ["raven", "sentry", "python"],
"version": "0.3.0",
"version": "0.4.0-dev",
"repository": "git://github.com/mattrobenolt/raven-node.git",
"author": "Matt Robenolt <matt@ydekproductions.com>",
"license": "BSD",
Expand Down
28 changes: 28 additions & 0 deletions test/raven.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?$/);
Expand All @@ -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);
});

Expand Down Expand Up @@ -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);
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion test/raven.parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down
5 changes: 5 additions & 0 deletions test/raven.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 7b93584

Please sign in to comment.