Skip to content

[@sentry/node] Sentry.captureException + Lambda doesn't work #1727

@Andriy-Kulak

Description

@Andriy-Kulak

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,
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions