Skip to content

Commit

Permalink
Capture full ARN for SNS topics in messaging.destination
Browse files Browse the repository at this point in the history
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 open-telemetry#1716
  • Loading branch information
alingamn committed Oct 11, 2023
1 parent 2d36152 commit de889eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SnsServiceExtension implements ServiceExtension {
MessagingDestinationKindValues.TOPIC;
const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;
spanAttributes[SemanticAttributes.MESSAGING_DESTINATION] =
this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);
TopicArn || TargetArn || PhoneNumber || 'unknown';

spanName = `${
PhoneNumber
Expand Down Expand Up @@ -76,23 +76,4 @@ export class SnsServiceExtension implements ServiceExtension {
tracer: Tracer,
config: AwsSdkInstrumentationConfig
): void {}

extractDestinationName(
topicArn: string,
targetArn: string,
phoneNumber: string
): string {
if (topicArn || targetArn) {
const arn = topicArn ?? targetArn;
try {
return arn.substr(arn.lastIndexOf(':') + 1);
} catch (err) {
return arn;
}
} else if (phoneNumber) {
return phoneNumber;
} else {
return 'unknown';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('SNS - v2', () => {
.promise();

const publishSpans = getTestSpans().filter(
(s: ReadableSpan) => s.name === `${topicName} send`
(s: ReadableSpan) => s.name === `${fakeARN} send`
);
expect(publishSpans.length).toBe(1);

Expand All @@ -83,7 +83,7 @@ describe('SNS - v2', () => {
).toBe(MessagingDestinationKindValues.TOPIC);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(topicName);
).toBe(fakeARN);
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
'Publish'
);
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('SNS - v2', () => {
.promise();

const publishSpans = getTestSpans().filter(
(s: ReadableSpan) => s.name === `${topicName} send`
(s: ReadableSpan) => s.name === `${fakeARN} send`
);
expect(publishSpans.length).toBe(1);
expect(
Expand Down Expand Up @@ -186,13 +186,15 @@ 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(
(s: ReadableSpan) => s.name === `${topicV3Name} send`
(s: ReadableSpan) => s.name === `${topicV3ARN} send`
);
expect(publishSpans.length).toBe(1);

Expand All @@ -202,7 +204,7 @@ describe('SNS - v3', () => {
).toBe(MessagingDestinationKindValues.TOPIC);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(topicV3Name);
).toBe(topicV3ARN);
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
'Publish'
);
Expand Down

0 comments on commit de889eb

Please sign in to comment.