Skip to content

fix(span): correctly parse multi-segment trace targets in single-arg view#1267

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/span-view-multi-segment-parse
Open

fix(span): correctly parse multi-segment trace targets in single-arg view#1267
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/span-view-multi-segment-parse

Conversation

@sentry

@sentry sentry Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The sentry span view command's parsePositionalArgs function previously only supported auto-splitting a single positional argument if it was in the <trace-id>/<span-id> format (i.e., exactly one slash). When users provided a fully-qualified target like <org>/<project>/<trace-id>/<span-id> as a single argument, the parser would skip the auto-split logic due to the multiple slashes. This resulted in the rawSpanIds array being empty, leading to a ContextError: Span ID is required.

This fix extends the parsePositionalArgs function to correctly handle single arguments that contain multiple slashes, specifically looking for the <org>/<project>/<trace-id>/<span-id> pattern. It now extracts the span ID from the last segment and treats the preceding part (<org>/<project>/<trace-id>) as the trace target, which is then processed by the existing parseTraceTargetWithRecovery mechanism. A warning message is also logged to advise users to use separate arguments for clarity.

Fixes CLI-1BD

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@github-actions github-actions Bot added the risk: high PR risk score: high label Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1267/

Built to branch gh-pages at 2026-07-17 21:01 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

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

Comment thread src/commands/span/view.ts
`Use separate arguments: sentry span view ${traceArg} ${maybeSpanId}`
);
return { kind: "deferred", rawTraceArg: traceArg, rawSpanIds: [maybeSpanId] };
}

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.

Comment thread src/commands/span/view.ts
Comment on lines +145 to +149
log.warn(
`Interpreting '${first}' as <trace-target>/<span-id>. ` +
`Use separate arguments: sentry span view ${traceArg} ${maybeSpanId}`
);
return { kind: "deferred", rawTraceArg: traceArg, rawSpanIds: [maybeSpanId] };

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.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

❌ Patch coverage is 71.43%. Project has 5482 uncovered lines.
✅ Project coverage is 81.67%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/commands/span/view.ts 71.43% ⚠️ 2 Missing and 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.67%    81.67%        —%
==========================================
  Files          426       426         —
  Lines        29896     29903        +7
  Branches     19420     19428        +8
==========================================
+ Hits         24416     24421        +5
- Misses        5480      5482        +2
- Partials      2035      2036        +1

Generated by Codecov Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant