elastic / apm-agent-nodejs

https://www.elastic.co/guide/en/apm/agent/nodejs/current/index.html
BSD 2-Clause "Simplified" License
582 stars 224 forks source link

recent addition of aws sqs instrumentation causing runtime failures when enabled #3746

Closed peterabbott closed 10 months ago

peterabbott commented 10 months ago

Describe the bug

To Reproduce

Using 4.1.0 of the agent. When publishing usign the SQS client and APM enabled, without any modifications.

Getting error following error. Not been able to get nested error out yet.

Error: Cannot convert undefined or null to object

The only different between the versions 4.0.0 and 4.1.0 is the introduction of aws-sqs instrumentation. Will post more details if we get anything out of the nested error. For now we can disable aws instrumentations to avoid renovate doignan auto bump again and breaking things.

Expected behavior

Environment (please complete the following information)

How are you starting the agent? (please tick one of the boxes)

Additional context

Agent config options:

Click to expand ``` { ...baseConfig, // leaving these in to support using with lambda-executor for local testing serviceName: appName, active: process.env.NODE_ENV === 'production', disableInstrumentations: [], environment: environment + '-' + zone, globalLabels: { deployEnvironment: environment, zoneName: zone, serviceName: appName } } ```

package.json dependencies:

Click to expand ``` "elastic-apm-node": "4.1.0" ```
peterabbott commented 10 months ago

Guess it was not picked up in testing because of this one https://github.com/elastic/apm-agent-nodejs/issues/3719

peterabbott commented 10 months ago

Managed to recreate locally with out test harness. It is this line here does not take into account that that message attributes might be undefined. The AWS type has it optional

 error: TypeError: Cannot convert undefined or null to object
      at Function.keys (<anonymous>)
      at  /XXXXXXXXXXX/elastic-apm-node/lib/instrumentation/modules/@aws-sdk/client-sqs.js:72:39
david-luna commented 10 months ago

Hi @peterabbott

Thanks for reporting the issue and provide a diagnose :)

The instrumentation is checking for MessageAttributes being defined on SendMessage command

if (commandName === 'SendMessage' && input.MessageAttributes)

For SendMessageBatch command is checking that Entries property is an array but not that the items inside are defined so I think this is where undefineds are coming from.

I'll start working with the fix today

david-luna commented 10 months ago

@peterabbott fix is available in latest release (v4.2.0). Thanks again for filing the issue :)