diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json index bd247c7676..05dd79d66e 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json @@ -52,11 +52,12 @@ "@opentelemetry/propagation-utils": "^0.27.0" }, "devDependencies": { - "@aws-sdk/client-dynamodb": "3.37.0", - "@aws-sdk/client-lambda": "3.37.0", - "@aws-sdk/client-s3": "3.37.0", - "@aws-sdk/client-sqs": "3.37.0", - "@aws-sdk/types": "3.37.0", + "@aws-sdk/client-dynamodb": "3.85.0", + "@aws-sdk/client-lambda": "3.85.0", + "@aws-sdk/client-s3": "3.85.0", + "@aws-sdk/client-sqs": "3.85.0", + "@aws-sdk/client-sns": "3.85.0", + "@aws-sdk/types": "3.78.0", "@opentelemetry/api": "1.0.1", "@opentelemetry/contrib-test-utils": "0.29.0", "@opentelemetry/sdk-trace-base": "1.2.0", diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sns-publish.xml b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sns-publish.xml new file mode 100644 index 0000000000..0a8091c8c7 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sns-publish.xml @@ -0,0 +1 @@ +90d1987b-4853-54ad-a499-c2d89c4edf3ad81e4f4f-2d70-51f3-a040-15ecf96d5a64 diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts index 2c2be487f7..a930dba4a1 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts @@ -21,7 +21,10 @@ import { const instrumentation = registerInstrumentationTesting( new AwsInstrumentation() ); -import * as AWS from 'aws-sdk'; +import * as AWSv2 from 'aws-sdk'; +import { SNS as SNSv3 } from '@aws-sdk/client-sns'; +import * as fs from 'fs'; +import * as nock from 'nock'; import { mockV2AwsSend } from './testing-utils'; import * as expect from 'expect'; @@ -41,9 +44,9 @@ const responseMockSuccess = { const topicName = 'topic'; const fakeARN = `arn:aws:sns:region:000000000:${topicName}`; -describe('SNS', () => { +describe('SNS - v2', () => { before(() => { - AWS.config.credentials = { + AWSv2.config.credentials = { accessKeyId: 'test key id', expired: false, expireTime: new Date(), @@ -60,7 +63,7 @@ describe('SNS', () => { describe('publish', () => { it('topic arn', async () => { - const sns = new AWS.SNS(); + const sns = new AWSv2.SNS(); await sns .publish({ @@ -91,7 +94,7 @@ describe('SNS', () => { }); it('phone number', async () => { - const sns = new AWS.SNS(); + const sns = new AWSv2.SNS(); const PhoneNumber = 'my phone number'; await sns .publish({ @@ -111,7 +114,7 @@ describe('SNS', () => { }); it('inject context propagation', async () => { - const sns = new AWS.SNS(); + const sns = new AWSv2.SNS(); const hookSpy = sinon.spy( (instrumentation['servicesExtensions'] as any)['services'].get('SNS'), 'requestPostSpanHook' @@ -136,7 +139,7 @@ describe('SNS', () => { describe('createTopic', () => { it('basic createTopic creates a valid span', async () => { - const sns = new AWS.SNS(); + const sns = new AWSv2.SNS(); const Name = 'my new topic'; await sns.createTopic({ Name }).promise(); @@ -160,3 +163,70 @@ describe('SNS', () => { }); }); }); + +describe('SNS - v3', () => { + let sns: any; + beforeEach(() => { + sns = new SNSv3({ + region: 'us-east-1', + credentials: { + accessKeyId: 'abcde', + secretAccessKey: 'abcde', + }, + }); + + nock('https://sns.us-east-1.amazonaws.com/') + .post('/') + .reply( + 200, + fs.readFileSync('./test/mock-responses/sns-publish.xml', 'utf8') + ); + }); + + describe('publish', () => { + it('topic arn', async () => { + const topicV3Name = 'dummy-sns-v3-topic'; + await sns.publish({ + Message: 'sns message', + TopicArn: `arn:aws:sns:us-east-1:000000000:${topicV3Name}`, + }); + + const publishSpans = getTestSpans().filter( + (s: ReadableSpan) => s.name === `${topicV3Name} send` + ); + expect(publishSpans.length).toBe(1); + + const publishSpan = publishSpans[0]; + expect( + publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] + ).toBe(MessagingDestinationKindValues.TOPIC); + expect( + publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] + ).toBe(topicV3Name); + expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe( + 'Publish' + ); + expect(publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toBe( + 'aws.sns' + ); + expect(publishSpan.kind).toBe(SpanKind.PRODUCER); + }); + + it('phone number', async () => { + const PhoneNumber = 'my phone number'; + await sns.publish({ + Message: 'sns message', + PhoneNumber, + }); + + const publishSpans = getTestSpans().filter( + (s: ReadableSpan) => s.name === 'phone_number send' + ); + expect(publishSpans.length).toBe(1); + const publishSpan = publishSpans[0]; + expect( + publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] + ).toBe(PhoneNumber); + }); + }); +});