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(aws-sdk): avoid repeating MessageAttributeNames in sqs receiveMessage #1044

Merged
merged 12 commits into from
Jun 10, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ export const extractPropagationContext = (
}
return undefined;
};

export const deduplicateMessageAttributeNames = (messageAttributeNames: string[]) => {
return Array.from(
new Set(messageAttributeNames)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
contextGetter,
extractPropagationContext,
injectPropagationContext,
deduplicateMessageAttributeNames
} from './MessageAttributes';

export class SqsServiceExtension implements ServiceExtension {
Expand Down Expand Up @@ -67,9 +68,13 @@ export class SqsServiceExtension implements ServiceExtension {
spanAttributes[SemanticAttributes.MESSAGING_OPERATION] =
MessagingOperationValues.RECEIVE;

request.commandInput.MessageAttributeNames = (
request.commandInput.MessageAttributeNames ?? []
).concat(propagation.fields());
const messageAttributeNames = request.commandInput.MessageAttributeNames ?
deduplicateMessageAttributeNames(request.commandInput.MessageAttributeNames) : [];

request.commandInput.MessageAttributeNames = [
...messageAttributeNames,
...propagation.fields()
blumamir marked this conversation as resolved.
Show resolved Hide resolved
];
}
blumamir marked this conversation as resolved.
Show resolved Hide resolved
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MAX_MESSAGE_ATTRIBUTES,
contextSetter,
injectPropagationContext,
deduplicateMessageAttributeNames
} from '../src/services/MessageAttributes';

describe('MessageAttributes', () => {
Expand Down Expand Up @@ -76,4 +77,11 @@ describe('MessageAttributes', () => {
expect(Object.keys(contextAttributes).length).toBe(10);
});
});

describe.only('deduplicateMessageAttributeNames', () => {
it('should remove duplicate message attribute names', () => {
const messageAttributeNames = ["name 1", "name 2", "name 1"];
expect(deduplicateMessageAttributeNames(messageAttributeNames)).toEqual(["name 1", "name 2"]);
})
});
});