Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cloud.resource_id in AWS ECS detector #5091

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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)

mmanciop marked this conversation as resolved.
Show resolved Hide resolved
### 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