Skip to content

Commit 29c1504

Browse files
committed
Add dataCallback option
1 parent 74b70b0 commit 29c1504

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ client = new raven.Client('{{ SENTRY_DSN }}', {
198198
});
199199
```
200200

201+
## Pre-processing data
202+
Pass the `dataCallback` configuration value:
203+
204+
```javascript
205+
client = new raven.Client('{{ SENTRY_DSN }}', {
206+
dataCallback: function(data) {
207+
delete data.request.env;
208+
return data;
209+
}
210+
});
211+
```
212+
201213
## Disable Raven
202214
Pass `false` as the DSN (or any falsey value).
203215

lib/client.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var Client = function Client(dsn, options) {
3030
this.transport = options.transport || transports[this.dsn.protocol];
3131

3232
this.loggerName = options.logger || '';
33+
this.dataCallback = options.dataCallback || null;
3334

3435
// enabled if a dsn is set
3536
this._enabled = !!this.dsn;
@@ -61,6 +62,10 @@ _.process = function process(kwargs) {
6162

6263
var ident = {'id': kwargs['event_id']};
6364

65+
if (this.dataCallback) {
66+
kwargs = this.dataCallback(kwargs);
67+
}
68+
6469
// this will happen asynchronously. We don't care about it's response.
6570
this._enabled && this.send(kwargs, ident);
6671

test/raven.client.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,40 @@ describe('raven.Client', function(){
297297
});
298298
});
299299

300+
describe('#process()', function(){
301+
it('should respect dataCallback', function(){
302+
var scope = nock('https://app.getsentry.com')
303+
.filteringRequestBody(/.*/, '*')
304+
.post('/api/store/', '*')
305+
.reply(200, function(uri, body) {
306+
zlib.inflate(new Buffer(body, 'base64'), function(err, dec) {
307+
if (err) return done(err);
308+
var msg = JSON.parse(dec.toString());
309+
var extra = msg.extra;
310+
311+
extra.should.not.have.property('foo');
312+
});
313+
return 'OK';
314+
});
315+
316+
var client = new raven.Client(dsn, {
317+
dataCallback: function(data){
318+
delete data.extra.foo;
319+
return data;
320+
}
321+
});
322+
323+
client.process({
324+
message: 'test',
325+
extra: {foo: 'bar'}
326+
});
327+
328+
client.on('logged', function(){
329+
scope.done();
330+
});
331+
});
332+
});
333+
300334
it('should use a custom transport', function(){
301335
var expected = {
302336
protocol: 'udp',

0 commit comments

Comments
 (0)