Reporting Errors to Bug Tracking Service

I’ve battled with a good solution to this for a long time. Whilst many services offer a Node Express middleware tracking solution getting errors to report correctly is a challenge because of getting the errors to surface from Parse > Express > Node > Tracking (this is how it works in my head).

Since 3.x this has been a lot easier as to my mind there are actually some global express errors surfaced and therefore caught by the tracking software.

I am using Bugsnag (best price/quota and nice UI).

I’ve set this up as such:


const bugsnag = require('@bugsnag/js');
const bugsnagExpress = require('@bugsnag/plugin-express');
const bugsnagClient = bugsnag({
  apiKey: process.env.BUGSNAG_API_KEY,
  appVersion: pkg.version,
  appType: 'api-server',
  notifyReleaseStages: ['development', 'production'],
  releaseStage: rgEnvironment,
const bugsnagMiddleware = bugsnagClient.getPlugin('express');
  app.use(function (err, req, res, next) { // eslint-disable-line no-unused-vars
    const isDev = process.env.NODE_ENV === 'development' || process.env.RG_ENV === 'development';

    req.bugsnag.notify(extractError(err), {
      metaData: {
        version: pkg.version,
        serverId: process.env.SERVER_ID,
        node: process.version,

    res.status(err.status || 500);
      message: err.message,
      error: isDev
        ? err // development error handler will print stacktrace
        : {}, // production error handler, no stacktraces leaking

    // Bugsnag would log this here, but we capture it above so we can add metadata
    // next(new Error(err.message));

index.js (parse invocation)

// Final handler - Bugsnag. This handles any errors that Express catches

This all works fine… however, when trying to use something like this in one of my modules I am unable to pass in the bugsnagClient

See here:

This is what I would like to achieve. How can I get the bugsnagClient as a global throughout my parse cloud code?

Just to make sure that I understood what you need. Do you want to do something like req.bugsnag.notify(...); inside a cloud code function?

Exact that :point_up_2: @davimacedo

As we can see in this line of Parse Server, the original Express.js req is not passed to the cloud code functions. So I don’t think you will be able to do this in the current Parse Server implementation. I think you should open an issue for discussion in the Parse Server repo to possibly include the raw Express.js request object in the arguments when calling the cloud code functions.

Thanks @davimacedo, it’s possible to run another instance of Bugsnag within the cloud ode, I got that working in my testing, however it just feels a ‘little wrong’ to do that.

I’ll keep digging and open an issue if I don’t get anywhere.

1 Like

I am experiencing a similar problem, I want to be able to set the user and email like this every time the system crashes and I am not quite sure how to do it…
Do you did that? How did you implemented that?

I’d try to add a middleware after parse server like this. You will be able to access the req object then and the user object should be there.