From 0f18efdd074afd92176f217510dd4472e86d291d Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:01:28 -0800 Subject: [PATCH] chore(aws-sdk): migrate 'SEMATTRS_*' to 'ATTR_*' --- .../src/aws-sdk.ts | 14 +-- .../src/services/dynamodb.ts | 115 +++++++++--------- .../src/services/lambda.ts | 18 +-- .../src/services/sns.ts | 15 +-- .../src/services/sqs.ts | 53 ++++---- .../src/utils.ts | 12 +- 6 files changed, 108 insertions(+), 119 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts index a3040a15a9..ff2286fe4b 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts @@ -59,7 +59,7 @@ import { } from './utils'; import { propwrap } from './propwrap'; import { RequestMetadata } from './services/ServiceExtension'; -import { SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions'; +import { ATTR_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions/incubating'; const V3_CLIENT_CONFIG_KEY = Symbol( 'opentelemetry.instrumentation.aws-sdk.client.config' @@ -348,7 +348,7 @@ export class AwsInstrumentation extends InstrumentationBase JSON.stringify(x)); } if (normalizedRequest.commandInput?.LocalSecondaryIndexes) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES] = + spanAttributes[ATTR_AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES] = this.toArray( normalizedRequest.commandInput.LocalSecondaryIndexes ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x)); @@ -155,67 +155,66 @@ export class DynamodbServiceExtension implements ServiceExtension { operation === 'Scan' ) { if (normalizedRequest.commandInput?.Limit) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_LIMIT] = + spanAttributes[ATTR_AWS_DYNAMODB_LIMIT] = normalizedRequest.commandInput.Limit; } } if (operation === 'ListTables') { if (normalizedRequest.commandInput?.ExclusiveStartTableName) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_EXCLUSIVE_START_TABLE] = + spanAttributes[ATTR_AWS_DYNAMODB_EXCLUSIVE_START_TABLE] = normalizedRequest.commandInput.ExclusiveStartTableName; } } if (operation === 'Query') { if (normalizedRequest.commandInput?.ScanIndexForward) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_SCAN_FORWARD] = + spanAttributes[ATTR_AWS_DYNAMODB_SCAN_FORWARD] = normalizedRequest.commandInput.ScanIndexForward; } if (normalizedRequest.commandInput?.IndexName) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_INDEX_NAME] = + spanAttributes[ATTR_AWS_DYNAMODB_INDEX_NAME] = normalizedRequest.commandInput.IndexName; } if (normalizedRequest.commandInput?.Select) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_SELECT] = + spanAttributes[ATTR_AWS_DYNAMODB_SELECT] = normalizedRequest.commandInput.Select; } } if (operation === 'Scan') { if (normalizedRequest.commandInput?.Segment) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_SEGMENT] = + spanAttributes[ATTR_AWS_DYNAMODB_SEGMENT] = normalizedRequest.commandInput?.Segment; } if (normalizedRequest.commandInput?.TotalSegments) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_TOTAL_SEGMENTS] = + spanAttributes[ATTR_AWS_DYNAMODB_TOTAL_SEGMENTS] = normalizedRequest.commandInput?.TotalSegments; } if (normalizedRequest.commandInput?.IndexName) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_INDEX_NAME] = + spanAttributes[ATTR_AWS_DYNAMODB_INDEX_NAME] = normalizedRequest.commandInput.IndexName; } if (normalizedRequest.commandInput?.Select) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_SELECT] = + spanAttributes[ATTR_AWS_DYNAMODB_SELECT] = normalizedRequest.commandInput.Select; } } if (operation === 'UpdateTable') { if (normalizedRequest.commandInput?.AttributeDefinitions) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS] = - this.toArray(normalizedRequest.commandInput.AttributeDefinitions).map( - (x: { [DictionaryKey: string]: any }) => JSON.stringify(x) - ); + spanAttributes[ATTR_AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS] = this.toArray( + normalizedRequest.commandInput.AttributeDefinitions + ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x)); } if (normalizedRequest.commandInput?.GlobalSecondaryIndexUpdates) { - spanAttributes[SEMATTRS_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES] = + spanAttributes[ATTR_AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES] = this.toArray( normalizedRequest.commandInput.GlobalSecondaryIndexUpdates ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x)); @@ -238,7 +237,7 @@ export class DynamodbServiceExtension implements ServiceExtension { ) { if (response.data?.ConsumedCapacity) { span.setAttribute( - SEMATTRS_AWS_DYNAMODB_CONSUMED_CAPACITY, + ATTR_AWS_DYNAMODB_CONSUMED_CAPACITY, toArray(response.data.ConsumedCapacity).map( (x: { [DictionaryKey: string]: any }) => JSON.stringify(x) ) @@ -247,7 +246,7 @@ export class DynamodbServiceExtension implements ServiceExtension { if (response.data?.ItemCollectionMetrics) { span.setAttribute( - SEMATTRS_AWS_DYNAMODB_ITEM_COLLECTION_METRICS, + ATTR_AWS_DYNAMODB_ITEM_COLLECTION_METRICS, this.toArray(response.data.ItemCollectionMetrics).map( (x: { [DictionaryKey: string]: any }) => JSON.stringify(x) ) @@ -256,18 +255,18 @@ export class DynamodbServiceExtension implements ServiceExtension { if (response.data?.TableNames) { span.setAttribute( - SEMATTRS_AWS_DYNAMODB_TABLE_COUNT, + ATTR_AWS_DYNAMODB_TABLE_COUNT, response.data?.TableNames.length ); } if (response.data?.Count) { - span.setAttribute(SEMATTRS_AWS_DYNAMODB_COUNT, response.data?.Count); + span.setAttribute(ATTR_AWS_DYNAMODB_COUNT, response.data?.Count); } if (response.data?.ScannedCount) { span.setAttribute( - SEMATTRS_AWS_DYNAMODB_SCANNED_COUNT, + ATTR_AWS_DYNAMODB_SCANNED_COUNT, response.data?.ScannedCount ); } 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 3970c3c098..ff4c358b7d 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/lambda.ts @@ -15,11 +15,11 @@ */ import { Span, SpanKind, Tracer, diag, Attributes } from '@opentelemetry/api'; import { - SEMATTRS_FAAS_EXECUTION, - SEMATTRS_FAAS_INVOKED_NAME, - SEMATTRS_FAAS_INVOKED_PROVIDER, - SEMATTRS_FAAS_INVOKED_REGION, -} from '@opentelemetry/semantic-conventions'; + ATTR_FAAS_INVOCATION_ID, + ATTR_FAAS_INVOKED_NAME, + ATTR_FAAS_INVOKED_PROVIDER, + ATTR_FAAS_INVOKED_REGION, +} from '@opentelemetry/semantic-conventions/incubating'; import { AwsSdkInstrumentationConfig, NormalizedRequest, @@ -45,11 +45,11 @@ export class LambdaServiceExtension implements ServiceExtension { switch (request.commandName) { case 'Invoke': spanAttributes = { - [SEMATTRS_FAAS_INVOKED_NAME]: functionName, - [SEMATTRS_FAAS_INVOKED_PROVIDER]: 'aws', + [ATTR_FAAS_INVOKED_NAME]: functionName, + [ATTR_FAAS_INVOKED_PROVIDER]: 'aws', }; if (request.region) { - spanAttributes[SEMATTRS_FAAS_INVOKED_REGION] = request.region; + spanAttributes[ATTR_FAAS_INVOKED_REGION] = request.region; } spanName = `${functionName} ${LambdaCommands.Invoke}`; break; @@ -85,7 +85,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 e825cdd309..c6e3811a2c 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sns.ts @@ -16,10 +16,12 @@ import { Span, Tracer, SpanKind, Attributes } from '@opentelemetry/api'; import { MESSAGINGDESTINATIONKINDVALUES_TOPIC, - SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_DESTINATION_KIND, - SEMATTRS_MESSAGING_SYSTEM, } from '@opentelemetry/semantic-conventions'; +import { + ATTR_MESSAGING_DESTINATION_NAME, + ATTR_MESSAGING_SYSTEM, +} from '@opentelemetry/semantic-conventions/incubating'; import { NormalizedRequest, NormalizedResponse, @@ -36,7 +38,7 @@ export class SnsServiceExtension implements ServiceExtension { let spanKind: SpanKind = SpanKind.CLIENT; let spanName = `SNS ${request.commandName}`; const spanAttributes: Attributes = { - [SEMATTRS_MESSAGING_SYSTEM]: 'aws.sns', + [ATTR_MESSAGING_SYSTEM]: 'aws.sns', }; if (request.commandName === 'Publish') { @@ -45,16 +47,15 @@ export class SnsServiceExtension implements ServiceExtension { spanAttributes[SEMATTRS_MESSAGING_DESTINATION_KIND] = MESSAGINGDESTINATIONKINDVALUES_TOPIC; const { TopicArn, TargetArn, PhoneNumber } = request.commandInput; - spanAttributes[SEMATTRS_MESSAGING_DESTINATION] = + spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] = this.extractDestinationName(TopicArn, TargetArn, PhoneNumber); - // ToDO: Use SEMATTRS_MESSAGING_DESTINATION_NAME when implemented - spanAttributes['messaging.destination.name'] = + spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] = TopicArn || TargetArn || PhoneNumber || 'unknown'; spanName = `${ PhoneNumber ? 'phone_number' - : spanAttributes[SEMATTRS_MESSAGING_DESTINATION] + : spanAttributes[ATTR_MESSAGING_DESTINATION_NAME] } 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 07cedaa25d..1e80bd173c 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts @@ -32,16 +32,16 @@ import { NormalizedResponse, } from '../types'; import { - MESSAGINGDESTINATIONKINDVALUES_QUEUE, - MESSAGINGOPERATIONVALUES_PROCESS, - MESSAGINGOPERATIONVALUES_RECEIVE, - SEMATTRS_MESSAGING_DESTINATION, - SEMATTRS_MESSAGING_DESTINATION_KIND, - SEMATTRS_MESSAGING_MESSAGE_ID, - SEMATTRS_MESSAGING_OPERATION, - SEMATTRS_MESSAGING_SYSTEM, - SEMATTRS_MESSAGING_URL, -} from '@opentelemetry/semantic-conventions'; + MESSAGING_DESTINATION_KIND_VALUE_QUEUE, + MESSAGING_OPERATION_VALUE_PROCESS, + MESSAGING_OPERATION_VALUE_RECEIVE, + ATTR_MESSAGING_DESTINATION, + ATTR_MESSAGING_DESTINATION_KIND, + ATTR_MESSAGING_MESSAGE_ID, + ATTR_MESSAGING_OPERATION, + ATTR_MESSAGING_SYSTEM, + ATTR_MESSAGING_URL, +} from '@opentelemetry/semantic-conventions/incubating'; import { contextGetter, extractPropagationContext, @@ -60,11 +60,10 @@ export class SqsServiceExtension implements ServiceExtension { let spanName: string | undefined; const spanAttributes: Attributes = { - [SEMATTRS_MESSAGING_SYSTEM]: 'aws.sqs', - [SEMATTRS_MESSAGING_DESTINATION_KIND]: - MESSAGINGDESTINATIONKINDVALUES_QUEUE, - [SEMATTRS_MESSAGING_DESTINATION]: queueName, - [SEMATTRS_MESSAGING_URL]: queueUrl, + [ATTR_MESSAGING_SYSTEM]: 'aws.sqs', + [ATTR_MESSAGING_DESTINATION_KIND]: MESSAGING_DESTINATION_KIND_VALUE_QUEUE, + [ATTR_MESSAGING_DESTINATION]: queueName, + [ATTR_MESSAGING_URL]: queueUrl, }; let isIncoming = false; @@ -75,8 +74,8 @@ export class SqsServiceExtension implements ServiceExtension { isIncoming = true; spanKind = SpanKind.CONSUMER; spanName = `${queueName} receive`; - spanAttributes[SEMATTRS_MESSAGING_OPERATION] = - MESSAGINGOPERATIONVALUES_RECEIVE; + spanAttributes[ATTR_MESSAGING_OPERATION] = + MESSAGING_OPERATION_VALUE_RECEIVE; request.commandInput.MessageAttributeNames = addPropagationFieldsToAttributeNames( @@ -139,10 +138,7 @@ export class SqsServiceExtension implements ServiceExtension { ) => { switch (response.request.commandName) { case 'SendMessage': - span.setAttribute( - SEMATTRS_MESSAGING_MESSAGE_ID, - response?.data?.MessageId - ); + span.setAttribute(ATTR_MESSAGING_MESSAGE_ID, response?.data?.MessageId); break; case 'SendMessageBatch': @@ -170,14 +166,13 @@ export class SqsServiceExtension implements ServiceExtension { contextGetter ), attributes: { - [SEMATTRS_MESSAGING_SYSTEM]: 'aws.sqs', - [SEMATTRS_MESSAGING_DESTINATION]: queueName, - [SEMATTRS_MESSAGING_DESTINATION_KIND]: - MESSAGINGDESTINATIONKINDVALUES_QUEUE, - [SEMATTRS_MESSAGING_MESSAGE_ID]: message.MessageId, - [SEMATTRS_MESSAGING_URL]: queueUrl, - [SEMATTRS_MESSAGING_OPERATION]: - MESSAGINGOPERATIONVALUES_PROCESS, + [ATTR_MESSAGING_SYSTEM]: 'aws.sqs', + [ATTR_MESSAGING_DESTINATION]: queueName, + [ATTR_MESSAGING_DESTINATION_KIND]: + MESSAGING_DESTINATION_KIND_VALUE_QUEUE, + [ATTR_MESSAGING_MESSAGE_ID]: message.MessageId, + [ATTR_MESSAGING_URL]: queueUrl, + [ATTR_MESSAGING_OPERATION]: MESSAGING_OPERATION_VALUE_PROCESS, }, }), processHook: (span: Span, message: SQS.Message) => diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/utils.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/utils.ts index cb8aaa6591..1d5e74e380 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/utils.ts @@ -15,9 +15,9 @@ */ import { Attributes, Context, context } from '@opentelemetry/api'; import { - SEMATTRS_RPC_METHOD, - SEMATTRS_RPC_SERVICE, - SEMATTRS_RPC_SYSTEM, + ATTR_RPC_METHOD, + ATTR_RPC_SERVICE, + ATTR_RPC_SYSTEM, } from '@opentelemetry/semantic-conventions'; import { AttributeNames } from './enums'; import { NormalizedRequest } from './types'; @@ -66,9 +66,9 @@ export const extractAttributesFromNormalizedRequest = ( normalizedRequest: NormalizedRequest ): Attributes => { return { - [SEMATTRS_RPC_SYSTEM]: 'aws-api', - [SEMATTRS_RPC_METHOD]: normalizedRequest.commandName, - [SEMATTRS_RPC_SERVICE]: normalizedRequest.serviceName, + [ATTR_RPC_SYSTEM]: 'aws-api', + [ATTR_RPC_METHOD]: normalizedRequest.commandName, + [ATTR_RPC_SERVICE]: normalizedRequest.serviceName, [AttributeNames.AWS_REGION]: normalizedRequest.region, }; };