From 9db13415c95dcdaa0e6c50f18303a5ba2fe29a8e Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Wed, 14 Feb 2024 10:51:37 +0100 Subject: [PATCH 1/3] implement cloud.resource_id in AWS ECS detector --- detectors/aws/README.md | 20 +++++++++++++++++--- detectors/aws/ecs/ecs.go | 1 + detectors/aws/ecs/ecs_test.go | 1 + detectors/aws/ecs/test/ecs_test.go | 4 ++++ 4 files changed, 23 insertions(+), 3 deletions(-) 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 From a362da4bc05ab6211e4132b8d13782208f71039b Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Wed, 14 Feb 2024 16:40:29 +0100 Subject: [PATCH 2/3] add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db722c702e3..1e36cc8053b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ The next release will require at least [Go 1.21]. - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) - Support [Go 1.22]. (#5082) +- Implemented setting the `cloud.resource_id` resource attribute in `go.opentelemetry.io/detectors/aws/ecs` based on the ECS Metadata v4 endpoint. (#5091) + ### Removed From 1d2ce4e6aed1aeea92a796ee084c93407c6b34af Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Tue, 20 Feb 2024 16:49:26 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Tyler Yahn --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e36cc8053b..d07396c46f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,6 @@ The next release will require at least [Go 1.21]. - Support [Go 1.22]. (#5082) - Implemented setting the `cloud.resource_id` resource attribute in `go.opentelemetry.io/detectors/aws/ecs` based on the ECS Metadata v4 endpoint. (#5091) - ### Removed - The deprecated `RequestCount` constant in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is removed. (#4894)