Skip to content

Commit

Permalink
fix(internal/telemetry): run TestNoEmptyHeaders only when we are runn…
Browse files Browse the repository at this point in the history
…ing in the right environment
  • Loading branch information
darccio committed Feb 3, 2025
1 parent d0985c4 commit e657fc8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ddtrace/tracer/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,30 @@ func TestWithUDS(t *testing.T) {
assert.Len(rt.reqs, 1)
assert.Equal(hits, 2)
}

func TestExternalEnvironment(t *testing.T) {
t.Setenv("DD_EXTERNAL_ENV", "it-false,cn-nginx-webserver,pu-75a2b6d5-3949-4afb-ad0d-92ff0674e759")
assert := assert.New(t)
found := false
srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
extEnv := r.Header.Get("Datadog-External-Env")
if extEnv == "" {
return
}
assert.Equal("it-false,cn-nginx-webserver,pu-75a2b6d5-3949-4afb-ad0d-92ff0674e759", extEnv)
found = true
}))
defer srv.Close()

u, err := url.Parse(srv.URL)
assert.NoError(err)
c := &http.Client{}
trc := newTracer(WithAgentTimeout(2), WithAgentAddr(u.Host), WithHTTPClient(c))
defer trc.Stop()

p, err := encode(getTestTrace(1, 1))
assert.NoError(err)
_, err = trc.config.transport.send(p)
assert.NoError(err)
assert.True(found)
}
1 change: 1 addition & 0 deletions internal/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func BoolVal(val string, def bool) bool {
return v
}

// ExternalEnvironment returns the value of the DD_EXTERNAL_ENV environment variable.
func ExternalEnvironment() string {
return os.Getenv("DD_EXTERNAL_ENV")
}
9 changes: 9 additions & 0 deletions internal/telemetry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"runtime"
"sort"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"

"gopkg.in/DataDog/dd-trace-go.v1/internal"
logging "gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)

Expand Down Expand Up @@ -439,11 +441,18 @@ func Test_heartbeatInterval(t *testing.T) {
}

func TestNoEmptyHeaders(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("skipping test on non-linux OS")
}
if internal.EntityID() == "" || internal.ContainerID() == "" {
t.Skip("skipping test when entity ID and container ID are not available")
}
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)
}
Expand Down

0 comments on commit e657fc8

Please sign in to comment.