Skip to content

Commit

Permalink
ddtrace/tracer: Add test for env on spans (#1135)
Browse files Browse the repository at this point in the history
While investigating how to save some memory allocations in StartSpan
I noticed that the code that sets the "env" tag did not appear to be
triggered by any test cases. Add a test based on the version test.
  • Loading branch information
evanj authored and Hellzy committed Feb 10, 2022
1 parent 773b4aa commit 35ce32e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ddtrace/tracer/tracer_test.go
Expand Up @@ -1373,6 +1373,28 @@ func TestVersion(t *testing.T) {
})
}

func TestEnvironment(t *testing.T) {
t.Run("normal", func(t *testing.T) {
tracer, _, _, stop := startTestTracer(t, WithEnv("test"))
defer stop()

assert := assert.New(t)
sp := tracer.StartSpan("http.request").(*span)
v := sp.Meta[ext.Environment]
assert.Equal("test", v)
})

t.Run("unset", func(t *testing.T) {
tracer, _, _, stop := startTestTracer(t)
defer stop()

assert := assert.New(t)
sp := tracer.StartSpan("http.request").(*span)
_, ok := sp.Meta[ext.Environment]
assert.False(ok)
})
}

// BenchmarkConcurrentTracing tests the performance of spawning a lot of
// goroutines where each one creates a trace with a parent and a child.
func BenchmarkConcurrentTracing(b *testing.B) {
Expand Down

0 comments on commit 35ce32e

Please sign in to comment.