Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

startWebTransaction not logging any data

nodeagent
integrations

#1

Hi,

I’m attempting to wrap all my lambdas in a ‘wrapper’ function which will record transactions in newrelic rather than repeating this code everywhere. Below is the code I’m using:

return NewRelic.startWebTransaction(`/serverless/${context.functionName}`, async () => {
    try {
      const response = await handler(event, context, callback)
      return response
    } catch (error) {
      context.exceptionHandler.captureException(error)

      logger.error({ msg: 'Something went wrong', error })

      return error
    } finally {
      NewRelic.endTransaction()
    }
  })

The problem is that the app isn’t even appearing in my newrelic account so no transactions can appear. As far as I can tell from the docs this should work.

I’ve also attempted telling newrelic that I will manually close the transaction by doing:

return NewRelic.startWebTransaction(`/serverless/${context.functionName}`, async () => {
    NewRelic.getTransaction()
    try {
      const response = await handler(event, context, callback)
      return response
    } catch (error) {
      context.exceptionHandler.captureException(error)

      logger.error({ msg: 'Something went wrong', error })

      return error
    } finally {
      NewRelic.endTransaction()
    }
  })

This doesn’t seem to work either. Any help would be greatly appreciated.

Thanks


#2

Hi, @richard.watkins: New Relic agents send their data once per minute; if your application does not run for at least a minute, it is likely the agent does not have a chance to send its data before the application terminates.

You might try calling the newrelic.shutdown() method with the collectPendingData option before the application ends, to tell the agent to send its data to the cloud.


#3

Hi,

I’ve tried adding your suggestion but it makes not difference. What would need to be returned from the try block in order to get the transaction to log or should it not make a difference? Should it return a promise? a callback?


#4

Hi there @richard.watkins - It looks like you are using lambda - in this case, I would suggest using the NodeJs Agent for Lambda. You may want to refer to the following documentation for how Lambda works with our Node Agent:

@philweber is right - since the agent sends data once per minute, we don’t have time to complete a harvest cycle before the agent is “frozen” by Lambda. Can you give the instructions outlined above a try and see if that helps?