Skip to content

Commit

Permalink
internal/telemetry: do not send empty container and entity headers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mez authored and katiehockman committed Jan 16, 2024
1 parent 6f544fc commit 4e91e50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,12 @@ func (c *client) newRequest(t RequestType) *Request {
"DD-Client-Library-Version": {version.Tag},
"DD-Agent-Env": {c.Env},
"DD-Agent-Hostname": {hostname},
"Datadog-Container-ID": {internal.ContainerID()},
"Datadog-Entity-ID": {internal.EntityID()},
}
if cid := internal.ContainerID(); cid != "" {
header.Set("Datadog-Container-ID", cid)
}
if eid := internal.EntityID(); eid != "" {
header.Set("Datadog-Entity-ID", eid)
}
if c.URL == getAgentlessURL() {
header.Set("DD-API-KEY", c.APIKey)
Expand Down
14 changes: 14 additions & 0 deletions internal/telemetry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,17 @@ func Test_heartbeatInterval(t *testing.T) {
})
}
}

func TestNoEmptyHeaders(t *testing.T) {
c := &client{}
req := c.newRequest(RequestTypeAppStarted)
assertNotEmpty := func(header string) {
headers := *req.Header
vals := headers[header]
for _, v := range vals {
assert.NotEmpty(t, v, "%s header should not be empty", header)
}
}
assertNotEmpty("Datadog-Container-ID")
assertNotEmpty("Datadog-Entity-ID")
}

0 comments on commit 4e91e50

Please sign in to comment.