Skip to content
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

Add Raven.setExtraContext and Raven.setTagsContext. #219

Merged
merged 1 commit into from
Jun 25, 2014
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
4 changes: 2 additions & 2 deletions docs/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ While a user is logged in, you can tell Sentry to associate errors with user dat

.. code-block:: javascript

Raven.setUser({
Raven.setUserContext({
email: 'matt@example.com',
id: '123'
})

If at any point, the user becomes unauthenticated, you can call ``Raven.setUser()`` with no arguments to remove their data. *This would only really be useful in a large web app where the user logs in/out without a page reload.*
If at any point, the user becomes unauthenticated, you can call ``Raven.setUserContext()`` with no arguments to remove their data. *This would only really be useful in a large web app where the user logs in/out without a page reload.*

Capturing a specific message
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//awesome
Raven.config('http://50dbe04cd1224d439e9c49bf1d0464df@localhost:8000/1').install();

Raven.setUser({
Raven.setUserContext({
email: 'matt@ydekproductions.com',
id: 5
})
Expand Down
28 changes: 27 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,36 @@ var Raven = {
* @param {object} user An object representing user data [optional]
* @return {Raven}
*/
setUser: function(user) {
setUserContext: function(user) {
globalUser = user;

return Raven;
},

/*
* Set extra attributes to be sent along with the payload.
*
* @param {object} extra An object representing extra data [optional]
* @return {Raven}
*/
setExtraContext: function(extra) {
globalOptions.extra = extra || {};

return Raven;
},

/*
* Set tags to be sent along with the payload.
*
* @param {object} tags An object representing tags [optional]
* @return {Raven}
*/
setTagsContext: function(tags) {
globalOptions.tags = tags || {};

return Raven;
},

/*
* Get the latest raw exception that was captured by Raven.
*
Expand All @@ -289,6 +313,8 @@ var Raven = {
}
};

Raven.setUser = Raven.setUserContext; // To be deprecated

function triggerEvent(eventType, options) {
var event, key;

Expand Down
32 changes: 29 additions & 3 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1361,19 +1361,45 @@ describe('Raven (public API)', function() {
});
});

describe('.setUser', function() {
describe('.setUserContext', function() {
it('should set the globalUser object', function() {
Raven.setUser({name: 'Matt'});
Raven.setUserContext({name: 'Matt'});
assert.deepEqual(globalUser, {name: 'Matt'});
});

it('should clear the globalUser with no arguments', function() {
globalUser = {name: 'Matt'};
Raven.setUser();
Raven.setUserContext();
assert.isUndefined(globalUser);
});
});

describe('.setExtraContext', function() {
it('should set the globalOptions.extra object', function() {
Raven.setExtraContext({name: 'Matt'});
assert.deepEqual(globalOptions.extra, {name: 'Matt'});
});

it('should clear globalOptions.extra with no arguments', function() {
globalOptions = {name: 'Matt'};
Raven.setExtraContext();
assert.deepEqual(globalOptions.extra, {});
});
});

describe('.setTagsContext', function() {
it('should set the globalOptions.tags object', function() {
Raven.setTagsContext({name: 'Matt'});
assert.deepEqual(globalOptions.tags, {name: 'Matt'});
});

it('should clear globalOptions.tags with no arguments', function() {
globalOptions = {name: 'Matt'};
Raven.setTagsContext();
assert.deepEqual(globalOptions.tags, {});
});
});

describe('.captureMessage', function() {
it('should work as advertised', function() {
this.sinon.stub(window, 'send');
Expand Down