-
Notifications
You must be signed in to change notification settings - Fork 619
feat: Add AWS_SNS_TOPIC_ARN semantic convention support for AWS SNS SDK #2885
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
Changes from 2 commits
c3056eb
696bbb7
bab4cfa
3665bc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0"?> | ||
| <CreateTopicResponse xmlns="https://sns.amazonaws.com/doc/2010-03-31/"> | ||
| <CreateTopicResult> | ||
| <TopicArn>arn:aws:sns:us-east-1:123456789012:sns-topic-foo</TopicArn> | ||
| </CreateTopicResult> | ||
| <ResponseMetadata> | ||
| <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId> | ||
| </ResponseMetadata> | ||
| </CreateTopicResponse> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,28 +27,30 @@ import { | |
| SEMATTRS_MESSAGING_SYSTEM, | ||
| SEMATTRS_RPC_METHOD, | ||
| } from '@opentelemetry/semantic-conventions'; | ||
| import { ATTR_AWS_SNS_TOPIC_ARN } from '@opentelemetry/semantic-conventions/incubating'; | ||
| import { SpanKind } from '@opentelemetry/api'; | ||
|
|
||
| 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', () => { | ||
| 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') | ||
| ); | ||
| }); | ||
|
|
||
| it('topic arn', async () => { | ||
| const topicV3Name = 'dummy-sns-v3-topic'; | ||
| const topicV3ARN = `arn:aws:sns:us-east-1:000000000:${topicV3Name}`; | ||
|
|
@@ -73,6 +75,7 @@ describe('SNS - v3', () => { | |
| expect(publishSpan.attributes['messaging.destination.name']).toBe( | ||
| topicV3ARN | ||
| ); | ||
| expect(publishSpan.attributes[ATTR_AWS_SNS_TOPIC_ARN]).toBe(topicV3ARN); | ||
| expect(publishSpan.attributes[SEMATTRS_RPC_METHOD]).toBe('Publish'); | ||
| expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toBe('aws.sns'); | ||
| expect(publishSpan.kind).toBe(SpanKind.PRODUCER); | ||
|
|
@@ -93,6 +96,41 @@ describe('SNS - v3', () => { | |
| expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toBe( | ||
| PhoneNumber | ||
| ); | ||
| expect(publishSpan.attributes[ATTR_AWS_SNS_TOPIC_ARN]).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Create Topic', () => { | ||
| 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-create-topic.xml', 'utf8') | ||
| ); | ||
| }); | ||
|
|
||
| it('should create topic ARN and capture expected trace attributes', async () => { | ||
| const topicName = 'sns-topic-foo'; | ||
| const topicArn = `arn:aws:sns:us-east-1:123456789012:${topicName}`; | ||
| await sns.createTopic({ | ||
| Name: topicName, | ||
| }); | ||
| const publishSpans = getTestSpans().filter( | ||
| (s: ReadableSpan) => s.name === 'SNS CreateTopic' | ||
| ); | ||
|
||
| expect(publishSpans.length).toBe(1); | ||
| const publishSpan = publishSpans[0]; | ||
| expect(publishSpan.attributes[ATTR_AWS_SNS_TOPIC_ARN]).toBe(topicArn); | ||
| expect(publishSpan.kind).toBe(SpanKind.CLIENT); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: copying also the docs would give more info to other contributors if they happen to work with this instrumentation. It also will reflect the
experiementalstatus of the attribute in the IDEThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, copying the docs is usually preferred.