Skip to content

Commit f25aa36

Browse files
committed
fix: prevent IEEE 754 precision loss in OTLP nanosecond timestamps (#3292)
1 parent 5dab2ae commit f25aa36

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Fix IEEE 754 precision loss in OTLP nanosecond timestamps by converting epoch ms to BigInt before multiplication

apps/webapp/app/v3/eventRepository/common.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function extractContextFromCarrier(carrier: Record<string, unknown>) {
2121
}
2222

2323
export function getNowInNanoseconds(): bigint {
24-
return BigInt(new Date().getTime() * 1_000_000);
24+
return BigInt(new Date().getTime()) * BigInt(1_000_000);
2525
}
2626

2727
export function getDateFromNanoseconds(nanoseconds: bigint): Date {
@@ -35,7 +35,7 @@ export function calculateDurationFromStart(
3535
) {
3636
const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime;
3737

38-
const duration = Number(BigInt($endtime.getTime() * 1_000_000) - startTime);
38+
const duration = Number(BigInt($endtime.getTime()) * BigInt(1_000_000) - startTime);
3939

4040
if (minimumDuration && duration < minimumDuration) {
4141
return minimumDuration;

apps/webapp/app/v3/eventRepository/index.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async function recordRunEvent(
215215
runId: foundRun.friendlyId,
216216
...attributes,
217217
},
218-
startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000),
218+
startTime: BigInt(startTime?.getTime() ?? Date.now()) * BigInt(1_000_000),
219219
...optionsRest,
220220
});
221221

apps/webapp/app/v3/runEngineHandlers.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export function registerRunEngineEventBusHandlers() {
429429
const eventRepository = resolveEventRepositoryForStore(run.taskEventStore);
430430

431431
await eventRepository.recordEvent(retryMessage, {
432-
startTime: BigInt(time.getTime() * 1000000),
432+
startTime: BigInt(time.getTime()) * BigInt(1_000_000),
433433
taskSlug: run.taskIdentifier,
434434
environment,
435435
attributes: {

0 commit comments

Comments
 (0)