refactor: unified trace-target parsing and resolution#438
Merged
Conversation
Extract parseTraceTarget + resolveTraceOrgProject + resolveTraceOrg into src/lib/trace-target.ts as a shared abstraction for all commands that accept trace IDs. Supports flexible positional formats: - <trace-id> auto-detect org/project - <org>/<trace-id> org-scoped - <org>/<project>/<trace-id> fully explicit - <target> <trace-id> two-arg form Two resolution levels: - resolveTraceOrgProject: for span list, span view, trace view - resolveTraceOrg: for trace logs (org-scoped API) Commands migrated: - span list: -55 lines (parsePositionalArgs + resolution switch) - span view: -40 lines (parsePositionalArgs + resolveTarget helper) - trace view: -83 lines (parsePositionalArgs + resolution switch) Keeps swap detection + issue short ID detection as preProcessArgs - trace logs: -44 lines (custom slash parsing + resolveOrg call) Closes #434
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Init
Issue List
Other
Bug Fixes 🐛Dsn
Init
Other
Documentation 📚
Internal Changes 🔧Init
Tests
Other
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1101 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.06% 95.06% —%
==========================================
Files 164 165 +1
Lines 22254 22299 +45
Branches 0 0 —
==========================================
+ Hits 21154 21198 +44
- Misses 1100 1101 +1
- Partials 0 0 —Generated by Codecov Action |
USAGE_TARGET_RE matches [<prefix>]<trail> instead of just [<prefix>], preventing malformed disambiguation examples like 'sentry span list <org>/frontend/abc123<trace-id>'.
The USAGE_TARGET_RE replacement for the org-scoped error case was dropping the trace ID from the disambiguation example.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
parseOrgProjectArg already warns internally about slug normalization. Don't propagate 'normalized' flag from targetArgToTraceTarget so callers' warnIfNormalized won't emit a duplicate warning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Extract shared trace-target parsing and resolution into
src/lib/trace-target.ts, replacing duplicated positional argument parsing and target resolution logic across 4 commands.New shared module:
src/lib/trace-target.tsparseTraceTarget(args, usageHint)— Parses positional args into a discriminated union:<trace-id>→auto-detect<org>/<trace-id>→org-scoped<org>/<project>/<trace-id>→explicit<target> <trace-id>→ delegates toparseOrgProjectArgresolveTraceOrgProject(parsed, cwd, hint)— For commands needing org+project (span list, span view, trace view)resolveTraceOrg(parsed, cwd, hint)— For org-scoped commands (trace logs)Commands migrated
span listparsePositionalArgs+ 4-way switchspan viewparsePositionalArgs+resolveTargethelpertrace viewparsePositionalArgs+ switch; kept swap detection aspreProcessArgstrace logsresolveOrgcallNet: -29 lines (777 added to shared module + tests, 806 removed from commands)
Closes #434