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

Commit 5969dfb

Browse files
committed
Ensure that span start <= end
Adds code to detect when a span's end time is less than its start time. This would be caught by a database constraint and prevent the insertion of the span. The new code will swap the start and end times to allow the span's insertion.
1 parent aa71c47 commit 5969dfb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ We use the following categories for changes:
2323
### Fixed
2424
- Fix broken `promscale_packager` telemetry field for docker envs [#1077]
2525
- Fix compression of old chunks thus reducing storage requirements [#1081]
26+
- Fix spans with end < start. Start and end are swapped in this case. [#1096]
2627

2728
## [0.8.0] - 2022-01-18
2829

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)