Skip to content

Commit

Permalink
tracer: verify that hostname reporting is honored regardless of stats…
Browse files Browse the repository at this point in the history
… calculation (#2533)
  • Loading branch information
katiehockman authored Jan 31, 2024
1 parent 8c4834f commit e707cc9
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,44 +1627,54 @@ func TestTracerFlush(t *testing.T) {
func TestTracerReportsHostname(t *testing.T) {
const hostname = "hostname-test"

t.Run("DD_TRACE_REPORT_HOSTNAME/set", func(t *testing.T) {
t.Setenv("DD_TRACE_REPORT_HOSTNAME", "true")
testReportHostnameEnabled := func(t *testing.T, name string, withComputeStats bool) {
t.Run(name, func(t *testing.T) {
t.Setenv("DD_TRACE_REPORT_HOSTNAME", "true")
t.Setenv("DD_TRACE_COMPUTE_STATS", fmt.Sprintf("%t", withComputeStats))

tracer, _, _, stop := startTestTracer(t)
defer stop()

root := tracer.StartSpan("root").(*span)
child := tracer.StartSpan("child", ChildOf(root.Context())).(*span)
child.Finish()
root.Finish()

assert := assert.New(t)

name, ok := root.Meta[keyHostname]
assert.True(ok)
assert.Equal(name, tracer.config.hostname)

name, ok = child.Meta[keyHostname]
assert.True(ok)
assert.Equal(name, tracer.config.hostname)
})
tracer, _, _, stop := startTestTracer(t)
defer stop()

t.Run("DD_TRACE_REPORT_HOSTNAME/unset", func(t *testing.T) {
tracer, _, _, stop := startTestTracer(t)
defer stop()
root := tracer.StartSpan("root").(*span)
child := tracer.StartSpan("child", ChildOf(root.Context())).(*span)
child.Finish()
root.Finish()

root := tracer.StartSpan("root").(*span)
child := tracer.StartSpan("child", ChildOf(root.Context())).(*span)
child.Finish()
root.Finish()
assert := assert.New(t)

assert := assert.New(t)
name, ok := root.Meta[keyHostname]
assert.True(ok)
assert.Equal(name, tracer.config.hostname)

_, ok := root.Meta[keyHostname]
assert.False(ok)
_, ok = child.Meta[keyHostname]
assert.False(ok)
})
name, ok = child.Meta[keyHostname]
assert.True(ok)
assert.Equal(name, tracer.config.hostname)
})
}
testReportHostnameEnabled(t, "DD_TRACE_REPORT_HOSTNAME/set,DD_TRACE_COMPUTE_STATS/true", true)
testReportHostnameEnabled(t, "DD_TRACE_REPORT_HOSTNAME/set,DD_TRACE_COMPUTE_STATS/false", false)

testReportHostnameDisabled := func(t *testing.T, name string, withComputeStats bool) {
t.Run(name, func(t *testing.T) {
t.Setenv("DD_TRACE_COMPUTE_STATS", fmt.Sprintf("%t", withComputeStats))
tracer, _, _, stop := startTestTracer(t)
defer stop()

root := tracer.StartSpan("root").(*span)
child := tracer.StartSpan("child", ChildOf(root.Context())).(*span)
child.Finish()
root.Finish()

assert := assert.New(t)

_, ok := root.Meta[keyHostname]
assert.False(ok)
_, ok = child.Meta[keyHostname]
assert.False(ok)
})
}
testReportHostnameDisabled(t, "DD_TRACE_REPORT_HOSTNAME/unset,DD_TRACE_COMPUTE_STATS/true", true)
testReportHostnameDisabled(t, "DD_TRACE_REPORT_HOSTNAME/unset,DD_TRACE_COMPUTE_STATS/false", false)

t.Run("WithHostname", func(t *testing.T) {
tracer, _, _, stop := startTestTracer(t, WithHostname(hostname))
Expand Down

0 comments on commit e707cc9

Please sign in to comment.