Skip to content

Commit

Permalink
feat(instrumentation-aws-sdk)!: Capture full ARN for span attribute m…
Browse files Browse the repository at this point in the history
…essaging.destination.name for SNS topics (#1727)

* Capture full ARN for SNS topics in messaging.destination

Problem:
The use of topic names instead of ARNs in `messaging.destination` omits
essential account information, making topic localization cumbersome.

Solution:
Adopt full ARNs as the value for `messaging.destination`, preserving both
topic name and account details, aligning with current SNS ServiceExtension
approach.

Closes #1716

* Add new span attribute instead of modifying the existing attribute

---------

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
  • Loading branch information
alingamn and pichlermarc committed Nov 13, 2023
1 parent 607d375 commit 28ea3b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class SnsServiceExtension implements ServiceExtension {
const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;
spanAttributes[SemanticAttributes.MESSAGING_DESTINATION] =
this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);
// ToDO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when implemented
spanAttributes['messaging.destination.name'] =
TopicArn || TargetArn || PhoneNumber || 'unknown';

spanName = `${
PhoneNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ describe('SNS - v2', () => {
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(topicName);
expect(publishSpan.attributes['messaging.destination.name']).toBe(
fakeARN
);
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
'Publish'
);
Expand Down Expand Up @@ -111,6 +114,9 @@ describe('SNS - v2', () => {
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(PhoneNumber);
expect(publishSpan.attributes['messaging.destination.name']).toBe(
PhoneNumber
);
});

it('inject context propagation', async () => {
Expand Down Expand Up @@ -159,6 +165,9 @@ describe('SNS - v2', () => {
expect(
createTopicSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBeUndefined();
expect(
createTopicSpan.attributes['messaging.destination.name']
).toBeUndefined();
expect(createTopicSpan.kind).toBe(SpanKind.CLIENT);
});
});
Expand Down Expand Up @@ -186,9 +195,11 @@ describe('SNS - v3', () => {
describe('publish', () => {
it('topic arn', async () => {
const topicV3Name = 'dummy-sns-v3-topic';
const topicV3ARN = `arn:aws:sns:us-east-1:000000000:${topicV3Name}`;

await sns.publish({
Message: 'sns message',
TopicArn: `arn:aws:sns:us-east-1:000000000:${topicV3Name}`,
TopicArn: topicV3ARN,
});

const publishSpans = getTestSpans().filter(
Expand All @@ -203,6 +214,9 @@ describe('SNS - v3', () => {
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(topicV3Name);
expect(publishSpan.attributes['messaging.destination.name']).toBe(
topicV3ARN
);
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
'Publish'
);
Expand Down

0 comments on commit 28ea3b6

Please sign in to comment.