Skip to content

Commit

Permalink
Merge pull request #337 from rollbar/propagate-message
Browse files Browse the repository at this point in the history
[Fixes #336] Propagate message
  • Loading branch information
rokob authored Jul 14, 2017
2 parents c08ebbe + 1e1ae05 commit 292ea16
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 93 deletions.
4 changes: 3 additions & 1 deletion sdks/rollbar.js/src/browser/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var transport = require('./transport');
var urllib = require('./url');

var transforms = require('./transforms');
var sharedTransforms = require('../transforms');
var predicates = require('./predicates');
var errorParser = require('./errorParser');

Expand Down Expand Up @@ -310,9 +311,10 @@ function addTransformsToNotifier(notifier) {
.addTransform(transforms.addClientInfo(window))
.addTransform(transforms.addPluginInfo(window))
.addTransform(transforms.addBody)
.addTransform(sharedTransforms.addMessageWithError)
.addTransform(transforms.scrubPayload)
.addTransform(transforms.userTransform)
.addTransform(transforms.itemToPayload);
.addTransform(sharedTransforms.itemToPayload);
}

function addPredicatesToQueue(queue) {
Expand Down
18 changes: 2 additions & 16 deletions sdks/rollbar.js/src/browser/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function addBodyTrace(item, options, callback) {
};

if (description) {
trace.exception.description = description || 'uncaught exception';
trace.exception.description = description;
}

// Transform a TraceKit stackInfo object into a Rollbar trace
Expand Down Expand Up @@ -238,19 +238,6 @@ function userTransform(item, options, callback) {
callback(null, newItem);
}

function itemToPayload(item, options, callback) {
var payloadOptions = options.payload || {};
if (payloadOptions.body) {
delete payloadOptions.body;
}

var data = _.extend(true, {}, item.data, payloadOptions);
if (item._isUncaught) {
data._isUncaught = true;
}
callback(null, data);
}

module.exports = {
handleItemWithError: handleItemWithError,
ensureItemHasSomethingToSay: ensureItemHasSomethingToSay,
Expand All @@ -260,6 +247,5 @@ module.exports = {
addPluginInfo: addPluginInfo,
addBody: addBody,
scrubPayload: scrubPayload,
userTransform: userTransform,
itemToPayload: itemToPayload
userTransform: userTransform
};
4 changes: 3 additions & 1 deletion sdks/rollbar.js/src/server/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var urllib = require('url');
var jsonBackup = require('json-stringify-safe');

var transforms = require('./transforms');
var sharedTransforms = require('../transforms');
var predicates = require('./predicates');

function Rollbar(options, client) {
Expand Down Expand Up @@ -362,9 +363,10 @@ function addTransformsToNotifier(notifier) {
.addTransform(transforms.baseData)
.addTransform(transforms.handleItemWithError)
.addTransform(transforms.addBody)
.addTransform(sharedTransforms.addMessageWithError)
.addTransform(transforms.addRequestData)
.addTransform(transforms.scrubPayload)
.addTransform(transforms.convertToPayload);
.addTransform(sharedTransforms.itemToPayload);
}

function addPredicatesToQueue(queue) {
Expand Down
13 changes: 1 addition & 12 deletions sdks/rollbar.js/src/server/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ function scrubPayload(item, options, callback) {
callback(null, item);
}

function convertToPayload(item, options, callback) {
var payloadOptions = options.payload || {};
if (payloadOptions.body) {
delete payloadOptions.body;
}

var data = _.extend(true, {}, item.data, payloadOptions);
callback(null, data);
}

/** Helpers **/

function _buildTraceData(chain) {
Expand Down Expand Up @@ -231,7 +221,6 @@ module.exports = {
addMessageData: addMessageData,
addErrorData: addErrorData,
addRequestData: addRequestData,
scrubPayload: scrubPayload,
convertToPayload: convertToPayload
scrubPayload: scrubPayload
};

43 changes: 43 additions & 0 deletions sdks/rollbar.js/src/transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var _ = require('./utility');

function itemToPayload(item, options, callback) {
var payloadOptions = options.payload || {};
if (payloadOptions.body) {
delete payloadOptions.body;
}

var data = _.extend(true, {}, item.data, payloadOptions);
if (item._isUncaught) {
data._isUncaught = true;
}
callback(null, data);
}

function addMessageWithError(item, options, callback) {
if (!item.message) {
callback(null, item);
return;
}
var tracePath = 'data.body.trace_chain.0';
var trace = _.get(item, tracePath);
if (!trace) {
tracePath = 'data.body.trace';
trace = _.get(item, tracePath);
}
if (trace) {
if (!(trace.exception && trace.exception.description)) {
_.set(item, tracePath+'.exception.description', item.message);
callback(null, item);
return;
}
var extra = _.get(item, tracePath+'.extra') || {};
var newExtra = _.extend(true, {}, extra, {message: item.message});
_.set(item, tracePath+'.extra', newExtra);
}
callback(null, item);
}

module.exports = {
itemToPayload: itemToPayload,
addMessageWithError: addMessageWithError
};
30 changes: 0 additions & 30 deletions sdks/rollbar.js/test/browser.transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,36 +318,6 @@ describe('addBody', function() {
});
});

describe('itemToPayload', function() {
it('ignores options.payload.body but merges in other payload options', function(done) {
var args = ['a message', {custom: 'stuff'}];
var item = itemFromArgs(args);
item.accessToken = 'abc123';
var options = {
endpoint: 'api.rollbar.com',
payload: {body: 'hey', x: 42}
};
t.itemToPayload(item, options, function(e, i) {
expect(i.body).to.not.eql('hey');
expect(i.x).to.eql(42);
done(e);
});
});
it('ignores handles trailing slash in endpoint', function(done) {
var args = ['a message', {custom: 'stuff'}];
var item = itemFromArgs(args);
item.accessToken = 'abc123';
item.data = {message: 'a message'};
var options = {
endpoint: 'api.rollbar.com/'
};
t.itemToPayload(item, options, function(e, i) {
expect(i.message).to.eql('a message');
done(e);
});
});
});

describe('scrubPayload', function() {
it('only scrubs payload data', function(done) {
var args = ['a message', {scooby: 'doo', okay: 'fizz=buzz&fuzz=baz', user: {id: 42}}];
Expand Down
33 changes: 0 additions & 33 deletions sdks/rollbar.js/test/server.transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,37 +679,4 @@ vows.describe('transforms')
}
}
})
.addBatch({
'convertToPayload': {
'options': {
'with payload data': {
topic: function() {
return {payload: {client: {code_version: 'bork'}, body: 'hello'}};
},
item: {
topic: function(options) {
var item = {
data: {
body: {
message: 'hey'
}
},
other: 'thing'
};
t.convertToPayload(item, options, this.callback);
},
'should not error': function(err, item) {
assert.ifError(err);
},
'should only return data': function(err, item) {
assert.equal(item.body.message, 'hey');
},
'should include payload options': function(err, item) {
assert.equal(item.client.code_version, 'bork');
}
}
}
}
}
})
.export(module, {error: false});
42 changes: 42 additions & 0 deletions sdks/rollbar.js/test/transforms.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* globals expect */
/* globals describe */
/* globals it */

var _ = require('../src/utility');
var t = require('../src/transforms');

function itemFromArgs(args) {
var item = _.createItem(args);
item.level = 'debug';
return item;
}

describe('itemToPayload', function() {
it('ignores options.payload.body but merges in other payload options', function(done) {
var args = ['a message', {custom: 'stuff'}];
var item = itemFromArgs(args);
item.accessToken = 'abc123';
var options = {
endpoint: 'api.rollbar.com',
payload: {body: 'hey', x: 42}
};
t.itemToPayload(item, options, function(e, i) {
expect(i.body).to.not.eql('hey');
expect(i.x).to.eql(42);
done(e);
});
});
it('ignores handles trailing slash in endpoint', function(done) {
var args = ['a message', {custom: 'stuff'}];
var item = itemFromArgs(args);
item.accessToken = 'abc123';
item.data = {message: 'a message'};
var options = {
endpoint: 'api.rollbar.com/'
};
t.itemToPayload(item, options, function(e, i) {
expect(i.message).to.eql('a message');
done(e);
});
});
});

0 comments on commit 292ea16

Please sign in to comment.