question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sentry Express middleware and errorhandler not working with AWS Serverless Express

See original GitHub issue

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",

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilogorekcommented, Oct 15, 2018

@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.

1reaction
FredrikSeidlcommented, Oct 17, 2018

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling with aws-serverless-express - node.js
I am using aws-serverless-express to provide an AWS Lambda handler for my Express webservice. The Lambda works, however, I am not able to ......
Read more >
Sentry with AWS Lambda & Express - Integrations
Hey Guys, I've successfully integrated Sentry.io with my Express app on my local and I got it to report any issue.
Read more >
Express | Sentry Documentation
The error handler must be before any other error middleware and after all controllers app.use(Sentry.Handlers.errorHandler()); // Optional fallthrough error ...
Read more >
Lambda Error Logging With Sentry - Oliver Roick
Setting up Sentry error logging for a Lambda function is not as straightforward as, say, using a Django middleware. This post explores how ......
Read more >
How to use Middy to validate your serverless API requests
Middy is a very simple middleware engine that allows you to simplify your AWS Lambda code when using Node.js. It allows you to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found