Skip to content

Commit

Permalink
replace patch with proper ATTR_CLOUD_RESOURCE_ID const
Browse files Browse the repository at this point in the history
  • Loading branch information
garysassano committed Jan 20, 2025
1 parent 5470bf5 commit f243570
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

29 changes: 29 additions & 0 deletions detectors/node/opentelemetry-resource-detector-aws/src/semconv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<SUBSCRIPTION_GUID>/resourceGroups/<RG>/providers/Microsoft.Web/sites/<FUNCAPP>/functions/<FUNC>
*
* @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/<SUBSCRIPTION_GUID>/resourceGroups/<RG>/providers/Microsoft.Web/sites/<FUNCAPP>/functions/<FUNC>`.
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f243570

Please sign in to comment.