Repository: open-telemetry/opentelemetry-go-contrib (2025-07-22T01:50:01Z)

Issue:
`detectors/aws/ecs` tests are failing locally
### Description

`detectors/aws/ecs` tests are failing locally

### Environment

- OS: Ubuntu

### Steps To Reproduce

```
make test-default
```

### Actual behavior

```
ok      go.opentelemetry.io/contrib/detectors/aws/ecs   1.015s
--- FAIL: TestDetectV4LaunchTypeEc2 (0.01s)
    ecs_test.go:83: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/detectors/aws/ecs/test/ecs_test.go:83
                Error:          Not equal: 
                                expected: &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ec2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"26", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/metadata"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2d", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                                actual  : &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ec2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"26", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/metadata"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2d", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -161,3 +161,3 @@
                                       numeric: (uint64) 0,
                                -      stringly: (string) "",
                                +      stringly: (string) (len=64) "00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope",
                                       slice: (interface {}) <nil>
                Test:           TestDetectV4LaunchTypeEc2
                Messages:       Resource returned is incorrect
--- FAIL: TestDetectV4LaunchTypeEc2BadContainerArn (0.01s)
    ecs_test.go:143: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/detectors/aws/ecs/test/ecs_test.go:143
                Error:          Not equal: 
                                expected: &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ec2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"26", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/metadata"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2d", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                                actual  : &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ec2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"26", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/metadata"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2d", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -161,3 +161,3 @@
                                       numeric: (uint64) 0,
                                -      stringly: (string) "",
                                +      stringly: (string) (len=64) "00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope",
                                       slice: (interface {}) <nil>
                Test:           TestDetectV4LaunchTypeEc2BadContainerArn
                Messages:       Resource returned is incorrect
--- FAIL: TestDetectV4LaunchTypeEc2BadTaskArn (0.01s)
    ecs_test.go:203: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/detectors/aws/ecs/test/ecs_test.go:203
                Error:          Not equal: 
                                expected: &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ec2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"26", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/metadata"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2d", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                                actual  : &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ec2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"26", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/metadata"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/8f03e41243824aea923aca126495f665"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2d", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -161,3 +161,3 @@
                                       numeric: (uint64) 0,
                                -      stringly: (string) "",
                                +      stringly: (string) (len=64) "00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope",
                                       slice: (interface {}) <nil>
                Test:           TestDetectV4LaunchTypeEc2BadTaskArn
                Messages:       Resource returned is incorrect
--- FAIL: TestDetectV4LaunchTypeFargate (0.01s)
    ecs_test.go:263: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/detectors/aws/ecs/test/ecs_test.go:263
                Error:          Not equal: 
                                expected: &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"fargate", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/e9028f8d5d8e4f258373e7b93ce9a3c3", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"3", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/containerlogs"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:log-stream:ecs/curl/cd189a933e5849daa93386466019ab50"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/cd189a933e5849daa93386466019ab50"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2a", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                                actual  : &resource.Resource{attrs:attribute.Set{equivalent:attribute.Distinct{iface:[18]attribute.KeyValue{attribute.KeyValue{Key:"aws.ecs.cluster.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:cluster/default", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.container.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.launchtype", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"fargate", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.arn", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:task/default/e9028f8d5d8e4f258373e7b93ce9a3c3", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.family", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"curltest", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.ecs.task.revision", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"3", slice:interface {}(nil)}}, attribute.KeyValue{Key:"aws.log.group.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:*"}}}, attribute.KeyValue{Key:"aws.log.group.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"/ecs/containerlogs"}}}, attribute.KeyValue{Key:"aws.log.stream.arns", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:log-stream:ecs/curl/cd189a933e5849daa93386466019ab50"}}}, attribute.KeyValue{Key:"aws.log.stream.names", Value:attribute.Value{vtype:8, numeric:0x0, stringly:"", slice:[1]string{"ecs/curl/cd189a933e5849daa93386466019ab50"}}}, attribute.KeyValue{Key:"cloud.account.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"111122223333", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.availability_zone", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2a", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.platform", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws_ecs", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.provider", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"aws", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.region", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"us-west-2", slice:interface {}(nil)}}, attribute.KeyValue{Key:"cloud.resource_id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.id", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope", slice:interface {}(nil)}}, attribute.KeyValue{Key:"container.name", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"ropajak-l-pw0c1e3r", slice:interface {}(nil)}}}}}, schemaURL:"https://opentelemetry.io/schemas/1.34.0"}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -161,3 +161,3 @@
                                       numeric: (uint64) 0,
                                -      stringly: (string) "",
                                +      stringly: (string) (len=64) "00.slice/user@1000.service/app.slice/app-gnome-code-173588.scope",
                                       slice: (interface {}) <nil>
                Test:           TestDetectV4LaunchTypeFargate
                Messages:       Resource returned is incorrect
FAIL
FAIL    go.opentelemetry.io/contrib/detectors/aws/ecs/test      0.043s
```

