Skip to content

Commit

Permalink
fix(instrumentation-aws-sdk): make empty context when SQS message has…
Browse files Browse the repository at this point in the history
… no propagation fields (#1889)

* fix(instrumentation-aws-sdk): make empty context when SQS message has no propagation fields

* style: lint fix

---------

Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
  • Loading branch information
zl4bv and blumamir committed Jan 13, 2024
1 parent c0d873c commit 577a291
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class ContextGetter
keys(
carrier: SQS.MessageBodyAttributeMap | SNS.MessageAttributeMap
): string[] {
if (carrier == null) {
return [];
}
return Object.keys(carrier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import { expect } from 'expect';
import {
MAX_MESSAGE_ATTRIBUTES,
contextGetter,
contextSetter,
injectPropagationContext,
addPropagationFieldsToAttributeNames,
} from '../src/services/MessageAttributes';
import { SNS, SQS } from '../src/aws-sdk.types';

describe('MessageAttributes', () => {
describe('MAX_MESSAGE_ATTRIBUTES', () => {
Expand All @@ -29,6 +31,30 @@ describe('MessageAttributes', () => {
});
});

describe('contextGetter', () => {
it('returns context keys if there are available attributes', () => {
const contextCarrier = {
key1: { DataType: 'String', StringValue: 'value1' },
};
const expectedKeys = ['key1'];

expect(contextGetter.keys(contextCarrier)).toEqual(expectedKeys);
});

it('returns empty context keys if there are no available attributes', () => {
const contextCarrier = undefined;
const expectedKeys: string[] = [];

expect(
contextGetter.keys(
contextCarrier as unknown as
| SQS.MessageBodyAttributeMap
| SNS.MessageAttributeMap
)
).toEqual(expectedKeys);
});
});

describe('contextSetter', () => {
it('should set parent context in sqs receive callback', () => {
const contextKey = 'key';
Expand Down

0 comments on commit 577a291

Please sign in to comment.