Skip to content

Commit

Permalink
ddtrace/tracer: test for different values of source
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm committed Dec 11, 2024
1 parent 24ad484 commit a8f097d
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions ddtrace/tracer/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
package tracer

import (
"slices"
"testing"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
globalinternal "gopkg.in/DataDog/dd-trace-go.v1/internal"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -64,24 +66,49 @@ func TestReportHealthMetrics(t *testing.T) {
}

func TestSpansStartedTags(t *testing.T) {
assert := assert.New(t)

var tg statsdtest.TestStatsdClient

defer func(old time.Duration) { statsInterval = old }(statsInterval)
statsInterval = time.Nanosecond

tracer, _, _, stop := startTestTracer(t, withStatsdClient(&tg))
defer stop()

tracer.StartSpan("operation").Finish()

tg.Wait(assert, 1, 10*time.Second)

counts := tg.Counts()
assert.Equal(int64(1), counts["datadog.tracer.spans_started"])
calls := tg.CountCalls()
assert.Contains(calls[0].Tags, "source:manual")
statsInterval = time.Millisecond

t.Run("default", func(t *testing.T) {
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, withStatsdClient(&tg))
defer stop()

tracer.StartSpan("operation").Finish()

tg.Wait(assert, 1, 100*time.Millisecond)

counts := tg.Counts()
assert.Equal(int64(1), counts["datadog.tracer.spans_started"])
for _, c := range tg.CountCalls() {
if slices.Equal(c.Tags, []string{"source:manual"}) {
return
}
}
assert.Fail("expected source:manual tag in spans_started")
})

t.Run("other_source", func(t *testing.T) {
tg.Reset()
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, withStatsdClient(&tg))
defer stop()

tracer.StartSpan("operation", Tag(ext.Component, "contrib")).Finish()
tg.Wait(assert, 1, 100*time.Millisecond)

counts := tg.Counts()
assert.Equal(int64(1), counts["datadog.tracer.spans_started"])
for _, c := range tg.CountCalls() {
if slices.Equal(c.Tags, []string{"source:contrib"}) {
return
}
}
assert.Fail("expected source:contrib tag in spans_started")

})
}

func TestTracerMetrics(t *testing.T) {
Expand Down

0 comments on commit a8f097d

Please sign in to comment.