Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-new-to-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
rauno56 authored May 10, 2022
2 parents 364bea7 + 0293d89 commit 69905a3
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"devDependencies": {
"@opentelemetry/api": "1.0.2",
"@opentelemetry/contrib-test-utils": "0.29.0",
"@opentelemetry/core": "1.2.0",
"@types/mocha": "8.2.3",
"@types/node": "16.11.21",
"@types/semver": "7.3.8",
Expand All @@ -59,6 +58,7 @@
"@opentelemetry/api": "^1.0.0"
},
"dependencies": {
"@opentelemetry/core": "^1.0.0",
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0",
"gcp-metadata": "^4.1.4",
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-fs/test/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type TestCreator = (
spans: any[]
) => void;

const TEST_CONTENTS = Buffer.from('hello, world\n');
const TEST_CONTENTS = Buffer.from('hello, world');
const ENOENT = /ENOENT: no such file or directory, /;
const tests: TestCase[] = [
[
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-fs/test/fixtures/readtest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hello, world
hello, world
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-fs/test/fixtures/writetest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hello, world
hello, world
11 changes: 6 additions & 5 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0"?><PublishResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/"><PublishResult><MessageId>90d1987b-4853-54ad-a499-c2d89c4edf3a</MessageId></PublishResult><ResponseMetadata><RequestId>d81e4f4f-2d70-51f3-a040-15ecf96d5a64</RequestId></ResponseMetadata></PublishResponse>
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(),
Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand All @@ -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'
Expand All @@ -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();
Expand All @@ -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);
});
});
});

0 comments on commit 69905a3

Please sign in to comment.