Skip to content

Add abitlity to configure global extra #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var _Raven = window.Raven,
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
tags: {}
tags: {},
extra: {}
};

var TK = TraceKit.noConflict();
Expand Down Expand Up @@ -496,11 +497,13 @@ function send(data) {
'sentry.interfaces.Http': getHttpData()
}, data);

// Merge in the tags separately since arrayMerge doesn't handle a deep merge
// Merge in the tags and extra separately since arrayMerge doesn't handle a deep merge
data.tags = arrayMerge(globalOptions.tags, data.tags);
data.extra = arrayMerge(globalOptions.extra, data.extra);

// If there are no tags, strip the key from the payload alltogther.
// If there are no tags/extra, strip the key from the payload alltogther.
if (!data.tags) delete data.tags;
if (!data.extra) delete data.extra;

if (globalUser) data['sentry.interfaces.User'] = globalUser;

Expand Down
32 changes: 32 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,38 @@ describe('globals', function() {
}]);
});

it('should merge in global extra', function() {
this.sinon.stub(window, 'isSetup').returns(true);
this.sinon.stub(window, 'makeRequest');
this.sinon.stub(window, 'getHttpData').returns({
url: 'http://localhost/?a=b',
headers: {'User-Agent': 'lolbrowser'}
});

globalProject = 2;
globalOptions = {
logger: 'javascript',
site: 'THE BEST',
extra: {key1: 'value1'}
};


send({extra: {key2: 'value2'}});
assert.deepEqual(window.makeRequest.lastCall.args, [{
project: 2,
logger: 'javascript',
site: 'THE BEST',
platform: 'javascript',
'sentry.interfaces.Http': {
url: 'http://localhost/?a=b',
headers: {
'User-Agent': 'lolbrowser'
}
},
extra: {key1: 'value1', key2: 'value2'}
}]);
});

it('should let dataCallback override everything', function() {
this.sinon.stub(window, 'isSetup').returns(true);
this.sinon.stub(window, 'makeRequest');
Expand Down