Skip to content

adding setContextsInterface #809

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/plugins/angular.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raven.js 3.9.1 (7bbae7d) | github.com/getsentry/raven-js */
/*! Raven.js 3.9.1 (79bc1ae) | github.com/getsentry/raven-js */

/*
* Includes TraceKit
Expand Down
2 changes: 1 addition & 1 deletion dist/plugins/angular.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/plugins/console.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raven.js 3.9.1 (7bbae7d) | github.com/getsentry/raven-js */
/*! Raven.js 3.9.1 (79bc1ae) | github.com/getsentry/raven-js */

/*
* Includes TraceKit
Expand Down
2 changes: 1 addition & 1 deletion dist/plugins/console.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/plugins/ember.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raven.js 3.9.1 (7bbae7d) | github.com/getsentry/raven-js */
/*! Raven.js 3.9.1 (79bc1ae) | github.com/getsentry/raven-js */

/*
* Includes TraceKit
Expand Down
2 changes: 1 addition & 1 deletion dist/plugins/ember.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/plugins/require.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raven.js 3.9.1 (7bbae7d) | github.com/getsentry/raven-js */
/*! Raven.js 3.9.1 (79bc1ae) | github.com/getsentry/raven-js */

/*
* Includes TraceKit
Expand Down
2 changes: 1 addition & 1 deletion dist/plugins/require.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/plugins/vue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raven.js 3.9.1 (7bbae7d) | github.com/getsentry/raven-js */
/*! Raven.js 3.9.1 (79bc1ae) | github.com/getsentry/raven-js */

/*
* Includes TraceKit
Expand Down
2 changes: 1 addition & 1 deletion dist/plugins/vue.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion dist/raven.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raven.js 3.9.1 (7bbae7d) | github.com/getsentry/raven-js */
/*! Raven.js 3.9.1 (79bc1ae) | github.com/getsentry/raven-js */

/*
* Includes TraceKit
Expand Down Expand Up @@ -548,6 +548,19 @@ Raven.prototype = {
return this;
},

/*
* Set/clear Contexts interface to be sent along with the payload.
*
* @param {object} contexts An object representing Contexts data [optional]
* @return {Raven}
*/
setContextsInterface: function(contexts) {
// Intentionally do not merge here since that's an unexpected behavior.
this._globalContext.contexts = contexts;

return this;
},

/*
* Merge extra attributes to be sent along with the payload.
*
Expand Down Expand Up @@ -1456,6 +1469,11 @@ Raven.prototype = {
data.user = this._globalContext.user;
}

if (this._globalContext.contexts) {
// sentry.interfaces.Contexts
data.contexts = this._globalContext.contexts;
}

// Include the environment if it's defined in globalOptions
if (globalOptions.environment) data.environment = globalOptions.environment;

Expand Down
4 changes: 2 additions & 2 deletions dist/raven.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/raven.min.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/sri.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"@dist/raven.js": {
"hashes": {
"sha256": "ihdEI9/hV9q/+yUm+WxgLgncmbFnuK9tr/lRnRgr60k=",
"sha512": "4WMClk7qzYHXT5/xR3X9RkpNs8dg/FIfbJ7RTythr9rXMRAVIDimD2X6NLEUdID+c7sJ3b6oOvsmf6oB0ORhwg=="
"sha256": "Zi62bVOegJu6xIbW0HEF0cnN1dPyT/Sg8igAgq1RHa8=",
"sha512": "K8RXJjVXwEoOtTCr0/PVGPiQzg3wMz8tZ4WgvP2FvpZw7SdHQLTUloJ7osCzUCo8XzdOxtKCZ37GnK+hmOQe6g=="
},
"type": null,
"integrity": "sha256-ihdEI9/hV9q/+yUm+WxgLgncmbFnuK9tr/lRnRgr60k= sha512-4WMClk7qzYHXT5/xR3X9RkpNs8dg/FIfbJ7RTythr9rXMRAVIDimD2X6NLEUdID+c7sJ3b6oOvsmf6oB0ORhwg==",
"integrity": "sha256-Zi62bVOegJu6xIbW0HEF0cnN1dPyT/Sg8igAgq1RHa8= sha512-K8RXJjVXwEoOtTCr0/PVGPiQzg3wMz8tZ4WgvP2FvpZw7SdHQLTUloJ7osCzUCo8XzdOxtKCZ37GnK+hmOQe6g==",
"path": "dist/raven.js"
},
"@dist/raven.min.js": {
"hashes": {
"sha256": "Iwsp4zEtQhPhOFbMNyTevyNpy7XTm8qUPteSJyopHDM=",
"sha512": "lL3X3M9f+DKT/mcKDJWixbXdXhVlYGWxy5DuPYyV6LrD8KNWQJ6ahpvTK3IyosXEAj3x+PWQ1DnFbKyGbIGdBw=="
"sha256": "hkHQD6hjsfVZYi6OvtQKv3ILDnLG8th+hJp2vU86a8k=",
"sha512": "EvQSBi66h4D4I1+MC6hs2ybi/PVMhQwXCyAKem5cWRCqVnP9hRkt66xdhN3Ia6TQN/dU/5u9okvXg5fAqq10ow=="
},
"type": null,
"integrity": "sha256-Iwsp4zEtQhPhOFbMNyTevyNpy7XTm8qUPteSJyopHDM= sha512-lL3X3M9f+DKT/mcKDJWixbXdXhVlYGWxy5DuPYyV6LrD8KNWQJ6ahpvTK3IyosXEAj3x+PWQ1DnFbKyGbIGdBw==",
"integrity": "sha256-hkHQD6hjsfVZYi6OvtQKv3ILDnLG8th+hJp2vU86a8k= sha512-EvQSBi66h4D4I1+MC6hs2ybi/PVMhQwXCyAKem5cWRCqVnP9hRkt66xdhN3Ia6TQN/dU/5u9okvXg5fAqq10ow==",
"path": "dist/raven.min.js"
}
}
18 changes: 18 additions & 0 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,19 @@ Raven.prototype = {
return this;
},

/*
* Set/clear Contexts interface to be sent along with the payload.
*
* @param {object} contexts An object representing Contexts data [optional]
* @return {Raven}
*/
setContextsInterface: function(contexts) {
// Intentionally do not merge here since that's an unexpected behavior.
this._globalContext.contexts = contexts;

return this;
},

