Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/commands/span/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ export function parsePositionalArgs(args: string[]): SpanViewArgs {
}
}

// Auto-detect `<org>/<project>/<trace-id>/<span-id>` 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 `<trace-id>/<span-id>` case is already handled above.
if (traceArg.includes("/") && SPAN_ID_RE.test(maybeSpanId)) {
log.warn(
`Interpreting '${first}' as <trace-target>/<span-id>. ` +
`Use separate arguments: sentry span view ${traceArg} ${maybeSpanId}`
);
return { kind: "deferred", rawTraceArg: traceArg, rawSpanIds: [maybeSpanId] };
Comment on lines +145 to +149

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The warning for combined arguments like org/project/traceId/spanId shows a normalized span ID (dashes removed), which can be confusing as it differs from the user's original input.
Severity: LOW

Suggested Fix

To avoid user confusion, the warning message should display the original, un-normalized span ID as entered by the user. The normalized version of the span ID should still be used internally for validation and further processing, but the user-facing output should reflect their exact input.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/commands/span/view.ts#L145-L149

Potential issue: When a user provides a combined argument like
`org/project/traceId/spanId`, the code normalizes the span ID by removing dashes and
lowercasing it. This normalized ID is then displayed in a warning message that suggests
the correct command usage. If the original span ID contained dashes, the suggested
command will show a span ID without dashes, which differs from the user's input. This
can be confusing for the user, even though the normalized ID is functionally valid for
subsequent processing. This new logic path is also not covered by tests.

Did we get this right? 👍 / 👎 to inform future reviews.

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix missing trace ID accepted

Medium Severity

The new single-argument splitter treats any path whose prefix still contains / and whose final segment is 16-character hex as &lt;trace-target&gt;/&lt;span-id&gt;. A three-segment input like org/project/&lt;span-id&gt; (trace target only, no separate span argument) is split into rawTraceArg org/project and a span ID, instead of the prior missing-span ContextError. Trace resolution then targets the wrong path.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2dc800b. Configure here.

}

// 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).
Expand Down
Loading