diff --git a/CHANGELOG.md b/CHANGELOG.md index a669a6336d6..2629f3fc6d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The next release will require at least [Go 1.21]. - Support [Go 1.22]. (#5082) - Add support for Summary metrics to `go.opentelemetry.io/contrib/bridges/prometheus`. (#5089) - Add support for Exponential (native) Histograms in `go.opentelemetry.io/contrib/bridges/prometheus`. (#5093) +- Implemented setting the `cloud.resource_id` resource attribute in `go.opentelemetry.io/detectors/aws/ecs` based on the ECS Metadata v4 endpoint. (#5091) ### Removed diff --git a/detectors/aws/README.md b/detectors/aws/README.md index 372db84018a..16523f950da 100644 --- a/detectors/aws/README.md +++ b/detectors/aws/README.md @@ -10,9 +10,9 @@ resource, err := ec2ResourceDetector.Detect(context.Background()) EC2 resource detector captures following EC2 instance environment attributes ``` -region -availability_zone -account.id +cloud.region +cloud.availability_zone +cloud.account.id host.id host.image.id host.type @@ -28,8 +28,22 @@ resource, err := ecsResourceDetector.Detect(context.Background()) ECS resource detector captures following ECS environment attributes ``` +cloud.region +cloud.availability_zone +cloud.account.id +cloud.resource_id container.name container.id +aws.ecs.cluster.arn +aws.ecs.container.arn +aws.ecs.launchtype +aws.ecs.task.arn +aws.ecs.task.family +aws.ecs.task.revision +aws.log.group.arns +aws.log.group.names +aws.log.stream.arns +aws.log.stream.names ``` ## EKS diff --git a/detectors/aws/ecs/ecs.go b/detectors/aws/ecs/ecs.go index 284c006c4de..a815664b8d7 100644 --- a/detectors/aws/ecs/ecs.go +++ b/detectors/aws/ecs/ecs.go @@ -159,6 +159,7 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc attributes = append( attributes, + semconv.CloudResourceID(containerMetadata.ContainerARN), semconv.AWSECSContainerARN(containerMetadata.ContainerARN), semconv.AWSECSClusterARN(taskMetadata.Cluster), semconv.AWSECSLaunchtypeKey.String(strings.ToLower(taskMetadata.LaunchType)), diff --git a/detectors/aws/ecs/ecs_test.go b/detectors/aws/ecs/ecs_test.go index 90f51e84cb2..bf005b09899 100644 --- a/detectors/aws/ecs/ecs_test.go +++ b/detectors/aws/ecs/ecs_test.go @@ -111,6 +111,7 @@ func TestDetectV4(t *testing.T) { semconv.CloudAccountID("111122223333"), semconv.CloudRegion("us-west-2"), semconv.CloudAvailabilityZone("us-west-2a"), + semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1"), semconv.ContainerName("container-Name"), semconv.ContainerID("0123456789A"), semconv.AWSECSClusterARN("arn:aws:ecs:us-west-2:111122223333:cluster/default"), diff --git a/detectors/aws/ecs/test/ecs_test.go b/detectors/aws/ecs/test/ecs_test.go index fcebbe415bd..0dde560d95f 100644 --- a/detectors/aws/ecs/test/ecs_test.go +++ b/detectors/aws/ecs/test/ecs_test.go @@ -69,6 +69,7 @@ func TestDetectV4LaunchTypeEc2(t *testing.T) { semconv.CloudAccountID("111122223333"), semconv.CloudRegion("us-west-2"), semconv.CloudAvailabilityZone("us-west-2d"), + semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"), semconv.ContainerName(hostname), // We are not running the test in an actual container, // the container id is tested with mocks of the cgroup @@ -128,6 +129,7 @@ func TestDetectV4LaunchTypeEc2BadContainerArn(t *testing.T) { semconv.CloudAccountID("111122223333"), semconv.CloudRegion("us-west-2"), semconv.CloudAvailabilityZone("us-west-2d"), + semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"), semconv.ContainerName(hostname), // We are not running the test in an actual container, // the container id is tested with mocks of the cgroup @@ -188,6 +190,7 @@ func TestDetectV4LaunchTypeEc2BadTaskArn(t *testing.T) { semconv.CloudAccountID("111122223333"), semconv.CloudRegion("us-west-2"), semconv.CloudAvailabilityZone("us-west-2d"), + semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"), // We are not running the test in an actual container, // the container id is tested with mocks of the cgroup // file in the unit tests @@ -247,6 +250,7 @@ func TestDetectV4LaunchTypeFargate(t *testing.T) { semconv.CloudAccountID("111122223333"), semconv.CloudRegion("us-west-2"), semconv.CloudAvailabilityZone("us-west-2a"), + semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1"), // We are not running the test in an actual container, // the container id is tested with mocks of the cgroup // file in the unit tests