Skip to content

Commit

Permalink
Added tests to ensure timestamp precision is at nanoseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Jul 15, 2024
1 parent 699d744 commit 4f6dc1a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ddtrace/opentelemetry/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,19 @@ func TestSpanAddEvent(t *testing.T) {
})
t.Run("event with timestamp", func(t *testing.T) {
_, sp := tr.Start(context.Background(), "span_event")
// generate micro and nano second timestamps
now := time.Now()
sp.AddEvent("My event!", oteltrace.WithTimestamp(now))
timeMicro := now.UnixMicro()
timeNano := now.UnixNano()
// pass microsecond timestamp into timestamp option
sp.AddEvent("My event!", oteltrace.WithTimestamp(time.UnixMicro(timeMicro)))
sp.End()

dd := sp.(*span)
assert.Len(dd.events, 1)
e := dd.events[0]
assert.Equal(e.TimeUnixNano, now.UnixNano())
// assert resulting timestamp is in nanoseconds
assert.Equal(e.TimeUnixNano, timeNano)
})
t.Run("mulitple events", func(t *testing.T) {
_, sp := tr.Start(context.Background(), "sp")
Expand Down

0 comments on commit 4f6dc1a

Please sign in to comment.