Skip to content

Commit

Permalink
fix trace event time conversion from internal to otlp (#896)
Browse files Browse the repository at this point in the history
* fix trace event time conversion from internal to otlp

* Enhance the effectiveness of SpanEvent test

* Empty
  • Loading branch information
tensorchen authored Jul 5, 2020
1 parent f1e3536 commit 550d365
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion exporters/otlp/internal/transform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func spanEvents(es []export.Event) []*tracepb.Span_Event {
events = append(events,
&tracepb.Span_Event{
Name: e.Name,
TimeUnixNano: uint64(e.Time.Nanosecond()),
TimeUnixNano: uint64(e.Time.UnixNano()),
Attributes: Attributes(e.Attributes),
// TODO (rghetia) : Add Drop Counts when supported.
},
Expand Down
12 changes: 6 additions & 6 deletions exporters/otlp/internal/transform/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,26 @@ func TestEmptySpanEvent(t *testing.T) {

func TestSpanEvent(t *testing.T) {
attrs := []kv.KeyValue{kv.Int("one", 1), kv.Int("two", 2)}
now := time.Now()
eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
got := spanEvents([]export.Event{
{
Name: "test 1",
Attributes: []kv.KeyValue{},
Time: now,
Time: eventTime,
},
{
Name: "test 2",
Attributes: attrs,
Time: now,
Time: eventTime,
},
})
if !assert.Len(t, got, 2) {
return
}
uNow := uint64(now.Nanosecond())
assert.Equal(t, &tracepb.Span_Event{Name: "test 1", Attributes: nil, TimeUnixNano: uNow}, got[0])
eventTimestamp := uint64(1589932800 * 1e9)
assert.Equal(t, &tracepb.Span_Event{Name: "test 1", Attributes: nil, TimeUnixNano: eventTimestamp}, got[0])
// Do not test Attributes directly, just that the return value goes to the correct field.
assert.Equal(t, &tracepb.Span_Event{Name: "test 2", Attributes: Attributes(attrs), TimeUnixNano: uNow}, got[1])
assert.Equal(t, &tracepb.Span_Event{Name: "test 2", Attributes: Attributes(attrs), TimeUnixNano: eventTimestamp}, got[1])
}

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

0 comments on commit 550d365

Please sign in to comment.