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

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

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading