@@ -156,7 +156,7 @@ export class ClickhouseEventRepository implements IEventRepository {
156
156
task_identifier : event . taskSlug ,
157
157
run_id : event . runId ,
158
158
start_time : formatClickhouseDate64NanosecondsEpochString ( event . startTime . toString ( ) ) ,
159
- duration : ( event . duration ?? 0 ) . toString ( ) ,
159
+ duration : formatClickhouseUnsignedIntegerString ( event . duration ?? 0 ) ,
160
160
trace_id : event . traceId ,
161
161
span_id : event . spanId ,
162
162
parent_span_id : event . parentId ?? "" ,
@@ -432,7 +432,9 @@ export class ClickhouseEventRepository implements IEventRepository {
432
432
const startTime = options . startTime ?? getNowInNanoseconds ( ) ;
433
433
const duration =
434
434
options . duration ??
435
- ( options . endTime ? calculateDurationFromStart ( startTime , options . endTime ) : 100 ) ;
435
+ ( options . endTime
436
+ ? calculateDurationFromStart ( startTime , options . endTime , 100 * 1_000_000 )
437
+ : 100 ) ;
436
438
437
439
const traceId = propagatedContext ?. traceparent ?. traceId ?? generateTraceId ( ) ;
438
440
const parentId = options . parentId ?? propagatedContext ?. traceparent ?. spanId ;
@@ -460,7 +462,7 @@ export class ClickhouseEventRepository implements IEventRepository {
460
462
task_identifier : options . taskSlug ,
461
463
run_id : options . attributes . runId ,
462
464
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
463
- duration : duration . toString ( ) ,
465
+ duration : formatClickhouseUnsignedIntegerString ( duration ) ,
464
466
trace_id : traceId ,
465
467
span_id : spanId ,
466
468
parent_span_id : parentId ?? "" ,
@@ -561,7 +563,7 @@ export class ClickhouseEventRepository implements IEventRepository {
561
563
task_identifier : options . taskSlug ,
562
564
run_id : options . attributes . runId ,
563
565
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
564
- duration : String ( options . incomplete ? 0 : duration ) ,
566
+ duration : formatClickhouseUnsignedIntegerString ( options . incomplete ? 0 : duration ) ,
565
567
trace_id : traceId ,
566
568
span_id : spanId ,
567
569
parent_span_id : parentId ?? "" ,
@@ -595,7 +597,7 @@ export class ClickhouseEventRepository implements IEventRepository {
595
597
task_identifier : options . taskSlug ,
596
598
run_id : options . attributes . runId ,
597
599
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
598
- duration : String ( options . incomplete ? 0 : duration ) ,
600
+ duration : formatClickhouseUnsignedIntegerString ( options . incomplete ? 0 : duration ) ,
599
601
trace_id : traceId ,
600
602
span_id : spanId ,
601
603
parent_span_id : parentId ?? "" ,
@@ -644,7 +646,9 @@ export class ClickhouseEventRepository implements IEventRepository {
644
646
task_identifier : run . taskIdentifier ,
645
647
run_id : run . friendlyId ,
646
648
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
647
- duration : calculateDurationFromStart ( startTime , endTime ?? new Date ( ) ) . toString ( ) ,
649
+ duration : formatClickhouseUnsignedIntegerString (
650
+ calculateDurationFromStart ( startTime , endTime ?? new Date ( ) )
651
+ ) ,
648
652
trace_id : run . traceId ,
649
653
span_id : run . spanId ,
650
654
parent_span_id : run . parentSpanId ?? "" ,
@@ -692,7 +696,9 @@ export class ClickhouseEventRepository implements IEventRepository {
692
696
task_identifier : run . taskIdentifier ,
693
697
run_id : blockedRun . friendlyId ,
694
698
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
695
- duration : calculateDurationFromStart ( startTime , endTime ?? new Date ( ) ) . toString ( ) ,
699
+ duration : formatClickhouseUnsignedIntegerString (
700
+ calculateDurationFromStart ( startTime , endTime ?? new Date ( ) )
701
+ ) ,
696
702
trace_id : blockedRun . traceId ,
697
703
span_id : spanId ,
698
704
parent_span_id : parentSpanId ,
@@ -732,7 +738,9 @@ export class ClickhouseEventRepository implements IEventRepository {
732
738
task_identifier : run . taskIdentifier ,
733
739
run_id : run . friendlyId ,
734
740
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
735
- duration : calculateDurationFromStart ( startTime , endTime ?? new Date ( ) ) . toString ( ) ,
741
+ duration : formatClickhouseUnsignedIntegerString (
742
+ calculateDurationFromStart ( startTime , endTime ?? new Date ( ) )
743
+ ) ,
736
744
trace_id : run . traceId ,
737
745
span_id : run . spanId ,
738
746
parent_span_id : run . parentSpanId ?? "" ,
@@ -778,7 +786,9 @@ export class ClickhouseEventRepository implements IEventRepository {
778
786
task_identifier : run . taskIdentifier ,
779
787
run_id : run . friendlyId ,
780
788
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
781
- duration : calculateDurationFromStart ( startTime , endTime ?? new Date ( ) ) . toString ( ) ,
789
+ duration : formatClickhouseUnsignedIntegerString (
790
+ calculateDurationFromStart ( startTime , endTime ?? new Date ( ) )
791
+ ) ,
782
792
trace_id : run . traceId ,
783
793
span_id : run . spanId ,
784
794
parent_span_id : run . parentSpanId ?? "" ,
@@ -868,7 +878,9 @@ export class ClickhouseEventRepository implements IEventRepository {
868
878
task_identifier : run . taskIdentifier ,
869
879
run_id : run . friendlyId ,
870
880
start_time : formatClickhouseDate64NanosecondsEpochString ( startTime . toString ( ) ) ,
871
- duration : calculateDurationFromStart ( startTime , cancelledAt ) . toString ( ) ,
881
+ duration : formatClickhouseUnsignedIntegerString (
882
+ calculateDurationFromStart ( startTime , cancelledAt )
883
+ ) ,
872
884
trace_id : run . traceId ,
873
885
span_id : run . spanId ,
874
886
parent_span_id : run . parentSpanId ?? "" ,
@@ -1841,3 +1853,15 @@ function convertClickhouseDate64NanosecondsEpochStringToBigInt(date: string): bi
1841
1853
const parts = date . split ( "." ) ;
1842
1854
return BigInt ( parts . join ( "" ) ) ;
1843
1855
}
1856
+
1857
+ function formatClickhouseUnsignedIntegerString ( value : number | bigint ) : string {
1858
+ if ( value < 0 ) {
1859
+ return "0" ;
1860
+ }
1861
+
1862
+ if ( typeof value === "bigint" ) {
1863
+ return value . toString ( ) ;
1864
+ }
1865
+
1866
+ return Math . floor ( value ) . toString ( ) ;
1867
+ }
0 commit comments