Skip to content

Commit 5e75116

Browse files
committed
Merge pull request #219 from DouweM/setextra-settags
Add Raven.setExtraContext and Raven.setTagsContext.
2 parents d264194 + 3144142 commit 5e75116

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

docs/usage/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ While a user is logged in, you can tell Sentry to associate errors with user dat
5858

5959
.. code-block:: javascript
6060
61-
Raven.setUser({
61+
Raven.setUserContext({
6262
email: 'matt@example.com',
6363
id: '123'
6464
})
6565
66-
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.*
66+
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.*
6767

6868
Capturing a specific message
6969
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//awesome
1515
Raven.config('http://50dbe04cd1224d439e9c49bf1d0464df@localhost:8000/1').install();
1616

17-
Raven.setUser({
17+
Raven.setUserContext({
1818
email: 'matt@ydekproductions.com',
1919
id: 5
2020
})

src/raven.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,36 @@ var Raven = {
264264
* @param {object} user An object representing user data [optional]
265265
* @return {Raven}
266266
*/
267-
setUser: function(user) {
267+
setUserContext: function(user) {
268268
globalUser = user;
269269

270270
return Raven;
271271
},
272272

273+
/*
274+
* Set extra attributes to be sent along with the payload.
275+
*
276+
* @param {object} extra An object representing extra data [optional]
277+
* @return {Raven}
278+
*/
279+
setExtraContext: function(extra) {
280+
globalOptions.extra = extra || {};
281+
282+
return Raven;
283+
},
284+
285+
/*
286+
* Set tags to be sent along with the payload.
287+
*
288+
* @param {object} tags An object representing tags [optional]
289+
* @return {Raven}
290+
*/
291+
setTagsContext: function(tags) {
292+
globalOptions.tags = tags || {};
293+
294+
return Raven;
295+
},
296+
273297
/*
274298
* Get the latest raw exception that was captured by Raven.
275299
*
@@ -289,6 +313,8 @@ var Raven = {
289313
}
290314
};
291315

316+
Raven.setUser = Raven.setUserContext; // To be deprecated
317+
292318
function triggerEvent(eventType, options) {
293319
var event, key;
294320

test/raven.test.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,19 +1361,45 @@ describe('Raven (public API)', function() {
13611361
});
13621362
});
13631363

1364-
describe('.setUser', function() {
1364+
describe('.setUserContext', function() {
13651365
it('should set the globalUser object', function() {
1366-
Raven.setUser({name: 'Matt'});
1366+
Raven.setUserContext({name: 'Matt'});
13671367
assert.deepEqual(globalUser, {name: 'Matt'});
13681368
});
13691369

13701370
it('should clear the globalUser with no arguments', function() {
13711371
globalUser = {name: 'Matt'};
1372-
Raven.setUser();
1372+
Raven.setUserContext();
13731373
assert.isUndefined(globalUser);
13741374
});
13751375
});
13761376

1377+
describe('.setExtraContext', function() {
1378+
it('should set the globalOptions.extra object', function() {
1379+
Raven.setExtraContext({name: 'Matt'});
1380+
assert.deepEqual(globalOptions.extra, {name: 'Matt'});
1381+
});
1382+
1383+
it('should clear globalOptions.extra with no arguments', function() {
1384+
globalOptions = {name: 'Matt'};
1385+
Raven.setExtraContext();
1386+
assert.deepEqual(globalOptions.extra, {});
1387+
});
1388+
});
1389+
1390+
describe('.setTagsContext', function() {
1391+
it('should set the globalOptions.tags object', function() {
1392+
Raven.setTagsContext({name: 'Matt'});
1393+
assert.deepEqual(globalOptions.tags, {name: 'Matt'});
1394+
});
1395+
1396+
it('should clear globalOptions.tags with no arguments', function() {
1397+
globalOptions = {name: 'Matt'};
1398+
Raven.setTagsContext();
1399+
assert.deepEqual(globalOptions.tags, {});
1400+
});
1401+
});
1402+
13771403
describe('.captureMessage', function() {
13781404
it('should work as advertised', function() {
13791405
this.sinon.stub(window, 'send');

0 commit comments

Comments
 (0)