From 6333ee3c1b6c845886e700332df74f66dd5b1bd4 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:56:45 -0800 Subject: [PATCH] fix(aws-sdk): reintroduce `SEMATTRS_*` which were changed --- .../src/services/lambda.ts | 2 ++ .../src/services/sns.ts | 7 +++++-- .../src/services/sqs.ts | 3 +++ .../test/lambda.test.ts | 4 ++++ .../test/sns.test.ts | 19 ++++++++++++++++--- .../test/sqs.test.ts | 4 ++++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts index ff4c358b7d..7c9f3a540b 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import { Span, SpanKind, Tracer, diag, Attributes } from '@opentelemetry/api'; +import { SEMATTRS_FAAS_EXECUTION } from '@opentelemetry/semantic-conventions'; import { ATTR_FAAS_INVOCATION_ID, ATTR_FAAS_INVOKED_NAME, @@ -85,6 +86,7 @@ export class LambdaServiceExtension implements ServiceExtension { switch (response.request.commandName) { case LambdaCommands.Invoke: { + span.setAttribute(SEMATTRS_FAAS_EXECUTION, response.requestId); span.setAttribute(ATTR_FAAS_INVOCATION_ID, response.requestId); } break; diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts index 148cc1f389..9aed57b658 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts @@ -16,6 +16,7 @@ import { Span, Tracer, SpanKind, Attributes } from '@opentelemetry/api'; import { MESSAGINGDESTINATIONKINDVALUES_TOPIC, + SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_DESTINATION_KIND, } from '@opentelemetry/semantic-conventions'; import { @@ -47,13 +48,15 @@ export class SnsServiceExtension implements ServiceExtension { spanAttributes[SEMATTRS_MESSAGING_DESTINATION_KIND] = MESSAGINGDESTINATIONKINDVALUES_TOPIC; const { TopicArn, TargetArn, PhoneNumber } = request.commandInput; - spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] = + spanAttributes[SEMATTRS_MESSAGING_DESTINATION] = this.extractDestinationName(TopicArn, TargetArn, PhoneNumber); + spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] = + TopicArn || TargetArn || PhoneNumber || 'unknown'; spanName = `${ PhoneNumber ? 'phone_number' - : spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] + : spanAttributes[SEMATTRS_MESSAGING_DESTINATION] } send`; } diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts index e2c1cc4368..f2409677a5 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts @@ -35,6 +35,7 @@ import { MESSAGINGDESTINATIONKINDVALUES_QUEUE, MESSAGINGOPERATIONVALUES_PROCESS, MESSAGINGOPERATIONVALUES_RECEIVE, + SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_DESTINATION_KIND, SEMATTRS_MESSAGING_URL, } from '@opentelemetry/semantic-conventions'; @@ -65,6 +66,7 @@ export class SqsServiceExtension implements ServiceExtension { [ATTR_MESSAGING_SYSTEM]: 'aws.sqs', [SEMATTRS_MESSAGING_DESTINATION_KIND]: MESSAGINGDESTINATIONKINDVALUES_QUEUE, + [SEMATTRS_MESSAGING_DESTINATION]: queueName, [ATTR_MESSAGING_DESTINATION_NAME]: queueName, [SEMATTRS_MESSAGING_URL]: queueUrl, }; @@ -170,6 +172,7 @@ export class SqsServiceExtension implements ServiceExtension { ), attributes: { [ATTR_MESSAGING_SYSTEM]: 'aws.sqs', + [SEMATTRS_MESSAGING_DESTINATION]: queueName, [ATTR_MESSAGING_DESTINATION_NAME]: queueName, [SEMATTRS_MESSAGING_DESTINATION_KIND]: MESSAGINGDESTINATIONKINDVALUES_QUEUE, diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/lambda.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/lambda.test.ts index b5f0e0f86e..b73f993f6f 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/lambda.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/lambda.test.ts @@ -21,6 +21,7 @@ import { } from '@opentelemetry/contrib-test-utils'; registerInstrumentationTesting(new AwsInstrumentation()); +import { SEMATTRS_FAAS_EXECUTION } from '@opentelemetry/semantic-conventions'; import { ATTR_FAAS_INVOCATION_ID, ATTR_FAAS_INVOKED_NAME, @@ -385,6 +386,9 @@ describe('Lambda', () => { expect(getTestSpans().length).toBe(1); const [span] = getTestSpans(); + expect(span.attributes[SEMATTRS_FAAS_EXECUTION]).toEqual( + '95882c2b-3fd2-485d-ada3-9fcb1ca65459' + ); expect(span.attributes[ATTR_FAAS_INVOCATION_ID]).toEqual( '95882c2b-3fd2-485d-ada3-9fcb1ca65459' ); diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts index 3bb559abf4..e6466aff2b 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sns.test.ts @@ -32,6 +32,7 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as sinon from 'sinon'; import { MESSAGINGDESTINATIONKINDVALUES_TOPIC, + SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_DESTINATION_KIND, } from '@opentelemetry/semantic-conventions'; import { @@ -86,9 +87,12 @@ describe('SNS - v2', () => { expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toBe( MESSAGINGDESTINATIONKINDVALUES_TOPIC ); - expect(publishSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toBe( + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toBe( topicName ); + expect(publishSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toBe( + fakeARN + ); expect(publishSpan.attributes[ATTR_RPC_METHOD]).toBe('Publish'); expect(publishSpan.attributes[ATTR_MESSAGING_SYSTEM]).toBe('aws.sns'); expect(publishSpan.kind).toBe(SpanKind.PRODUCER); @@ -109,6 +113,9 @@ describe('SNS - v2', () => { ); expect(publishSpans.length).toBe(1); const publishSpan = publishSpans[0]; + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toBe( + PhoneNumber + ); expect(publishSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toBe( PhoneNumber ); @@ -155,6 +162,9 @@ describe('SNS - v2', () => { expect( createTopicSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] ).toBeUndefined(); + expect( + createTopicSpan.attributes[SEMATTRS_MESSAGING_DESTINATION] + ).toBeUndefined(); expect( createTopicSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME] ).toBeUndefined(); @@ -201,9 +211,12 @@ describe('SNS - v3', () => { expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toBe( MESSAGINGDESTINATIONKINDVALUES_TOPIC ); - expect(publishSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toBe( + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toBe( topicV3Name ); + expect(publishSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toBe( + topicV3ARN + ); expect(publishSpan.attributes[ATTR_RPC_METHOD]).toBe('Publish'); expect(publishSpan.attributes[ATTR_MESSAGING_SYSTEM]).toBe('aws.sns'); expect(publishSpan.kind).toBe(SpanKind.PRODUCER); @@ -221,7 +234,7 @@ describe('SNS - v3', () => { ); expect(publishSpans.length).toBe(1); const publishSpan = publishSpans[0]; - expect(publishSpan.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toBe( + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toBe( PhoneNumber ); }); diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts index fd189e22cf..11e106aa14 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts @@ -29,6 +29,7 @@ import { MESSAGINGDESTINATIONKINDVALUES_QUEUE, MESSAGINGOPERATIONVALUES_PROCESS, MESSAGINGOPERATIONVALUES_RECEIVE, + SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_DESTINATION_KIND, SEMATTRS_MESSAGING_URL, } from '@opentelemetry/semantic-conventions'; @@ -404,6 +405,9 @@ describe('SQS', () => { expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual( MESSAGINGDESTINATIONKINDVALUES_QUEUE ); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + QueueName + ); expect(span.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toEqual( QueueName );