Skip to content
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

feat(instrumentation-aws-sdk)!: Capture full ARN for span attribute messaging.destination.name for SNS topics #1727

Merged
merged 12 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] =
Copy link
Contributor Author

@alingamn alingamn Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavankrish123 Semantic attribute messaging.destination.name is not yet available. This is the PR to address that open-telemetry/opentelemetry-js#4197

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alingamn We're having some trouble updating the semantic conventions package at the moment (they are auto-generated but already released as stable). In the meantime, please add any non-stable semantic attribute names as constants here in this package.

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
Loading