From 550d365c545467f3c37078a59563f5a30316690d Mon Sep 17 00:00:00 2001 From: Chen Yixiao Date: Mon, 6 Jul 2020 00:32:40 +0800 Subject: [PATCH] fix trace event time conversion from internal to otlp (#896) * fix trace event time conversion from internal to otlp * Enhance the effectiveness of SpanEvent test * Empty --- exporters/otlp/internal/transform/span.go | 2 +- exporters/otlp/internal/transform/span_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/exporters/otlp/internal/transform/span.go b/exporters/otlp/internal/transform/span.go index 4221a53c79b..aa0f560f189 100644 --- a/exporters/otlp/internal/transform/span.go +++ b/exporters/otlp/internal/transform/span.go @@ -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. }, diff --git a/exporters/otlp/internal/transform/span_test.go b/exporters/otlp/internal/transform/span_test.go index 4f7f75ef363..346ff4b4639 100644 --- a/exporters/otlp/internal/transform/span_test.go +++ b/exporters/otlp/internal/transform/span_test.go @@ -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) {