/*
* Merge extra attributes to be sent along with the payload.
*
Expand Down Expand Up @@ -1362,6 +1375,11 @@ Raven.prototype = {
data.user = this._globalContext.user;
}

if (this._globalContext.contexts) {
// sentry.interfaces.Contexts
data.contexts = this._globalContext.contexts;
}

// Include the environment if it's defined in globalOptions
if (globalOptions.environment) data.environment = globalOptions.environment;

Expand Down
27 changes: 23 additions & 4 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ describe('Raven (public API)', function() {
describe('callback function', function() {
it('should callback a function if it is global', function() {
window.RavenConfig = {
dsn: "http://[email protected]:80/2",
dsn: 'http://[email protected]:80/2',
config: {some: 'config'}
};

Expand Down Expand Up @@ -1570,7 +1570,7 @@ describe('Raven (public API)', function() {
Raven.config('//[email protected]/2', {
whitelistUrls: [
/my.app/i,
"stringy.app"
'stringy.app'
]
});

Expand Down Expand Up @@ -1842,6 +1842,25 @@ describe('Raven (public API)', function() {
});
});

describe('.setContextsInterface', function() {
it('should set the globalContext.contexts object', function() {
Raven.setContextsInterface({device: {family: 'asus', type: 'device'}});
assert.deepEqual(Raven._globalContext.contexts, {device: {family: 'asus', type: 'device'}});
});

it('should not merge globalContext.device object, but rewrite', function () {
Raven._globalContext.contexts = {device: {family: 'asus', type: 'device'}};
Raven.setContextsInterface({os: {name: 'Android'}});
assert.deepEqual(Raven._globalContext.contexts, {os: {name: 'Android'}});
});

it('should clear the globalContext.device with no arguments', function() {
Raven._globalContext.contexts = {device: {family: 'asus', type: 'device'}};
Raven.setContextsInterface();
assert.isUndefined(Raven._globalContext.contexts);
});
});

describe('.setExtraContext', function() {
it('should set the globalContext.extra object', function() {
Raven.setExtraContext({name: 'Matt'});
Expand Down Expand Up @@ -2190,8 +2209,8 @@ describe('Raven (public API)', function() {

it('should capture custom errors that extend the Error prototype', function() {
function NotImplementedError(message) {
this.name = "NotImplementedError";
this.message = message || "";
this.name = 'NotImplementedError';
this.message = message || '';
}
NotImplementedError.prototype = Error.prototype;

Expand Down