From 35ce32e6b0fa9033fe0851f9ff6fc31fec86383d Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 10 Feb 2022 08:04:59 -0500 Subject: [PATCH] ddtrace/tracer: Add test for env on spans (#1135) 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. --- ddtrace/tracer/tracer_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ddtrace/tracer/tracer_test.go b/ddtrace/tracer/tracer_test.go index 90fbcacb0c..4be33eb93c 100644 --- a/ddtrace/tracer/tracer_test.go +++ b/ddtrace/tracer/tracer_test.go @@ -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) {