Skip to content

Commit

Permalink
Implement cloud.resource_id in AWS ECS detector (#5091)
Browse files Browse the repository at this point in the history
* implement cloud.resource_id in AWS ECS detector

* add CHANGELOG entry

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
mmanciop and MrAlias committed Feb 26, 2024
1 parent fab2938 commit 45226f8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions detectors/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions detectors/aws/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
1 change: 1 addition & 0 deletions detectors/aws/ecs/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 4 additions & 0 deletions detectors/aws/ecs/test/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 45226f8

Please sign in to comment.