@@ -1696,7 +1696,7 @@ export class ClickhouseEventRepository implements IEventRepository {
16961696 traceId : string ,
16971697 startCreatedAt : Date ,
16981698 endCreatedAt ?: Date ,
1699- options ?: { includeDebugLogs ?: boolean ; anchorSpanId ?: string }
1699+ options ?: { includeDebugLogs ?: boolean ; anchorSpanId ?: string ; insertedAtEnd ?: Date }
17001700 ) : Promise < TraceSummary | undefined > {
17011701 const limit = this . _config . maximumTraceSummaryViewCount ;
17021702 const records = await this . #fetchTraceSummaryRecords( {
@@ -1741,7 +1741,7 @@ export class ClickhouseEventRepository implements IEventRepository {
17411741 anchorSpanId : string ,
17421742 startCreatedAt : Date ,
17431743 endCreatedAt ?: Date ,
1744- options ?: { includeDebugLogs ?: boolean }
1744+ options ?: { includeDebugLogs ?: boolean ; insertedAtEnd ?: Date }
17451745 ) : Promise < TraceSummary | undefined > {
17461746 const { records, isTruncated, missingAnchor } = await this . #fetchTraceSubtreeRecords( {
17471747 environmentId,
@@ -1927,6 +1927,17 @@ export class ClickhouseEventRepository implements IEventRepository {
19271927 queryBuilder . where ( sortKey . clause , sortKey . params ) ;
19281928 }
19291929
1930+ #whereInsertedAtEnd(
1931+ queryBuilder : { where : ( clause : string , params ?: any ) => unknown } ,
1932+ end : Date | undefined
1933+ ) {
1934+ if ( end ) {
1935+ queryBuilder . where ( "inserted_at <= {insertedAtEnd: DateTime64(3)}" , {
1936+ insertedAtEnd : convertDateToClickhouseDateTime ( end ) ,
1937+ } ) ;
1938+ }
1939+ }
1940+
19301941 #applyTraceScopeWhere(
19311942 queryBuilder : { where : ( clause : string , params ?: any ) => unknown } ,
19321943 {
@@ -1968,11 +1979,7 @@ export class ClickhouseEventRepository implements IEventRepository {
19681979 } ) ;
19691980 }
19701981
1971- if ( options ?. insertedAtEnd ) {
1972- queryBuilder . where ( "inserted_at <= {insertedAtEnd: DateTime64(3)}" , {
1973- insertedAtEnd : convertDateToClickhouseDateTime ( options . insertedAtEnd ) ,
1974- } ) ;
1975- }
1982+ this . #whereInsertedAtEnd( queryBuilder , options ?. insertedAtEnd ) ;
19761983 }
19771984
19781985 if ( options ?. includeDebugLogs !== true ) {
@@ -2172,7 +2179,7 @@ export class ClickhouseEventRepository implements IEventRepository {
21722179 anchorSpanId : string ;
21732180 startCreatedAt : Date ;
21742181 endCreatedAt ?: Date ;
2175- options ?: { includeDebugLogs ?: boolean } ;
2182+ options ?: { includeDebugLogs ?: boolean ; insertedAtEnd ?: Date } ;
21762183 limit ?: number ;
21772184 } ) : Promise < {
21782185 records : TaskEventSummaryV1Result [ ] ;
@@ -2419,7 +2426,7 @@ export class ClickhouseEventRepository implements IEventRepository {
24192426 traceId : string ;
24202427 startCreatedAt ?: Date ;
24212428 endCreatedAt ?: Date ;
2422- options ?: { includeDebugLogs ?: boolean } ;
2429+ options ?: { includeDebugLogs ?: boolean ; insertedAtEnd ?: Date } ;
24232430 spanIds ?: string [ ] ;
24242431 parentSpanIds ?: string [ ] ;
24252432 limit ?: number ;
@@ -2446,6 +2453,8 @@ export class ClickhouseEventRepository implements IEventRepository {
24462453 queryBuilder . where ( "inserted_at >= {insertedAtStart: DateTime64(3)}" , {
24472454 insertedAtStart : convertDateToClickhouseDateTime ( startCreatedAtWithBuffer ) ,
24482455 } ) ;
2456+
2457+ this . #whereInsertedAtEnd( queryBuilder , options ?. insertedAtEnd ) ;
24492458 }
24502459 }
24512460
@@ -2542,7 +2551,7 @@ export class ClickhouseEventRepository implements IEventRepository {
25422551 traceId : string ,
25432552 startCreatedAt : Date ,
25442553 endCreatedAt ?: Date ,
2545- options ?: { includeDebugLogs ?: boolean }
2554+ options ?: { includeDebugLogs ?: boolean ; insertedAtEnd ?: Date }
25462555 ) : Promise < SpanDetail | undefined > {
25472556 const startCreatedAtWithBuffer = new Date ( startCreatedAt . getTime ( ) - 60_000 ) ;
25482557
@@ -2561,6 +2570,8 @@ export class ClickhouseEventRepository implements IEventRepository {
25612570 queryBuilder . where ( "inserted_at >= {insertedAtStart: DateTime64(3)}" , {
25622571 insertedAtStart : convertDateToClickhouseDateTime ( startCreatedAtWithBuffer ) ,
25632572 } ) ;
2573+
2574+ this . #whereInsertedAtEnd( queryBuilder , options ?. insertedAtEnd ) ;
25642575 }
25652576
25662577 if ( options ?. includeDebugLogs !== true ) {
@@ -3058,11 +3069,7 @@ export class ClickhouseEventRepository implements IEventRepository {
30583069 insertedAtStart : convertDateToClickhouseDateTime ( startCreatedAtWithBuffer ) ,
30593070 } ) ;
30603071
3061- if ( options ?. insertedAtEnd ) {
3062- queryBuilder . where ( "inserted_at <= {insertedAtEnd: DateTime64(3)}" , {
3063- insertedAtEnd : convertDateToClickhouseDateTime ( options . insertedAtEnd ) ,
3064- } ) ;
3065- }
3072+ this . #whereInsertedAtEnd( queryBuilder , options ?. insertedAtEnd ) ;
30663073 }
30673074 } else if ( insertedAtStart && this . _version === "v2" ) {
30683075 queryBuilder . where ( "inserted_at >= {insertedAtStart: DateTime64(3)}" , {
@@ -3484,7 +3491,8 @@ export class ClickhouseEventRepository implements IEventRepository {
34843491 traceId : string ,
34853492 runId : string ,
34863493 startCreatedAt : Date ,
3487- endCreatedAt ?: Date
3494+ endCreatedAt ?: Date ,
3495+ options ?: { insertedAtEnd ?: Date }
34883496 ) : Promise < RunPreparedEvent [ ] > {
34893497 const startCreatedAtWithBuffer = new Date ( startCreatedAt . getTime ( ) - 1000 ) ;
34903498
@@ -3503,6 +3511,8 @@ export class ClickhouseEventRepository implements IEventRepository {
35033511 queryBuilder . where ( "inserted_at >= {insertedAtStart: DateTime64(3)}" , {
35043512 insertedAtStart : convertDateToClickhouseDateTime ( startCreatedAtWithBuffer ) ,
35053513 } ) ;
3514+
3515+ this . #whereInsertedAtEnd( queryBuilder , options ?. insertedAtEnd ) ;
35063516 }
35073517
35083518 queryBuilder . where ( "kind != {kind: String}" , { kind : "DEBUG_EVENT" } ) ;
0 commit comments