Skip to content

Commit af9e278

Browse files
committed
refactor: unify sort values with trace list ('date'/'duration')
span list used 'time' while trace list used 'date' — both mapped to the same -timestamp API sort. Standardize on 'date'/'duration' to match trace list and issue list conventions. Also removes 'time' from the listSpans API type since it was redundant with 'date'. Refs: PR #393 review feedback
1 parent 1230ccb commit af9e278

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/commands/span/list.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import { validateTraceId } from "../../lib/trace-id.js";
3737
type ListFlags = {
3838
readonly limit: number;
3939
readonly query?: string;
40-
readonly sort: "time" | "duration";
40+
readonly sort: "date" | "duration";
4141
readonly json: boolean;
4242
readonly fresh: boolean;
4343
readonly fields?: string[];
4444
};
4545

46-
type SortValue = "time" | "duration";
46+
type SortValue = "date" | "duration";
4747

48-
/** Accepted values for the --sort flag */
49-
const VALID_SORT_VALUES: SortValue[] = ["time", "duration"];
48+
/** Accepted values for the --sort flag (matches trace list) */
49+
const VALID_SORT_VALUES: SortValue[] = ["date", "duration"];
5050

5151
/**
5252
* CLI-side upper bound for --limit.
@@ -62,7 +62,7 @@ const MAX_LIMIT = 1000;
6262
const DEFAULT_LIMIT = 25;
6363

6464
/** Default sort order for span results */
65-
const DEFAULT_SORT: SortValue = "time";
65+
const DEFAULT_SORT: SortValue = "date";
6666

6767
/** Usage hint for ContextError messages */
6868
const USAGE_HINT = "sentry span list [<org>/<project>/]<trace-id>";
@@ -120,7 +120,7 @@ function parseLimit(value: string): number {
120120
/**
121121
* Parse and validate sort flag value.
122122
*
123-
* @throws Error if value is not "time" or "duration"
123+
* @throws Error if value is not "date" or "duration"
124124
*/
125125
export function parseSort(value: string): SortValue {
126126
if (!VALID_SORT_VALUES.includes(value as SortValue)) {

src/lib/api/traces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ type ListSpansOptions = {
168168
query?: string;
169169
/** Maximum number of spans to return */
170170
limit?: number;
171-
/** Sort order: "date"/"time" (newest first) or "duration" (slowest first) */
172-
sort?: "date" | "time" | "duration";
171+
/** Sort order: "date" (newest first) or "duration" (slowest first) */
172+
sort?: "date" | "duration";
173173
/** Time period for spans (e.g., "7d", "24h") */
174174
statsPeriod?: string;
175175
/** Pagination cursor to resume from a previous page */

test/commands/span/list.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ describe("parsePositionalArgs", () => {
9898
});
9999

100100
describe("parseSort", () => {
101-
test("accepts 'time'", () => {
102-
expect(parseSort("time")).toBe("time");
101+
test("accepts 'date'", () => {
102+
expect(parseSort("date")).toBe("date");
103103
});
104104

105105
test("accepts 'duration'", () => {
106106
expect(parseSort("duration")).toBe("duration");
107107
});
108108

109+
test("rejects 'time' (use 'date' instead)", () => {
110+
expect(() => parseSort("time")).toThrow("Invalid sort value");
111+
});
112+
109113
test("throws for invalid value", () => {
110114
expect(() => parseSort("name")).toThrow("Invalid sort value");
111115
});
@@ -190,7 +194,7 @@ describe("listCommand.func", () => {
190194
context,
191195
{
192196
limit: 25,
193-
sort: "time",
197+
sort: "date",
194198
fresh: false,
195199
},
196200
VALID_TRACE_ID
@@ -219,7 +223,7 @@ describe("listCommand.func", () => {
219223
{
220224
limit: 25,
221225
query: "op:db",
222-
sort: "time",
226+
sort: "date",
223227
fresh: false,
224228
},
225229
VALID_TRACE_ID
@@ -243,7 +247,7 @@ describe("listCommand.func", () => {
243247
context,
244248
{
245249
limit: 25,
246-
sort: "time",
250+
sort: "date",
247251
fresh: false,
248252
},
249253
`my-org/my-project/${VALID_TRACE_ID}`

0 commit comments

Comments
 (0)