Sentry-javascript: [@sentry/node] Sentry.captureException + Lambda doesn't work

Created on 11 Nov 2018  路  4Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [4.3.0 ] @sentry/node
  • [8.10.0] node

I am trying to have sentry work with AWS Lambda and I for some reason once lambda is deployed, I am only able to get sentry to send an error on the first time from AWS. Afterwards, it does not work. I am also using Serverless Framework to deploy the lambda but I am not sure how that would be the issue as it doesn't change the code. Below is my code:

'use strict'

const Sentry =  require('@sentry/node')
Sentry.init({
  dsn: 'xxx',
  environment: process.env.STAGE
});

module.exports.createPlaylist = async (event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = false
  if(!event.body) {
    Sentry.captureException(error)
    await new Promise(resolve => Sentry.getCurrentHub().getClient().close(2000).then(resolve))
    // also tried ==> await Sentry.getCurrentHub().getClient().close(2000)
    // also tried ==> await new Promise(resolve => {setTimeout(resolve, 2000)})
    return {
      statusCode: 500,
      headers: { 'Content-Type': 'text/plain' },
      body: 'Missing body parameters'
    }
  }
  return {
    statusCode: 200,
  }
};

Most helpful comment

All 4 comments

See #1449, related.

And the documentation at: https://docs.sentry.io/learn/draining/?platform=browser states that:

After shutdown the client cannot be used any more so make sure to only do that right before you shut down the application.

So calling:

Sentry.getCurrentHub().getClient().close(2000)

Prevents any other errors to be reported.

I would also know how to handle this case 馃憤

Related to https://github.com/getsentry/sentry-javascript/issues/1727
Let's keep the conversation there so it's easier to track everything. Thanks!

@kamilogorek the link to #1727 in your previous comment is just this issue.

Was this page helpful?
0 / 5 - 0 ratings