How to use raven

Comprehensive raven code examples:

How to use raven.install:

40
41
42
43
44
45
46
47
48
49
50
51
52
      });
    }


    raven.disableConsoleAlerts();


    raven.install();


    return BbPromise.resolve();
  });
}

How to use raven.transports:

115
116
117
118
119
120
121
                }
        };
}

module.exports.utils = raven.utils;
module.exports.transports = raven.transports;
module.exports.parsers = raven.parsers;

How to use raven.utils:

114
115
116
117
118
119
120
121
                        res && res.status(500).send({ type: 'Uncaught Error', error: error });
                }
        };
}

module.exports.utils = raven.utils;
module.exports.transports = raven.transports;
module.exports.parsers = raven.parsers;

How to use raven.on:

62
63
64
65
66
67
68
69
70
71
72
      user: {
        id: this.deviceHash,
      },
    });


    Raven.on('error', e => {
      console.log(`Raven: ${e.statusCode} - ${e.reason}`);
    });
  }
};

How to use raven.requestHandler:

31
32
33
34
35
36
37
38
39
40
 * Returns a Sentry request handler in case
 * Sentry client is set up.
 */
exports.requestHandler = () => {
  if (SENTRY_DSN) {
    return Raven.requestHandler();
  } else {
    return (req, res, next) => {
      next();
    };

How to use raven.send:

44
45
46
47
48
49
50
51
52
53
if (!raven.dsn) {
  log.info('Does not have global sentry');
  return;
}
ctx.event_id = raven.generateEventId();
raven.send(ctx, (publishErr) => {
  if (publishErr) {
    log.error('Failed to publish error into global sentry: %s', publishErr.message);
    return;
  }

How to use raven.generateEventId:

43
44
45
46
47
48
49
50
51
52
function notifySentryGlobal(ctx) {
  if (!raven.dsn) {
    log.info('Does not have global sentry');
    return;
  }
  ctx.event_id = raven.generateEventId();
  raven.send(ctx, (publishErr) => {
    if (publishErr) {
      log.error('Failed to publish error into global sentry: %s', publishErr.message);
      return;

How to use raven.context:

How to use raven.getContext:

219
220
221
222
223
224
225
226
227
 * @param {string} key
 * @param {object} value
 * @private
 */
static _mergeContext(key, value) {
  const context = Raven.getContext();
  if (!context[key]) {
    context[key] = {};
  }

How to use raven.parsers:

17
18
19
20
21
22
    }
    Raven.captureMessage(msg, meta);
  }
};

exports.parseRequest = Raven.parsers.parseRequest;

How to use raven.errorHandler:

45
46
47
48
49
50
51
52
53
54
 * Returns a Sentry error handler in case
 * Sentry client is set up.
 */
exports.errorHandler = () => {
  if (SENTRY_DSN) {
    return Raven.errorHandler();
  } else {
    return (err, req, res, next) => {
      next(err);
    };

How to use raven.disableConsoleAlerts:

23
24
25
26
27
28
29
30
31
32
    var options = {
        release: this.options.release,
        serverName: this.options.serverName
    };
    if (this.options.disableConsoleAlerts === true) {
        SentryLib.disableConsoleAlerts();
    }
    global.sentry = SentryLib.config(dsnPublic, reject(options)).install();
};

How to use raven.mergeContext:

How to use raven.captureMessage:

57
58
59
60
61
62
63
64
65
66
 * @param {string} message
 * @param {object} kwargs
 * @returns {Promise<unknown>}
 */
function captureMessage(message, kwargs) {
  return new Promise(res => Raven.captureMessage(message, kwargs, res));
}

/**
 * Sentry's implementation of wrap does not trow an exception

How to use raven.setContext:

12
13
14
15
16
17
18
19
20
21
22
23


function raven_report(e, context_opts) {
    if(process.env.SENTRY_DSN) {
        Raven.context(function () {
            if(context_opts) {
                Raven.setContext(context_opts);
            };


            Raven.captureException(e, (sendErr, event) => {
                if(sendErr) {

How to use raven.captureBreadcrumb:

193
194
195
196
197
198
199
200
201
202

We can capture breadcrumbs and associate them with a context, and then send them along with any errors captured from that context:

```javascript
Raven.context(function () {
  Raven.captureBreadcrumb({
    message: 'Received payment confirmation',
    category: 'payment',
    data: {
       amount: 312,

How to use raven.config:

19
20
21
22
23
24
25
26
27

const { ASSET_CACHE_DURATION } = process.env;
const MAX_ASSET_AGE = ASSET_CACHE_DURATION === 'Infinity' ? Infinity : 0;

if (USE_SENTRY) {
  Raven.config(SENTRY_DSN).install();
}

const app = express();

How to use raven.Client:

7
8
9
10
11
12
13
14
15

const log = require('../support/log');

raven.config();
raven.disableConsoleAlerts();
const globalSentryDSNClient = new raven.Client();
const cache = {};

ravenHTTPSTransport.agent = https.globalAgent;

How to use raven.captureException:

15
16
17
18
19
20
21
22
23
24
Raven.context(function () {
    if(context_opts) {
        Raven.setContext(context_opts);
    };

    Raven.captureException(e, (sendErr, event) => {
        if(sendErr) {
            console.log('error on log to sentry')
        } else {
            console.log('raven logged event', event);