File tree 3 files changed +32
-6
lines changed
3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
10
10
11
11
### Added
12
12
13
- - Adding ` ot-tracer ` propagator (#562 )
13
+ - Add ` ot-tracer ` propagator (#562 )
14
14
15
15
### Changed
16
16
17
17
- Rename project default branch from ` master ` to ` main ` .
18
18
19
+ ### Fixed
20
+
21
+ - Added failure message for AWS ECS resource detector for better debugging (#568 )
22
+
19
23
## [ 0.16.0] - 2021-01-13
20
24
21
25
### Fixed
Original file line number Diff line number Diff line change @@ -35,10 +35,11 @@ const (
35
35
)
36
36
37
37
var (
38
- empty = resource .Empty ()
39
- errCannotReadContainerID = errors .New ("failed to read container ID from cGroupFile" )
40
- errCannotReadCGroupFile = errors .New ("ECS resource detector failed to read cGroupFile" )
41
- errNotOnECS = errors .New ("process is not on ECS, cannot detect environment variables from ECS" )
38
+ empty = resource .Empty ()
39
+ errCannotReadContainerID = errors .New ("failed to read container ID from cGroupFile" )
40
+ errCannotReadContainerName = errors .New ("failed to read hostname" )
41
+ errCannotReadCGroupFile = errors .New ("ECS resource detector failed to read cGroupFile" )
42
+ errNotOnECS = errors .New ("process is not on ECS, cannot detect environment variables from ECS" )
42
43
)
43
44
44
45
// Create interface for methods needing to be mocked
@@ -102,5 +103,9 @@ func (ecsUtils ecsDetectorUtils) getContainerID() (string, error) {
102
103
103
104
// returns host name reported by the kernel
104
105
func (ecsUtils ecsDetectorUtils ) getContainerName () (string , error ) {
105
- return os .Hostname ()
106
+ hostName , err := os .Hostname ()
107
+ if err != nil {
108
+ return "" , errCannotReadContainerName
109
+ }
110
+ return hostName , nil
106
111
}
Original file line number Diff line number Diff line change @@ -81,6 +81,23 @@ func TestDetectCannotReadContainerID(t *testing.T) {
81
81
assert .Equal (t , 0 , len (resource .Attributes ()))
82
82
}
83
83
84
+ //returns empty resource when detector cannot read container Name
85
+ func TestDetectCannotReadContainerName (t * testing.T ) {
86
+ os .Clearenv ()
87
+ os .Setenv (metadataV3EnvVar , "3" )
88
+ os .Setenv (metadataV4EnvVar , "4" )
89
+ detectorUtils := new (MockDetectorUtils )
90
+
91
+ detectorUtils .On ("getContainerName" ).Return ("" , errCannotReadContainerName )
92
+ detectorUtils .On ("getContainerID" ).Return ("0123456789A" , nil )
93
+
94
+ detector := ResourceDetector {detectorUtils }
95
+ resource , err := detector .Detect (context .Background ())
96
+
97
+ assert .Equal (t , errCannotReadContainerName , err )
98
+ assert .Equal (t , 0 , len (resource .Attributes ()))
99
+ }
100
+
84
101
//returns empty resource when process is not running ECS
85
102
func TestReturnsIfNoEnvVars (t * testing.T ) {
86
103
os .Clearenv ()
You can’t perform that action at this time.
0 commit comments