### Expected behavior

The test passes locally



Discussion:
@pyohannes @akats7: PTAL as code owners.
I'm not able to reproduce locally:

```
$ uname -a
Linux xi 6.15.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 19 Jun 2025 14:41:19 +0000 x86_64 GNU/Linux

$ git show
commit f9a279a2e22856e5c4c1456ba0922852978afeab (HEAD -> main, upstream/main, upstream/HEAD, origin/main, origin/HEAD)
```
I was able to reproduce it locally on an Ubuntu VM, it’s been on my list, I’ll address it in the coming days.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89d02c2747f..92f86cde3f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
   - `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`
   - `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`
 
+### Fixed
+
+- Improve the ECS detector correctness in `go.opentelemetry.io/contrib/detectors/aws/ecs`. (#7607)
+
 <!-- Released section -->
 <!-- Don't change this section unless doing release -->
 
diff --git a/detectors/aws/ecs/ecs.go b/detectors/aws/ecs/ecs.go
index a256fb8430f..b2753807664 100644
--- a/detectors/aws/ecs/ecs.go
+++ b/detectors/aws/ecs/ecs.go
@@ -10,6 +10,7 @@ import (
 	"fmt"
 	"net/http"
 	"os"
+	"regexp"
 	"runtime"
 	"strings"
 
@@ -35,6 +36,7 @@ var (
 	errCannotParseTaskArn                 = errors.New("cannot parse region and account ID from the Task's ARN: the ARN does not contain at least 6 segments separated by the ':' character")
 	errCannotRetrieveLogsGroupMetadataV4  = errors.New("the ECS Metadata v4 did not return a AwsLogGroup name")
 	errCannotRetrieveLogsStreamMetadataV4 = errors.New("the ECS Metadata v4 did not return a AwsLogStream name")
+	ecsCgroupPathPattern                  = regexp.MustCompile(`/ecs/[^/]+/[a-f0-9]{64}$`)
 )
 
 // Create interface for methods needing to be mocked.
@@ -246,13 +248,7 @@ func (ecsUtils ecsDetectorUtils) getContainerID() (string, error) {
 		// For example, windows; or when running integration tests outside of a container.
 		return "", nil
 	}
-	splitData := strings.Split(strings.TrimSpace(string(fileData)), "\n")
-	for _, str := range splitData {
-		if len(str) > containerIDLength {
-			return str[len(str)-containerIDLength:], nil
-		}
-	}
-	return "", nil
+	return getCgroupContainerID(fileData), nil
 }
 
 // returns host name reported by the kernel.
@@ -263,3 +259,13 @@ func (ecsUtils ecsDetectorUtils) getContainerName() (string, error) {
 	}
 	return hostName, nil
 }
+
+func getCgroupContainerID(fileData []byte) string {
+	splitData := strings.Split(strings.TrimSpace(string(fileData)), "\n")
+	for _, str := range splitData {
+		if ecsCgroupPathPattern.MatchString(str) {
+			return str[len(str)-containerIDLength:]
+		}
+	}
+	return ""
+}


Test patch:
diff --git a/detectors/aws/ecs/ecs_test.go b/detectors/aws/ecs/ecs_test.go
index 2deb397258a..ede92a48b86 100644
--- a/detectors/aws/ecs/ecs_test.go
+++ b/detectors/aws/ecs/ecs_test.go
@@ -230,3 +230,34 @@ func TestLogsAttributesAlternatePartition(t *testing.T) {
 	}
 	assert.Equal(t, expectedAttributes, actualAttributes, "logs attributes are incorrect")
 }
+
+func TestCgroupContainerID(t *testing.T) {
+	cgroups := []struct {
+		cgroupPath      string
+		wantContainerID string
+	}{
+		{
+			"10:memory:/ecs/my-task-name/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
+			"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
+		},
+		{
+			"10:memory:/ecs/api_service_1/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+			"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+		},
+		{
+			"10:memory:/ecs/my-task-name/12345abc",
+			"",
+		},
+		{
+			"10:memory:/docker/my-task-name/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
+			"",
+		},
+	}
+
+	for _, c := range cgroups {
+		t.Run(c.cgroupPath, func(t *testing.T) {
+			containerID := getCgroupContainerID([]byte(c.cgroupPath))
+			assert.Equal(t, c.wantContainerID, containerID)
+		})
+	}
+}