From f2435700211ddc4a84bb20cbcbc7aa80c92dc6f7 Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:34:36 +0100 Subject: [PATCH] replace patch with proper `ATTR_CLOUD_RESOURCE_ID` const --- .../src/detectors/AwsEcsDetectorSync.ts | 27 +++++++++-------- .../detectors/SemanticResourceAttributes.ts | 23 --------------- .../src/semconv.ts | 29 +++++++++++++++++++ .../test/detectors/AwsEcsDetector.test.ts | 5 ++-- .../test/detectors/AwsEcsDetectorSync.test.ts | 5 ++-- 5 files changed, 46 insertions(+), 43 deletions(-) delete mode 100644 detectors/node/opentelemetry-resource-detector-aws/src/detectors/SemanticResourceAttributes.ts diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts index d7ccaf8465..4f47169d4a 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts @@ -23,28 +23,27 @@ import { ResourceAttributes, } from '@opentelemetry/resources'; import { - ATTR_CLOUD_PROVIDER, - ATTR_CLOUD_PLATFORM, - ATTR_CONTAINER_ID, - ATTR_CONTAINER_NAME, - ATTR_AWS_ECS_CONTAINER_ARN, ATTR_AWS_ECS_CLUSTER_ARN, + ATTR_AWS_ECS_CONTAINER_ARN, ATTR_AWS_ECS_LAUNCHTYPE, ATTR_AWS_ECS_TASK_ARN, ATTR_AWS_ECS_TASK_FAMILY, ATTR_AWS_ECS_TASK_REVISION, - ATTR_CLOUD_ACCOUNT_ID, - ATTR_CLOUD_REGION, - ATTR_CLOUD_AVAILABILITY_ZONE, - ATTR_AWS_LOG_GROUP_NAMES, ATTR_AWS_LOG_GROUP_ARNS, - ATTR_AWS_LOG_STREAM_NAMES, + ATTR_AWS_LOG_GROUP_NAMES, ATTR_AWS_LOG_STREAM_ARNS, - CLOUD_PROVIDER_VALUE_AWS, + ATTR_AWS_LOG_STREAM_NAMES, + ATTR_CLOUD_ACCOUNT_ID, + ATTR_CLOUD_AVAILABILITY_ZONE, + ATTR_CLOUD_PLATFORM, + ATTR_CLOUD_PROVIDER, + ATTR_CLOUD_REGION, + ATTR_CLOUD_RESOURCE_ID, + ATTR_CONTAINER_ID, + ATTR_CONTAINER_NAME, CLOUD_PLATFORM_VALUE_AWS_ECS, + CLOUD_PROVIDER_VALUE_AWS, } from '../semconv'; -// Patch until the OpenTelemetry SDK is updated to ship this attribute -import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from './SemanticResourceAttributes'; import * as http from 'http'; import * as util from 'util'; import * as fs from 'fs'; @@ -185,7 +184,7 @@ export class AwsEcsDetectorSync implements DetectorSync { [ATTR_CLOUD_ACCOUNT_ID]: accountId, [ATTR_CLOUD_REGION]: region, - [AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID]: containerArn, + [ATTR_CLOUD_RESOURCE_ID]: containerArn, }; // The availability zone is not available in all Fargate runtimes diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/SemanticResourceAttributes.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/SemanticResourceAttributes.ts deleted file mode 100644 index 24efaebd07..0000000000 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/SemanticResourceAttributes.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export const SemanticResourceAttributes = { - /** - * Cloud provider-specific native identifier of the monitored cloud resource - * (e.g. an ARN on AWS, a fully qualified resource ID on Azure, a full resource - * name on GCP) - */ - CLOUD_RESOURCE_ID: 'cloud.resource_id', -}; diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/semconv.ts b/detectors/node/opentelemetry-resource-detector-aws/src/semconv.ts index 3d34526643..148a382134 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/semconv.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/semconv.ts @@ -165,6 +165,35 @@ export const ATTR_CLOUD_PROVIDER = 'cloud.provider'; */ export const ATTR_CLOUD_REGION = 'cloud.region'; +/** + * Cloud provider-specific native identifier of the monitored cloud resource (e.g. an [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) on AWS, a [fully qualified resource ID](https://learn.microsoft.com/rest/api/resources/resources/get-by-id) on Azure, a [full resource name](https://cloud.google.com/apis/design/resource_names#full_resource_name) on GCP) + * + * @example arn:aws:lambda:REGION:ACCOUNT_ID:function:my-function + * @example //run.googleapis.com/projects/PROJECT_ID/locations/LOCATION_ID/services/SERVICE_ID + * @example /subscriptions//resourceGroups//providers/Microsoft.Web/sites//functions/ + * + * @note On some cloud providers, it may not be possible to determine the full ID at startup, + * so it may be necessary to set `cloud.resource_id` as a span attribute instead. + * + * The exact value to use for `cloud.resource_id` depends on the cloud provider. + * The following well-known definitions **MUST** be used if you set this attribute and they apply: + * + * - **AWS Lambda:** The function [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). + * Take care not to use the "invoked ARN" directly but replace any + * [alias suffix](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html) + * with the resolved function version, as the same runtime instance may be invocable with + * multiple different aliases. + * - **GCP:** The [URI of the resource](https://cloud.google.com/iam/docs/full-resource-names) + * - **Azure:** The [Fully Qualified Resource ID](https://docs.microsoft.com/rest/api/resources/resources/get-by-id) of the invoked function, + * *not* the function app, having the form + * `/subscriptions//resourceGroups//providers/Microsoft.Web/sites//functions/`. + * This means that a span attribute **MUST** be used, as an Azure function app can host multiple functions that would usually share + * a TracerProvider. + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_CLOUD_RESOURCE_ID = 'cloud.resource_id'; + /** * Container ID. Usually a UUID, as for example used to [identify Docker containers](https://docs.docker.com/engine/containers/run/#container-identification). The UUID might be abbreviated. * diff --git a/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetector.test.ts b/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetector.test.ts index e046d3c01b..825c595414 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetector.test.ts @@ -39,11 +39,10 @@ import { ATTR_CLOUD_PLATFORM, ATTR_CLOUD_PROVIDER, ATTR_CLOUD_REGION, + ATTR_CLOUD_RESOURCE_ID, CLOUD_PLATFORM_VALUE_AWS_ECS, CLOUD_PROVIDER_VALUE_AWS, } from '../../src/semconv'; -// Patch until the OpenTelemetry SDK is updated to ship this attribute -import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from '../../src/detectors/SemanticResourceAttributes'; import { readFileSync } from 'fs'; import * as os from 'os'; import { join } from 'path'; @@ -93,7 +92,7 @@ const assertEcsResource = ( validations.containerArn ); assert.strictEqual( - resource.attributes[AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID], + resource.attributes[ATTR_CLOUD_RESOURCE_ID], validations.containerArn ); assert.strictEqual( diff --git a/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetectorSync.test.ts b/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetectorSync.test.ts index 42145f01f9..9bbd9d3f60 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetectorSync.test.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetectorSync.test.ts @@ -39,11 +39,10 @@ import { ATTR_CLOUD_PLATFORM, ATTR_CLOUD_PROVIDER, ATTR_CLOUD_REGION, + ATTR_CLOUD_RESOURCE_ID, CLOUD_PLATFORM_VALUE_AWS_ECS, CLOUD_PROVIDER_VALUE_AWS, } from '../../src/semconv'; -// Patch until the OpenTelemetry SDK is updated to ship this attribute -import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from '../../src/detectors/SemanticResourceAttributes'; import { readFileSync } from 'fs'; import * as os from 'os'; import { join } from 'path'; @@ -93,7 +92,7 @@ const assertEcsResource = ( validations.containerArn ); assert.strictEqual( - resource.attributes[AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID], + resource.attributes[ATTR_CLOUD_RESOURCE_ID], validations.containerArn ); assert.strictEqual(