99// biome-ignore lint/performance/noNamespaceImport: Sentry SDK recommends namespace import
1010import * as Sentry from "@sentry/node-core/light" ;
1111import type { SentryContext } from "../../context.js" ;
12- import { listLogs , listTraceLogs } from "../../lib/api-client.js" ;
1312import {
14- parseSort ,
15- type SortDirection ,
16- validateLimit ,
17- } from "../../lib/arg-parsing.js" ;
13+ type LogSortDirection ,
14+ listLogs ,
15+ listTraceLogs ,
16+ } from "../../lib/api-client.js" ;
17+ import { parseLogSort , validateLimit } from "../../lib/arg-parsing.js" ;
1818import { AuthError , stringifyUnknown } from "../../lib/errors.js" ;
1919import {
2020 buildLogRowCells ,
@@ -50,7 +50,7 @@ type ListFlags = {
5050 readonly query ?: string ;
5151 readonly follow ?: number ;
5252 readonly period ?: string ;
53- readonly sort : SortDirection ;
53+ readonly sort : LogSortDirection ;
5454 readonly json : boolean ;
5555 readonly fresh : boolean ;
5656 readonly fields ?: string [ ] ;
@@ -180,21 +180,19 @@ async function executeSingleFetch(
180180 query : flags . query ,
181181 limit : flags . limit ,
182182 statsPeriod : period ,
183+ sort : flags . sort ,
183184 } ) ;
184185
185186 if ( logs . length === 0 ) {
186187 return { result : { logs : [ ] , hasMore : false } , hint : "No logs found." } ;
187188 }
188189
189- // API returns newest first. Reverse only when user wants oldest-first.
190- const ordered = flags . sort === "oldest" ? [ ...logs ] . reverse ( ) : logs ;
191-
192190 const hasMore = logs . length >= flags . limit ;
193191 const countText = `Showing ${ logs . length } log${ logs . length === 1 ? "" : "s" } .` ;
194192 const tip = hasMore ? " Use --limit to show more, or -f to follow." : "" ;
195193
196194 return {
197- result : { logs : ordered , hasMore } ,
195+ result : { logs, hasMore } ,
198196 hint : `${ countText } ${ tip } ` ,
199197 } ;
200198}
@@ -440,6 +438,7 @@ async function executeTraceSingleFetch(
440438 query : flags . query ,
441439 limit : flags . limit ,
442440 statsPeriod : period ,
441+ sort : flags . sort ,
443442 } ) ;
444443
445444 if ( logs . length === 0 ) {
@@ -451,14 +450,12 @@ async function executeTraceSingleFetch(
451450 } ;
452451 }
453452
454- const ordered = flags . sort === "oldest" ? [ ...logs ] . reverse ( ) : logs ;
455-
456453 const hasMore = logs . length >= flags . limit ;
457454 const countText = `Showing ${ logs . length } log${ logs . length === 1 ? "" : "s" } for trace ${ traceId } .` ;
458455 const tip = hasMore ? " Use --limit to show more." : "" ;
459456
460457 return {
461- result : { logs : ordered , traceId, hasMore } ,
458+ result : { logs, traceId, hasMore } ,
462459 hint : `${ countText } ${ tip } ` ,
463460 } ;
464461}
@@ -645,7 +642,7 @@ export const listCommand = buildListCommand(
645642 } ,
646643 sort : {
647644 kind : "parsed" ,
648- parse : parseSort ,
645+ parse : parseLogSort ,
649646 brief : 'Sort order: "newest" (default) or "oldest"' ,
650647 default : "newest" ,
651648 } ,
0 commit comments