Skip to content

Commit

Permalink
feat(internal/telemetry): add Datadog-External-Env default HTTP header
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed Jan 28, 2025
1 parent d0985c4 commit 814d0ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ func (c *client) newRequest(t RequestType) *Request {
if eid := internal.EntityID(); eid != "" {
header.Set("Datadog-Entity-ID", eid)
}
if extEnv := internal.ExternalEnvironment(); extEnv != "" {
header.Set("Datadog-External-Env", extEnv)
}
if c.URL == getAgentlessURL() {
header.Set("DD-API-KEY", c.APIKey)
}
Expand Down
11 changes: 9 additions & 2 deletions internal/telemetry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"runtime"
"sort"
"sync"
"testing"
Expand Down Expand Up @@ -439,17 +440,23 @@ func Test_heartbeatInterval(t *testing.T) {
}

func TestNoEmptyHeaders(t *testing.T) {
t.Setenv("DD_EXTERNAL_ENV", "it-false,cn-nginx-webserver,pu-75a2b6d5-3949-4afb-ad0d-92ff0674e759")
c := &client{}
req := c.newRequest(RequestTypeAppStarted)
assertNotEmpty := func(header string) {
headers := *req.Header
vals := headers[header]
assert.Greater(t, len(vals), 0, "header %s should not be empty", header)
for _, v := range vals {
assert.NotEmpty(t, v, "%s header should not be empty", header)
}
}
assertNotEmpty("Datadog-Container-ID")
assertNotEmpty("Datadog-Entity-ID")
if runtime.GOOS == "linux" {
// These headers are only set on Linux
assertNotEmpty("Datadog-Container-ID")
assertNotEmpty("Datadog-Entity-ID")
}
assertNotEmpty("Datadog-External-Env")
}

func TestTelementryClientLogging(t *testing.T) {
Expand Down

0 comments on commit 814d0ba

Please sign in to comment.