feat(formatters): colorize SQL in DB span descriptions#546
Merged
Conversation
Add SQL syntax highlighting to all DB span rendering paths using `@sentry/sqlish`. The parser tokenizes SQL-ish strings (including parameterized queries) and the new `colorizeSql()` function maps tokens to the project's chalk color palette (keywords → cyan, parameters → magenta, parens/collapsed → muted). All four rendering paths are updated: - Span list table (inline colorization) - Span view detail (pretty-printed query block via `formatSqlBlock`) - Span tree in trace view (inline colorization) - Ancestor chain in span view (inline colorization) Pretty-printing is disabled in non-TTY mode — `formatSqlBlock()` falls back to compact single-line output when piped. `colorizeSql()` respects `isPlainOutput()` and returns plain text under NO_COLOR.
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧Coverage
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 83.05%. Project has 1037 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 96.03% 96.01% -0.02%
==========================================
Files 186 187 +1
Lines 25929 25987 +58
Branches 0 0 —
==========================================
+ Hits 24899 24950 +51
- Misses 1030 1037 +7
- Partials 0 0 —Generated by Codecov Action |
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.
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.

Add SQL syntax highlighting to all DB span rendering paths using
@sentry/sqlish.What
New
src/lib/formatters/sql.tsmodule with three exports:isDbSpanOp(op)— detectsdb.*span operationscolorizeSql(sql)— inline ANSI colorization (keywords → cyan, parameters → magenta, parens → muted)formatSqlBlock(sql)— pretty-printed + colorized multi-line SQL block for detail viewsWhere
All four DB span rendering paths are updated:
trace.tstrace.tshuman.tstrace.tsPlain output
colorizeSql()returns plain text whenisPlainOutput()is trueformatSqlBlock()disables pretty-printing in non-TTY — falls back to compact single-line SQLTests
test/lib/formatters/sql.test.tstest/lib/formatters/sql.property.test.ts(round-trip, plain-mode identity, determinism, idempotent strip)