Skip to content

fix(span): Handle invalid trace ID in tryAutoSplitSpanArg - #1443

Merged
BYK merged 4 commits into
mainfrom
seer/fix/span-view-invalid-trace-id-error
Aug 20, 2026
Merged

fix(span): Handle invalid trace ID in tryAutoSplitSpanArg#1443
BYK merged 4 commits into
mainfrom
seer/fix/span-view-invalid-trace-id-error

Conversation

@sentry

@sentry sentry Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issue CLI-1GP, where the sentry span view command would throw a ValidationError: Invalid trace ID when a user provided a span target in the format <org>/<project>/<span-id> (i.e., omitting the trace ID segment).

Root Cause:
In packages/cli/src/commands/span/view.ts, the tryAutoSplitSpanArg function attempts to parse a single argument that might contain a trace target and a span ID. When a user provided <org>/<project>/<span-id>, tryAutoSplitSpanArg incorrectly passed the tracePrefix (e.g., org/project) to parseSlashSeparatedTraceTarget. Inside parseSlashSeparatedTraceTarget, the last segment of tracePrefix (e.g., project) was then treated as a trace ID. Since a project name like "scout" is not a 32-character hexadecimal string, parseSlashSeparatedTraceTarget threw a ValidationError, which was not handled by tryAutoSplitSpanArg.

Fix:
The call to parseSlashSeparatedTraceTarget within tryAutoSplitSpanArg is now wrapped in a try/catch block. If a ValidationError (or any error from parseSlashSeparatedTraceTarget) is caught, tryAutoSplitSpanArg logs a debug message and returns null. This allows the parsePositionalArgs function to correctly identify that the argument could not be auto-split and proceed to its existing logic for handling missing trace IDs, which provides a more user-friendly ContextError.

Additionally, a minor formatting adjustment was made to the log.debug call to comply with Biome linting rules.

Fixes CLI-1GP

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cli Ready Ready Preview Aug 20, 2026 9:48am

Request Review

Comment thread packages/cli/src/commands/span/view.ts
@sentry sentry Bot changed the title fix(span): Handle missing trace ID in view command fix(span): Handle invalid trace ID in tryAutoSplitSpanArg Aug 19, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: low PR risk score: low labels Aug 19, 2026
@BYK BYK added the jared Trigger the Jared agent to work on stuff label Aug 20, 2026

@jared-outpost jared-outpost 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.

the fix is correct and minimal — wrapping the `parseSlashSeparatedTraceTarget` call in try/catch lets `org/project/` fall through to the clean `ContextError` instead of leaking a confusing `ValidationError`. traced it through: prefix `org/project` → `validateTraceId("project")` throws → caught → returns null → `parsePositionalArgs` surfaces the missing-span-id `ContextError`. all 37 span/view tests and lint pass.

one gap: no regression test for the actual bug scenario. this parser has thorough coverage in test/commands/span/view.test.ts (the auto-split and error cases describes), but nothing asserts that single-arg org/project/<span-id> now throws a ContextError rather than a ValidationError. worth adding a case there so this does not silently regress — e.g. under the auto-split describe:

test("does not auto-split org/project/spanId (missing trace ID → ContextError)", () => {
  expect(() =>
    parsePositionalArgs([`my-org/my-project/${VALID_SPAN_ID}`])
  ).toThrow(ContextError);
});

not blocking, but recommend adding before merge given the rest of this file guards each branch.

@BYK

BYK commented Aug 20, 2026

Copy link
Copy Markdown
Member

Jared can you implement the missing test and address BugBot's comment, push your changes to the PR and then merge it?

@BYK

BYK commented Aug 20, 2026

Copy link
Copy Markdown
Member

Jared?

@BYK BYK added jared Trigger the Jared agent to work on stuff and removed jared Trigger the Jared agent to work on stuff labels Aug 20, 2026
The previous try/catch returned null on any parse failure, which routed
org/project/<span-id> into the generic 'missing span ID' fallback (that
wrongly suggested 'span list' with the span ID) and swallowed the precise
ValidationError for org/project/<bad-trace>/<span-id>.

Since the catch is only reached after confirming the last segment is a
span ID and the prefix looks like a trace target, a failure there always
means the trace-target portion is bad. Throw a trace-focused ContextError
that preserves the underlying validation detail instead.

Adds regression tests for both cases (CLI-1GP). Addresses BugBot review.
@jared-outpost

jared-outpost Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

done. pushed b506b32:

  • BugBot's finding (both parts): the previous catch → return null routed org/project/<span-id> into the generic 'missing span ID' fallback (which even suggested span list treating the span id as a trace) and swallowed the precise ValidationError for org/project/<bad-trace>/<span-id>. since the catch is only reached after we've confirmed the last segment is a span id and the prefix looks like a trace target, a failure there always means the trace-target portion is bad — so it now throws a trace-focused ContextError that preserves the underlying detail. resolved that thread.
  • missing test: added two regression cases covering org/project/<span-id> and org/project/<bad-trace>/<span-id>. full span/view suite (39 tests) + biome pass locally.

auto-merge (squash) is enabled — it'll land once required checks go green.

@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 2 potential issues.

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 b506b32. Configure here.

Comment thread packages/cli/src/commands/span/view.ts
Comment thread packages/cli/src/commands/span/view.ts
@BYK
BYK disabled auto-merge August 20, 2026 09:47
- drop raw ValidationError detail from alternatives (prevents split bullets and contradictory guidance)
- make suggestion conditional: if prefix already ends with a hex trace segment, tell the user to correct it; otherwise tell them to add the missing trace-id segment
- prefix catch var with _ to satisfy noUnusedVariables
- biome + 39 tests pass
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: medium PR risk score: medium labels Aug 20, 2026
@BYK
BYK merged commit a703b89 into main Aug 20, 2026
31 checks passed
@BYK
BYK deleted the seer/fix/span-view-invalid-trace-id-error branch August 20, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jared Trigger the Jared agent to work on stuff risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant