Home
Support Forums

How to you integrate Sentry with Netlify Functions?

Hey there,

I’ve got a Gatsby + Netlify site and would like to integrate Sentry to monitor lambda functions. I’m a little confused because I’ve seen a tutorial here and there where they use @sentry/node, but there’s also @sentry/serverless for AWS Lambda functions.

I know Netlify uses AWS under the hood for functions, so my assumption was to follow Sentry’s AWS Lambda integration docs.

However, when I follow their guide, no errors are being reported. I’m basically doing this

const Sentry = require("@sentry/serverless");

const {
  SENTRY_DSN
} = require('./config')

Sentry.AWSLambda.init({
  dsn: SENTRY_DSN,
  tracesSampleRate: 1.0,
});

exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  // ... some code here
  let someVariable
  try {
      someVariable = await someFetchRequest()

      throw new Error('this is a Sentry test error')
    } catch (err) {
      return statusReturn(500, { error: err.message })
    }
});

Yet, no issues are coming in. The docs say that this is all you need to start capturing error events within the handler.

Am I taking the wrong approach?

Thanks in advance

I haven’t used Sentry myself, though this issue here: Sentry.AWSLambda.init doesn't work with Netlify dev · Issue #3000 · getsentry/sentry-javascript · GitHub confirms that it should work fine.

Quoted:

It works great when deployed to Netlify, …

On a side note, the Sentry.AWSLambda.wrapHandler works fine with Netlify dev.

So it appears your approach is correct, but then I can’t say why it won’t work.

Thx @hrishikesh, I finally realized that it only automatically picks up errors that halt the execution of the handler.

I had some try/catch blocks inside that didn’t necessarily stop the execution of the entire function, so when I started using Sentry.captureException(error) errors got picked up.

Thanks for coming back and letting us know what you found, @proton! We appreciate it :netlisparkles:

1 Like