Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trace jaeger conversion to internal traces zero time bug #1957

Merged
merged 4 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions consumer/pdata/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ func UnixNanoToTime(u TimestampUnixNano) time.Time {
}
return time.Unix(0, int64(u)).UTC()
}

func TimeToUnixNano(t time.Time) TimestampUnixNano {
// 0 is a special case and want to make sure we return zero timestamp to support inverse function for UnixNanoToTime
if t.IsZero() {
return 0
}
return TimestampUnixNano(uint64(t.UnixNano()))
}
3 changes: 3 additions & 0 deletions consumer/pdata/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ func TestUnixNanosConverters(t *testing.T) {
tp := UnixNanoToTimestamp(tun)
assert.EqualValues(t, &timestamppb.Timestamp{Seconds: 1585012403, Nanos: 789}, tp)
assert.EqualValues(t, tun, TimestampToUnixNano(tp))
assert.EqualValues(t, tun, TimeToUnixNano(t1))
assert.EqualValues(t, t1, UnixNanoToTime(TimeToUnixNano(t1)))
}

func TestZeroTimestamps(t *testing.T) {
assert.Zero(t, TimestampToUnixNano(nil))
assert.Nil(t, UnixNanoToTimestamp(0))
assert.True(t, UnixNanoToTime(0).IsZero())
assert.Zero(t, TimeToUnixNano(time.Time{}))
}
4 changes: 2 additions & 2 deletions translator/trace/jaeger/jaegerproto_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func jSpanToInternal(span *model.Span) (pdata.Span, instrumentationLibrary) {
dest.SetTraceID(tracetranslator.UInt64ToTraceID(span.TraceID.High, span.TraceID.Low))
dest.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(span.SpanID)))
dest.SetName(span.OperationName)
dest.SetStartTime(pdata.TimestampUnixNano(uint64(span.StartTime.UnixNano())))
dest.SetEndTime(pdata.TimestampUnixNano(uint64(span.StartTime.Add(span.Duration).UnixNano())))
dest.SetStartTime(pdata.TimeToUnixNano(span.StartTime))
dest.SetEndTime(pdata.TimeToUnixNano(span.StartTime.Add(span.Duration)))

parentSpanID := span.ParentSpanID()
if parentSpanID != model.SpanID(0) {
Expand Down