Skip to content

Commit e657fc8

Browse files
committed
fix(internal/telemetry): run TestNoEmptyHeaders only when we are running in the right environment
1 parent d0985c4 commit e657fc8

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

ddtrace/tracer/transport_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,30 @@ func TestWithUDS(t *testing.T) {
396396
assert.Len(rt.reqs, 1)
397397
assert.Equal(hits, 2)
398398
}
399+
400+
func TestExternalEnvironment(t *testing.T) {
401+
t.Setenv("DD_EXTERNAL_ENV", "it-false,cn-nginx-webserver,pu-75a2b6d5-3949-4afb-ad0d-92ff0674e759")
402+
assert := assert.New(t)
403+
found := false
404+
srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
405+
extEnv := r.Header.Get("Datadog-External-Env")
406+
if extEnv == "" {
407+
return
408+
}
409+
assert.Equal("it-false,cn-nginx-webserver,pu-75a2b6d5-3949-4afb-ad0d-92ff0674e759", extEnv)
410+
found = true
411+
}))
412+
defer srv.Close()
413+
414+
u, err := url.Parse(srv.URL)
415+
assert.NoError(err)
416+
c := &http.Client{}
417+
trc := newTracer(WithAgentTimeout(2), WithAgentAddr(u.Host), WithHTTPClient(c))
418+
defer trc.Stop()
419+
420+
p, err := encode(getTestTrace(1, 1))
421+
assert.NoError(err)
422+
_, err = trc.config.transport.send(p)
423+
assert.NoError(err)
424+
assert.True(found)
425+
}

internal/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func BoolVal(val string, def bool) bool {
134134
return v
135135
}
136136

137+
// ExternalEnvironment returns the value of the DD_EXTERNAL_ENV environment variable.
137138
func ExternalEnvironment() string {
138139
return os.Getenv("DD_EXTERNAL_ENV")
139140
}

internal/telemetry/client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import (
1111
"net/http"
1212
"net/http/httptest"
1313
"reflect"
14+
"runtime"
1415
"sort"
1516
"sync"
1617
"testing"
1718
"time"
1819

1920
"github.com/stretchr/testify/assert"
2021

22+
"gopkg.in/DataDog/dd-trace-go.v1/internal"
2123
logging "gopkg.in/DataDog/dd-trace-go.v1/internal/log"
2224
)
2325

@@ -439,11 +441,18 @@ func Test_heartbeatInterval(t *testing.T) {
439441
}
440442

441443
func TestNoEmptyHeaders(t *testing.T) {
444+
if runtime.GOOS != "linux" {
445+
t.Skip("skipping test on non-linux OS")
446+
}
447+
if internal.EntityID() == "" || internal.ContainerID() == "" {
448+
t.Skip("skipping test when entity ID and container ID are not available")
449+
}
442450
c := &client{}
443451
req := c.newRequest(RequestTypeAppStarted)
444452
assertNotEmpty := func(header string) {
445453
headers := *req.Header
446454
vals := headers[header]
455+
assert.Greater(t, len(vals), 0, "header %s should not be empty", header)
447456
for _, v := range vals {
448457
assert.NotEmpty(t, v, "%s header should not be empty", header)
449458
}

0 commit comments

Comments
 (0)