@@ -40,6 +40,7 @@ extend(Raven.prototype, {
40
40
41
41
this . loggerName = options . logger || '' ;
42
42
this . dataCallback = options . dataCallback ;
43
+ this . shouldSendCallback = options . shouldSendCallback ;
43
44
44
45
if ( ! this . dsn ) {
45
46
utils . consoleAlert ( 'no DSN provided, error reporting disabled' ) ;
@@ -115,12 +116,18 @@ extend(Raven.prototype, {
115
116
kwargs = this . dataCallback ( kwargs ) ;
116
117
}
117
118
118
- if ( this . _enabled ) {
119
+ var shouldSend = true ;
120
+ if ( ! this . _enabled ) shouldSend = false ;
121
+ if ( this . shouldSendCallback && ! this . shouldSendCallback ( ) ) shouldSend = false ;
122
+
123
+ if ( shouldSend ) {
119
124
this . send ( kwargs , cb ) ;
120
125
} else {
121
- setImmediate ( function ( ) {
126
+ // wish there was a good way to communicate to cb why we didn't send; worth considering cb api change?
127
+ // avoiding setImmediate here because node 0.8
128
+ setTimeout ( function ( ) {
122
129
cb ( null , eventId ) ;
123
- } ) ;
130
+ } , 0 ) ;
124
131
}
125
132
} ,
126
133
@@ -310,6 +317,41 @@ extend(Raven.prototype, {
310
317
utils . consoleAlert ( 'setTagsContext has been deprecated and will be removed in v2.0' ) ;
311
318
this . _globalContext . tags = extend ( { } , this . _globalContext . tags , tags ) ;
312
319
return this ;
320
+ } ,
321
+
322
+ setCallbackHelper : function ( propertyName , callback ) {
323
+ var original = this [ propertyName ] ;
324
+ if ( typeof callback === 'function' ) {
325
+ this [ propertyName ] = function ( data ) {
326
+ return callback ( data , original ) ;
327
+ } ;
328
+ } else {
329
+ this [ propertyName ] = callback ;
330
+ }
331
+
332
+ return this ;
333
+ } ,
334
+
335
+ /*
336
+ * Set the dataCallback option
337
+ *
338
+ * @param {function } callback The callback to run which allows the
339
+ * data blob to be mutated before sending
340
+ * @return {Raven }
341
+ */
342
+ setDataCallback : function ( callback ) {
343
+ return this . setCallbackHelper ( 'dataCallback' , callback ) ;
344
+ } ,
345
+
346
+ /*
347
+ * Set the shouldSendCallback option
348
+ *
349
+ * @param {function } callback The callback to run which allows
350
+ * introspecting the blob before sending
351
+ * @return {Raven }
352
+ */
353
+ setShouldSendCallback : function ( callback ) {
354
+ return this . setCallbackHelper ( 'shouldSendCallback' , callback ) ;
313
355
}
314
356
} ) ;
315
357
0 commit comments