Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 8381cf3

Browse files
committed
Ensure that span start <= end
1 parent aa71c47 commit 8381cf3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/pgmodel/ingestor/trace/writer.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,23 @@ func (t *traceWriterImpl) InsertTraces(ctx context.Context, traces pdata.Traces)
265265

266266
eventTimeRange := getEventTimeRange(span.Events())
267267

268+
// postgresql timestamptz only has microsecond precision while time.Time has nanosecond precision
269+
start := span.StartTimestamp().AsTime().Truncate(time.Microsecond)
270+
end := span.EndTimestamp().AsTime().Truncate(time.Microsecond)
271+
// make sure start <= end
272+
if end.Before(start) {
273+
start, end = end, start
274+
}
275+
268276
spanBatch.Queue(
269277
insertSpanSQL,
270278
traceID,
271279
spanID,
272280
getTraceStateValue(span.TraceState()),
273281
parentSpanID,
274282
operationID,
275-
span.StartTimestamp().AsTime(),
276-
span.EndTimestamp().AsTime(),
283+
start,
284+
end,
277285
string(jsonTags),
278286
span.DroppedAttributesCount(),
279287
eventTimeRange,

0 commit comments

Comments
 (0)