Skip to content

Commit 28ea3b6

Browse files
feat(instrumentation-aws-sdk)!: Capture full ARN for span attribute messaging.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 <[email protected]>
1 parent 607d375 commit 28ea3b6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export class SnsServiceExtension implements ServiceExtension {
4242
const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;
4343
spanAttributes[SemanticAttributes.MESSAGING_DESTINATION] =
4444
this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);
45+
// ToDO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when implemented
46+
spanAttributes['messaging.destination.name'] =
47+
TopicArn || TargetArn || PhoneNumber || 'unknown';
4548

4649
spanName = `${
4750
PhoneNumber

Diff for: plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ describe('SNS - v2', () => {
8484
expect(
8585
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
8686
).toBe(topicName);
87+
expect(publishSpan.attributes['messaging.destination.name']).toBe(
88+
fakeARN
89+
);
8790
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
8891
'Publish'
8992
);
@@ -111,6 +114,9 @@ describe('SNS - v2', () => {
111114
expect(
112115
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
113116
).toBe(PhoneNumber);
117+
expect(publishSpan.attributes['messaging.destination.name']).toBe(
118+
PhoneNumber
119+
);
114120
});
115121

116122
it('inject context propagation', async () => {
@@ -159,6 +165,9 @@ describe('SNS - v2', () => {
159165
expect(
160166
createTopicSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
161167
).toBeUndefined();
168+
expect(
169+
createTopicSpan.attributes['messaging.destination.name']
170+
).toBeUndefined();
162171
expect(createTopicSpan.kind).toBe(SpanKind.CLIENT);
163172
});
164173
});
@@ -186,9 +195,11 @@ describe('SNS - v3', () => {
186195
describe('publish', () => {
187196
it('topic arn', async () => {
188197
const topicV3Name = 'dummy-sns-v3-topic';
198+
const topicV3ARN = `arn:aws:sns:us-east-1:000000000:${topicV3Name}`;
199+
189200
await sns.publish({
190201
Message: 'sns message',
191-
TopicArn: `arn:aws:sns:us-east-1:000000000:${topicV3Name}`,
202+
TopicArn: topicV3ARN,
192203
});
193204

194205
const publishSpans = getTestSpans().filter(
@@ -203,6 +214,9 @@ describe('SNS - v3', () => {
203214
expect(
204215
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
205216
).toBe(topicV3Name);
217+
expect(publishSpan.attributes['messaging.destination.name']).toBe(
218+
topicV3ARN
219+
);
206220
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
207221
'Publish'
208222
);

0 commit comments

Comments
 (0)