File tree 3 files changed +28
-6
lines changed
3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 8
8
* DEPRECATED: Replace ` Raven.setReleaseContext ` with ` Raven.setRelease ` .
9
9
* NEW: Add ` Raven.clearContext() ` to empty all of the context.
10
10
* NEW: Add ` Raven.getContext() ` to get a copy of the current context.
11
+ * NEW: ` Raven.set{Extra,Tags}Context(ctx) ` now merges with existing values instead of overwriting.
11
12
12
13
## 1.1.22
13
14
Original file line number Diff line number Diff line change @@ -295,31 +295,40 @@ var Raven = {
295
295
* @return {Raven }
296
296
*/
297
297
setUserContext : function ( user ) {
298
+ // Intentionally do not merge here since that's an unexpected behavior.
298
299
globalContext . user = user ;
299
300
300
301
return Raven ;
301
302
} ,
302
303
303
304
/*
304
- * Set extra attributes to be sent along with the payload.
305
+ * Merge extra attributes to be sent along with the payload.
305
306
*
306
307
* @param {object } extra An object representing extra data [optional]
307
308
* @return {Raven }
308
309
*/
309
310
setExtraContext : function ( extra ) {
310
- globalContext . extra = extra || { } ;
311
+ if ( isUndefined ( extra ) ) {
312
+ delete globalContext . extra ;
313
+ } else {
314
+ globalContext . extra = objectMerge ( globalContext . extra || { } , extra ) ;
315
+ }
311
316
312
317
return Raven ;
313
318
} ,
314
319
315
320
/*
316
- * Set tags to be sent along with the payload.
321
+ * Merge tags to be sent along with the payload.
317
322
*
318
323
* @param {object } tags An object representing tags [optional]
319
324
* @return {Raven }
320
325
*/
321
326
setTagsContext : function ( tags ) {
322
- globalContext . tags = tags || { } ;
327
+ if ( isUndefined ( tags ) ) {
328
+ delete globalContext . tags ;
329
+ } else {
330
+ globalContext . tags = objectMerge ( globalContext . tags || { } , tags ) ;
331
+ }
323
332
324
333
return Raven ;
325
334
} ,
Original file line number Diff line number Diff line change @@ -1843,7 +1843,13 @@ describe('Raven (public API)', function() {
1843
1843
it ( 'should clear globalContext.extra with no arguments' , function ( ) {
1844
1844
globalOptions . extra = { name : 'Matt' } ;
1845
1845
Raven . setExtraContext ( ) ;
1846
- assert . deepEqual ( globalContext . extra , { } ) ;
1846
+ assert . isUndefined ( globalContext . extra ) ;
1847
+ } ) ;
1848
+
1849
+ it ( 'should merge globalContext.extra with subsequent calls' , function ( ) {
1850
+ Raven . setExtraContext ( { a : 1 } ) ;
1851
+ Raven . setExtraContext ( { b : 2 } ) ;
1852
+ assert . deepEqual ( globalContext . extra , { a : 1 , b : 2 } ) ;
1847
1853
} ) ;
1848
1854
} ) ;
1849
1855
@@ -1856,7 +1862,13 @@ describe('Raven (public API)', function() {
1856
1862
it ( 'should clear globalContext.tags with no arguments' , function ( ) {
1857
1863
globalContext . tags = { name : 'Matt' } ;
1858
1864
Raven . setTagsContext ( ) ;
1859
- assert . deepEqual ( globalContext . tags , { } ) ;
1865
+ assert . isUndefined ( globalContext . tags ) ;
1866
+ } ) ;
1867
+
1868
+ it ( 'should merge globalContext.tags with subsequent calls' , function ( ) {
1869
+ Raven . setTagsContext ( { a : 1 } ) ;
1870
+ Raven . setTagsContext ( { b : 2 } ) ;
1871
+ assert . deepEqual ( globalContext . tags , { a : 1 , b : 2 } ) ;
1860
1872
} ) ;
1861
1873
} ) ;
1862
1874
You can’t perform that action at this time.
0 commit comments