From 2dc800b5f436ca615615f8975f8dd43b1d9ba0a1 Mon Sep 17 00:00:00 2001 From: "joseph.sawaya@sentry.io" Date: Fri, 17 Jul 2026 21:00:37 +0000 Subject: [PATCH] fix(span): correctly parse multi-segment trace targets in single-arg view --- src/commands/span/view.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/commands/span/view.ts b/src/commands/span/view.ts index f289e23a20..3b0d7047b7 100644 --- a/src/commands/span/view.ts +++ b/src/commands/span/view.ts @@ -127,6 +127,29 @@ export function parsePositionalArgs(args: string[]): SpanViewArgs { } } + // Auto-detect `///` single-arg form with + // multiple slashes. When the last segment is a valid 16-char hex span ID, + // split it off and defer the trace portion to parseTraceTargetWithRecovery. + if (args.length === 1 && first.indexOf("/") !== -1) { + const lastSlash = first.lastIndexOf("/"); + const maybeSpanId = first + .slice(lastSlash + 1) + .trim() + .toLowerCase() + .replace(/-/g, ""); + const traceArg = first.slice(0, lastSlash); + // Only treat it as a combined trace/span arg when the prefix still + // contains a slash (i.e. this is truly multi-segment like org/proj/trace/span). + // The single-slash `/` case is already handled above. + if (traceArg.includes("/") && SPAN_ID_RE.test(maybeSpanId)) { + log.warn( + `Interpreting '${first}' as /. ` + + `Use separate arguments: sentry span view ${traceArg} ${maybeSpanId}` + ); + return { kind: "deferred", rawTraceArg: traceArg, rawSpanIds: [maybeSpanId] }; + } + } + // Single bare arg that looks like a span ID (16-char hex, no slashes): // the user forgot the trace ID. Give a targeted ContextError instead // of the confusing "Invalid trace ID" from validateTraceId() (CLI-SC).