sentry-javascript: Sentry Express middleware and errorhandler not working with AWS Serverless Express

Raven errorhandler does not seem to capture the errors to Sentry when using it with AWS Serverless Express on AWS Lambda.

Following the sentry express example from https://docs.sentry.io/clients/node/integrations/express/ and then also the AWS Serverless Express example from https://github.com/awslabs/aws-serverless-express i get the following serverless handler.js file:

var app = require('express')();
var Raven = require('raven');
var awsServerlessExpress = require('aws-serverless-express')

// Must configure Raven before doing anything else with it
Raven.config(global.process.env.SENTRY_DSN).install();

// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());

app.get('/', function mainHandler(req, res) {
    throw new Error('Broke!');
});

// The error handler must be before any other error middleware
app.use(Raven.errorHandler());

const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);

Using:

"raven": "2.6.3",
"aws-serverless-express": "3.2.0",
"express": "4.16.3",

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@ondrowan thanks for the repro case, it’s very useful! We found out that the issue is with serverless wrapping everything in a domain, which we ourselves use in express middlewares (that’s why it works with just node handler.js). We are working on the fix as we speak.

From version 4 of sentry-node the captureException function no longer accepts a callback so the solution described above is no longer working. Do you have any plans to re-add this?