Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-sdk instrumentation - a "TypeError: _c.forEach is not a function" error is thrown for bad SQS.sendMessageBatch input #1975

Closed
harelmo-lumigo opened this issue Feb 28, 2024 · 1 comment · Fixed by #1999
Assignees
Labels
bug Something isn't working pkg:instrumentation-aws-sdk priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies

Comments

@harelmo-lumigo
Copy link

What version of OpenTelemetry are you using?

0.48.0

What version of Node are you using?

v18.17.1

What did you do?

I ran the following script:

const { AwsInstrumentation } = require('@opentelemetry/instrumentation-aws-sdk');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const AWS = require('aws-sdk');

registerInstrumentations({ instrumentations: [new AwsInstrumentation()] });

AWS.config.update({ region: 'us-west-2' });

const sqs = new AWS.SQS();

// A bad "Entries" object, should be an array
const Entries = { Key1: { MessageBody: 'This is the first message' } };

const params = {
  Entries,
  QueueUrl: "https://sqs.us-west-2.amazonaws.com/288057938227/harel-test-otel"
};

sqs.sendMessageBatch(params).promise().catch(console.error);

What did you expect to see?

An validation error pointing out that Entries should have been an array

What did you see instead?

The following error:

/my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/services/sqs.js:39
                        (_c = (_b = request.commandInput) === null || _b === void 0 ? void 0 : _b.Entries) === null || _c === void 0 ? void 0 : _c.forEach((messageParams) => {
                                                                                                                                                   ^

TypeError: _c.forEach is not a function
    at SqsServiceExtension.requestPostSpanHook (/my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/services/sqs.js:39:148)
    at ServicesExtensions.requestPostSpanHook (/my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/services/ServicesExtensions.js:28:33)
    at /my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/aws-sdk.js:344:41
    at NoopContextManager.with (/my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js:25:19)
    at ContextAPI.with (/my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/api/build/src/api/context.js:60:46)
    at Request.promise (/my-folder/aws-sdk-bug-repro/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/aws-sdk.js:343:51)
    at Object.<anonymous> (/my-folder/aws-sdk-bug-repro/1.js:17:30)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)

Additional context

@harelmo-lumigo harelmo-lumigo added the bug Something isn't working label Feb 28, 2024
@harelmo-lumigo harelmo-lumigo changed the title A "TypeError: _c.forEach is not a function" error is shown for bad Entries object when using the SQS client sendMessageBatch method aws-sdk instrumentation - A "TypeError: _c.forEach is not a function" error is thrown for bad SQS.sendMessageBatch input Feb 28, 2024
@harelmo-lumigo harelmo-lumigo changed the title aws-sdk instrumentation - A "TypeError: _c.forEach is not a function" error is thrown for bad SQS.sendMessageBatch input aws-sdk instrumentation - a "TypeError: _c.forEach is not a function" error is thrown for bad SQS.sendMessageBatch input Feb 28, 2024
@pichlermarc pichlermarc added up-for-grabs Good for taking. Extra help will be provided by maintainers priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies pkg:instrumentation-aws-sdk labels Mar 6, 2024
@pichlermarc
Copy link
Member

Looks like we're iterating over it without checking if it's an array first. Might need some more defensive logic.

@trentm trentm self-assigned this Mar 6, 2024
@trentm trentm removed the up-for-grabs Good for taking. Extra help will be provided by maintainers label Mar 6, 2024
trentm added a commit to trentm/opentelemetry-js-contrib that referenced this issue Mar 6, 2024
pichlermarc added a commit that referenced this issue Mar 7, 2024
…us SQS.sendMessageBatch input (#1999)

* fix(instr-aws-sdk): ensure that instrumentation does not crash on bogus SQS.sendMessageBatch input

Fixes: #1975

* force intentionally bogus sendMessageBatch params to pass type check

---------

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:instrumentation-aws-sdk priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies
Projects
None yet
3 participants