Skip to content

Commit

Permalink
fix(instr-aws-sdk): ensure that instrumentation does not crash on bog…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
trentm and pichlermarc committed Mar 7, 2024
1 parent 65a9553 commit fa7e2f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Expand Up @@ -110,13 +110,16 @@ export class SqsServiceExtension implements ServiceExtension {

case 'SendMessageBatch':
{
request.commandInput?.Entries?.forEach(
(messageParams: SQS.SendMessageBatchRequestEntry) => {
messageParams.MessageAttributes = injectPropagationContext(
messageParams.MessageAttributes ?? {}
);
}
);
const entries = request.commandInput?.Entries;
if (Array.isArray(entries)) {
entries.forEach(
(messageParams: SQS.SendMessageBatchRequestEntry) => {
messageParams.MessageAttributes = injectPropagationContext(
messageParams.MessageAttributes ?? {}
);
}
);
}
}
break;
}
Expand Down
Expand Up @@ -23,6 +23,7 @@ const instrumentation = registerInstrumentationTesting(
);
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';
import type { SQS } from 'aws-sdk';

import {
MessagingDestinationKindValues,
Expand Down Expand Up @@ -494,6 +495,29 @@ describe('SQS', () => {
expect(processSpans[0].status.code).toStrictEqual(SpanStatusCode.UNSET);
expect(processSpans[1].status.code).toStrictEqual(SpanStatusCode.UNSET);
});

it('bogus sendMessageBatch input should not crash', async () => {
const region = 'us-east-1';
const sqs = new AWS.SQS();
sqs.config.update({ region });

const QueueName = 'unittest';
const params = {
QueueUrl: `queue/url/for/${QueueName}`,
Entries: { Key1: { MessageBody: 'This is the first message' } },
};
await sqs
.sendMessageBatch(params as unknown as SQS.SendMessageBatchRequest)
.promise();

const spans = getTestSpans();
expect(spans.length).toBe(1);

// Spot check a single attribute as a sanity check.
expect(spans[0].attributes[SemanticAttributes.RPC_METHOD]).toEqual(
'SendMessageBatch'
);
});
});

describe('extract payload', () => {
Expand Down

0 comments on commit fa7e2f5

Please sign in to comment.