Skip to content

Commit 8359555

Browse files
mmanciopMrAlias
authored andcommitted
Implement cloud.resource_id in AWS ECS detector (open-telemetry#5091)
* implement cloud.resource_id in AWS ECS detector * add CHANGELOG entry * Update CHANGELOG.md Co-authored-by: Tyler Yahn <[email protected]> --------- Co-authored-by: Tyler Yahn <[email protected]>
1 parent 50562f8 commit 8359555

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The next release will require at least [Go 1.21].
2626
- Support [Go 1.22]. (#5082)
2727
- Add support for Summary metrics to `go.opentelemetry.io/contrib/bridges/prometheus`. (#5089)
2828
- Add support for Exponential (native) Histograms in `go.opentelemetry.io/contrib/bridges/prometheus`. (#5093)
29+
- Implemented setting the `cloud.resource_id` resource attribute in `go.opentelemetry.io/detectors/aws/ecs` based on the ECS Metadata v4 endpoint. (#5091)
2930

3031
### Removed
3132

detectors/aws/README.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ resource, err := ec2ResourceDetector.Detect(context.Background())
1010

1111
EC2 resource detector captures following EC2 instance environment attributes
1212
```
13-
region
14-
availability_zone
15-
account.id
13+
cloud.region
14+
cloud.availability_zone
15+
cloud.account.id
1616
host.id
1717
host.image.id
1818
host.type
@@ -28,8 +28,22 @@ resource, err := ecsResourceDetector.Detect(context.Background())
2828

2929
ECS resource detector captures following ECS environment attributes
3030
```
31+
cloud.region
32+
cloud.availability_zone
33+
cloud.account.id
34+
cloud.resource_id
3135
container.name
3236
container.id
37+
aws.ecs.cluster.arn
38+
aws.ecs.container.arn
39+
aws.ecs.launchtype
40+
aws.ecs.task.arn
41+
aws.ecs.task.family
42+
aws.ecs.task.revision
43+
aws.log.group.arns
44+
aws.log.group.names
45+
aws.log.stream.arns
46+
aws.log.stream.names
3347
```
3448

3549
## EKS

detectors/aws/ecs/ecs.go

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc
159159

160160
attributes = append(
161161
attributes,
162+
semconv.CloudResourceID(containerMetadata.ContainerARN),
162163
semconv.AWSECSContainerARN(containerMetadata.ContainerARN),
163164
semconv.AWSECSClusterARN(taskMetadata.Cluster),
164165
semconv.AWSECSLaunchtypeKey.String(strings.ToLower(taskMetadata.LaunchType)),

detectors/aws/ecs/ecs_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func TestDetectV4(t *testing.T) {
111111
semconv.CloudAccountID("111122223333"),
112112
semconv.CloudRegion("us-west-2"),
113113
semconv.CloudAvailabilityZone("us-west-2a"),
114+
semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1"),
114115
semconv.ContainerName("container-Name"),
115116
semconv.ContainerID("0123456789A"),
116117
semconv.AWSECSClusterARN("arn:aws:ecs:us-west-2:111122223333:cluster/default"),

detectors/aws/ecs/test/ecs_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestDetectV4LaunchTypeEc2(t *testing.T) {
6969
semconv.CloudAccountID("111122223333"),
7070
semconv.CloudRegion("us-west-2"),
7171
semconv.CloudAvailabilityZone("us-west-2d"),
72+
semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"),
7273
semconv.ContainerName(hostname),
7374
// We are not running the test in an actual container,
7475
// the container id is tested with mocks of the cgroup
@@ -128,6 +129,7 @@ func TestDetectV4LaunchTypeEc2BadContainerArn(t *testing.T) {
128129
semconv.CloudAccountID("111122223333"),
129130
semconv.CloudRegion("us-west-2"),
130131
semconv.CloudAvailabilityZone("us-west-2d"),
132+
semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"),
131133
semconv.ContainerName(hostname),
132134
// We are not running the test in an actual container,
133135
// the container id is tested with mocks of the cgroup
@@ -188,6 +190,7 @@ func TestDetectV4LaunchTypeEc2BadTaskArn(t *testing.T) {
188190
semconv.CloudAccountID("111122223333"),
189191
semconv.CloudRegion("us-west-2"),
190192
semconv.CloudAvailabilityZone("us-west-2d"),
193+
semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"),
191194
// We are not running the test in an actual container,
192195
// the container id is tested with mocks of the cgroup
193196
// file in the unit tests
@@ -247,6 +250,7 @@ func TestDetectV4LaunchTypeFargate(t *testing.T) {
247250
semconv.CloudAccountID("111122223333"),
248251
semconv.CloudRegion("us-west-2"),
249252
semconv.CloudAvailabilityZone("us-west-2a"),
253+
semconv.CloudResourceID("arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1"),
250254
// We are not running the test in an actual container,
251255
// the container id is tested with mocks of the cgroup
252256
// file in the unit tests

0 commit comments

Comments
 (0)