Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Add a "silent" option for test/development #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/client.js
Expand Up @@ -21,12 +21,14 @@ var Client = function Client(dsn, options) {
dsn = process.env.SENTRY_DSN;
}
options = options || {};
this.dsn = utils.parseDSN(dsn);
this.dsn = utils.parseDSN(dsn, options.silent) || {};
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 (!options.silent) {
console.warn('Warning: Sentry logging is disabled, please set NODE_ENV=production');
}
this._enabled = false;
} else {
this._enabled = true;
Expand Down Expand Up @@ -61,7 +63,7 @@ _.process = function process(kwargs) {
kwargs['timestamp'] = new Date().toISOString().split('.')[0];
kwargs['project'] = this.dsn.project_id;
kwargs['site'] = kwargs['site'] || this.site;

// this will happen asynchronously. We don't care about it's response.
this._enabled && this.send(kwargs);

Expand Down
10 changes: 6 additions & 4 deletions lib/utils.js
Expand Up @@ -31,7 +31,7 @@ module.exports.getAuthHeader = function getAuthHeader(signature, timestamp, api_
return header.join(', ');
};

module.exports.parseDSN = function parseDSN(dsn) {
module.exports.parseDSN = function parseDSN(dsn, silent) {
try {
var parsed = url.parse(dsn),
response = {
Expand All @@ -54,7 +54,9 @@ module.exports.parseDSN = function parseDSN(dsn) {
response.port = ~~parsed.port || protocolMap[response.protocol] || 443;
return response;
} catch(e) {
throw new Error('Invalid Sentry DSN: ' + dsn);
if (!silent) {
throw new Error('Invalid Sentry DSN: ' + dsn);
}
}
};

Expand Down Expand Up @@ -91,7 +93,7 @@ module.exports.parseStackBetter = function parseStackBetter(err, cb) {
//Error.captureStackTrace(err);
var lines = err.stack;
Error.prepareStackTrace = orig;

lines.forEach(function(line, index){
var frame = {
function: line.getFunctionName(),
Expand All @@ -118,7 +120,7 @@ module.exports.parseStack = function parseStack(stack, cb) {
callbacks=lines.length,
frames=[],
cache={};

if(lines.length === 0) {
throw new Error('No lines to parse!');
}
Expand Down
4 changes: 4 additions & 0 deletions test/raven.client.js
Expand Up @@ -85,6 +85,10 @@ describe('raven.Client', function(){
delete process.env.SENTRY_SITE;
});

it('should survive in silent mode with missing DSN', function() {
var client = new raven.Client(undefined, { silent: true });
});

describe('#getIdent()', function(){
it('should match', function(){
var result = {
Expand Down