Skip to content

Commit fb2bc4a

Browse files
committed
fix: handle multi-arg trace mode and fix orphaned JSDoc
- parseLogListArgs now checks last arg for trace-id in 2+ arg case (e.g., 'sentry log list my-org <trace-id>') - Move DEFAULT_PROJECT_PERIOD above JSDoc so it attaches correctly to executeSingleFetch
1 parent bd6b5f4 commit fb2bc4a

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/commands/log/list.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,17 @@ type ParsedLogArgs =
160160
/**
161161
* Disambiguate log list positional arguments.
162162
*
163-
* Checks if the "tail" segment (last part after `/`, or the entire arg
164-
* if no `/`) looks like a 32-char hex trace ID. If so, delegates to
165-
* {@link parseTraceTarget} for full trace target parsing. Otherwise,
166-
* treats the argument as a project target.
163+
* Detects trace mode by checking whether any argument segment looks like
164+
* a 32-char hex trace ID:
165+
*
166+
* - **Single arg**: checks the tail segment (last part after `/`, or the
167+
* entire arg). `<trace-id>`, `<org>/<trace-id>`, `<org>/<project>/<trace-id>`.
168+
* - **Two+ args**: checks the last positional (`<org> <trace-id>` or
169+
* `<org>/<project> <trace-id>` space-separated forms).
170+
* - **No match**: treats the argument as a project target.
171+
*
172+
* When trace mode is detected, delegates to {@link parseTraceTarget} for
173+
* full parsing and validation.
167174
*
168175
* @param args - Positional arguments from CLI
169176
* @returns Parsed args with mode discrimination
@@ -178,7 +185,19 @@ function parseLogListArgs(args: string[]): ParsedLogArgs {
178185
return { mode: "project" };
179186
}
180187

181-
// Check the tail segment: last part after `/`, or the entire arg
188+
// Two+ args: check if the last arg is a trace ID (space-separated form)
189+
// e.g., `sentry log list my-org abc123...` or `sentry log list my-org/proj abc123...`
190+
if (args.length >= 2) {
191+
const last = args.at(-1);
192+
if (last && isTraceId(last)) {
193+
return {
194+
mode: "trace",
195+
parsed: parseTraceTarget(args, TRACE_USAGE_HINT),
196+
};
197+
}
198+
}
199+
200+
// Single arg: check the tail segment (last part after `/`, or the entire arg)
182201
const lastSlash = first.lastIndexOf("/");
183202
const tail = lastSlash === -1 ? first : first.slice(lastSlash + 1);
184203

@@ -192,15 +211,15 @@ function parseLogListArgs(args: string[]): ParsedLogArgs {
192211
return { mode: "project", target: first };
193212
}
194213

214+
/** Default time period for project-scoped log queries */
215+
const DEFAULT_PROJECT_PERIOD = "90d";
216+
195217
/**
196218
* Execute a single fetch of logs (non-streaming mode).
197219
*
198220
* Returns the logs and a hint. The caller yields the result and
199221
* returns the hint as a footer via `CommandReturn`.
200222
*/
201-
/** Default time period for project-scoped log queries */
202-
const DEFAULT_PROJECT_PERIOD = "90d";
203-
204223
async function executeSingleFetch(
205224
org: string,
206225
project: string,

0 commit comments

Comments
 (0)