diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2d620c729..27e911e66bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added -- Adding `ot-tracer` propagator (#562) +- Add `ot-tracer` propagator (#562) ### Changed - Rename project default branch from `master` to `main`. +### Fixed + +- Added failure message for AWS ECS resource detector for better debugging (#568) + ## [0.16.0] - 2021-01-13 ### Fixed diff --git a/detectors/aws/ecs/ecs.go b/detectors/aws/ecs/ecs.go index dcc11955b91..1bf477345d1 100644 --- a/detectors/aws/ecs/ecs.go +++ b/detectors/aws/ecs/ecs.go @@ -35,10 +35,11 @@ const ( ) var ( - empty = resource.Empty() - errCannotReadContainerID = errors.New("failed to read container ID from cGroupFile") - errCannotReadCGroupFile = errors.New("ECS resource detector failed to read cGroupFile") - errNotOnECS = errors.New("process is not on ECS, cannot detect environment variables from ECS") + empty = resource.Empty() + errCannotReadContainerID = errors.New("failed to read container ID from cGroupFile") + errCannotReadContainerName = errors.New("failed to read hostname") + errCannotReadCGroupFile = errors.New("ECS resource detector failed to read cGroupFile") + errNotOnECS = errors.New("process is not on ECS, cannot detect environment variables from ECS") ) // Create interface for methods needing to be mocked @@ -102,5 +103,9 @@ func (ecsUtils ecsDetectorUtils) getContainerID() (string, error) { // returns host name reported by the kernel func (ecsUtils ecsDetectorUtils) getContainerName() (string, error) { - return os.Hostname() + hostName, err := os.Hostname() + if err != nil { + return "", errCannotReadContainerName + } + return hostName, nil } diff --git a/detectors/aws/ecs/ecs_test.go b/detectors/aws/ecs/ecs_test.go index 85cbb131288..7d667c35f3b 100644 --- a/detectors/aws/ecs/ecs_test.go +++ b/detectors/aws/ecs/ecs_test.go @@ -81,6 +81,23 @@ func TestDetectCannotReadContainerID(t *testing.T) { assert.Equal(t, 0, len(resource.Attributes())) } +//returns empty resource when detector cannot read container Name +func TestDetectCannotReadContainerName(t *testing.T) { + os.Clearenv() + os.Setenv(metadataV3EnvVar, "3") + os.Setenv(metadataV4EnvVar, "4") + detectorUtils := new(MockDetectorUtils) + + detectorUtils.On("getContainerName").Return("", errCannotReadContainerName) + detectorUtils.On("getContainerID").Return("0123456789A", nil) + + detector := ResourceDetector{detectorUtils} + resource, err := detector.Detect(context.Background()) + + assert.Equal(t, errCannotReadContainerName, err) + assert.Equal(t, 0, len(resource.Attributes())) +} + //returns empty resource when process is not running ECS func TestReturnsIfNoEnvVars(t *testing.T) { os.Clearenv()