Skip to content

feat(formatters): colorize SQL in DB span descriptions#546

Merged
BYK merged 3 commits intomainfrom
feat/sql-colorize-db-spans
Mar 24, 2026
Merged

feat(formatters): colorize SQL in DB span descriptions#546
BYK merged 3 commits intomainfrom
feat/sql-colorize-db-spans

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 24, 2026

Add SQL syntax highlighting to all DB span rendering paths using @sentry/sqlish.

What

New src/lib/formatters/sql.ts module with three exports:

  • isDbSpanOp(op) — detects db.* span operations
  • colorizeSql(sql) — inline ANSI colorization (keywords → cyan, parameters → magenta, parens → muted)
  • formatSqlBlock(sql) — pretty-printed + colorized multi-line SQL block for detail views

Where

All four DB span rendering paths are updated:

Path File Mode
Span list table trace.ts Inline colorization
Span view detail trace.ts Pretty-printed query block
Span tree (trace view) human.ts Inline colorization
Ancestor chain (span view) trace.ts Inline colorization

Plain output

  • colorizeSql() returns plain text when isPlainOutput() is true
  • formatSqlBlock() disables pretty-printing in non-TTY — falls back to compact single-line SQL

Tests

  • Unit tests: test/lib/formatters/sql.test.ts
  • Property-based tests: test/lib/formatters/sql.property.test.ts (round-trip, plain-mode identity, determinism, idempotent strip)

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.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (formatters) Colorize SQL in DB span descriptions by BYK in #546
  • Native debug ID injection and sourcemap upload by BYK in #543

Internal Changes 🔧

Coverage

  • Use informational-patch input instead of sed hack by BYK in #544
  • Make checks informational on release branches by BYK in #541

Other

  • (ci) Upgrade GitHub Actions to Node 24 runtime by BYK in #542
  • (issue-list) Use collapse parameter to skip unused Snuba queries by BYK in #545
  • Regenerate skill files by github-actions[bot] in ec1ffe28

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 83.05%. Project has 1037 uncovered lines.
❌ Project coverage is 96.01%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
human.ts 96.43% ⚠️ 46 Missing
trace.ts 92.67% ⚠️ 20 Missing
sql.ts 85.11% ⚠️ 7 Missing
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

@BYK BYK marked this pull request as ready for review March 24, 2026 00:53
Copy link

@cursor cursor bot left a comment

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.

@BYK BYK merged commit 7da52e0 into main Mar 24, 2026
22 checks passed
@BYK BYK deleted the feat/sql-colorize-db-spans branch March 24, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant