How to use the setContext function from raven

Find comprehensive JavaScript raven.setContext code examples handpicked from public code repositorys.

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) {
fork icon38
star icon63
watch icon0

225
226
227
228
229
230
231
232
233
234
235
236
    if (!context[key]) {
      context[key] = {};
    }


    Object.assign(context[key], value);
    Raven.setContext(context);
  }


}

fork icon5
star icon3
watch icon0

+ 2 other calls in file

246
247
248
249
250
251
252
253
254
255
socket.emit('user', webUser);
socket.join('user:' + webUser._id);
socket.webUser = webUser;
// now have a user context and can work
if (process.env.SENTRY_DSN) {
  Raven.setContext({user: webUser});
}
// handlers
comments(socket, io, antiSpam, webpush);
question(socket, io, errorHandler);
fork icon2
star icon9
watch icon0

52
53
54
55
56
57
58
59
60
61
// eslint-disable-next-line max-statements
.use(async function attachUserToRequest(req, _res, next) {
  req.user = req.user || {}
  const token = req.headers['access-token']
  const { id: userId } = jwtDecode(token, { secret })
  raven.setContext({})
  try {
    raven.mergeContext({
      user: { id: userId },
      tags: {
fork icon3
star icon5
watch icon0

58
59
60
61
62
63
64
65
66
67
 * @param {Identify} identify
 */
Sentry.prototype.setContext = function (identify) {
    var traits = identify.traits();
    if (!global.sentry) {
        SentryLib.setContext(traits);
    }
    else {
        global.sentry.setContext(traits);
    }
fork icon0
star icon2
watch icon0

9
10
11
12
13
14
15
16
17
18
19
20
const nats = require('nats').connect(config.natsCfg);


const hemera = new Hemera(nats, config.hemeraCfg);


Raven.context(() => {
  Raven.setContext({
    extra: {
      serviceName: 'user-service',
    },
  });
fork icon2
star icon0
watch icon0

58
59
60
61
62
63
64
65
66
67
68
      };
      if (req.user) {
        Object.assign(user, _.pick(req.user, 'id', 'username'));
      }


      Raven.setContext({ user });
    }
    next();
  });
};
fork icon0
star icon0
watch icon0

31
32
33
34
35
36
37
38
39
40
    invocationId,
  },
});

if (config.userId) {
  raven.setContext({
    user: {
      id: config.userId,
    },
  });
fork icon0
star icon0
watch icon0