Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

fix(local): Handle standalone span items, Cloudflare SDK source, and warn level - #1276

Merged
MathurAditya724 merged 2 commits into
mainfrom
fix/local-formatter-cloudflare-ai-spans
Jul 22, 2026
Merged

MathurAditya724 merged 2 commits into
mainfrom
fix/local-formatter-cloudflare-ai-spans

Conversation

@MathurAditya724

Copy link
Copy Markdown
Member

Summary

Three fixes for sentry local serve discovered during Hono + Cloudflare Workers stress testing:

  • Standalone span item formatter — The Cloudflare (and other modern) SDKs emit gen_ai/mcp spans as standalone span envelope items (v2 span streaming), not embedded in transactions. These were rendering as a useless • span fallback. Now they get full semantic rendering with gen_ai labels, model names, token usage, duration, trace IDs — and --filter ai correctly matches them.
  • Cloudflare SDK labeled [SERVER] — Added cloudflare to SERVER_JS_MARKERS so sentry.javascript.cloudflare events show [SERVER] instead of [BROWSER].
  • warn level colored — Added warn key to LEVEL_COLORS since the Sentry SDK emits level "warn" (not "warning").

Context

These gaps were found by creating a real Hono + @sentry/cloudflare Workers app, running it under sentry local serve via wrangler dev --local, and hitting routes that generate errors, transactions, structured logs, and gen_ai/mcp AI spans.

Changes

  • src/lib/formatters/local.ts:
    • New formatSingleSpan, formatSpanItem, formatSpanJson functions for the span item type
    • flattenSpanAttributes to convert typed { key: { type, value } } to plain Record<string, unknown>
    • spanItemHasAiActivity for --filter ai matching on standalone spans
    • itemTypeToFilterCategory maps "span" to "transaction" category
    • isItemIncluded checks standalone spans for AI attributes
    • formatItem, formatItemJson route "span" type to the new formatters
    • SERVER_JS_MARKERS += "cloudflare"
    • LEVEL_COLORS += warn: yellow
  • test/lib/formatters/local.test.ts: 16 new tests covering all three fixes

All 937 existing formatter tests + 16 new tests pass. Property tests pass.

…warn level

Three fixes for `sentry local serve` discovered during Hono + Cloudflare
Workers stress testing:

1. Add formatter for standalone `span` envelope items (v2 span streaming).
   The Cloudflare SDK emits gen_ai/mcp spans as standalone span items, not
   embedded in transactions. Without this, AI spans render as a bare
   `• span` fallback line and `--filter ai` misses them entirely. Now they
   get full semantic rendering (gen_ai labels, duration, trace ID) and are
   properly matched by the ai/transaction filters.

2. Add `cloudflare` to SERVER_JS_MARKERS so `sentry.javascript.cloudflare`
   SDK events are labeled `[SERVER]` instead of `[BROWSER]`.

3. Add `warn` key to LEVEL_COLORS (alongside existing `warning`) since
   the Sentry SDK emits log level `warn`, not `warning`.
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-22 13:09 UTC

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 87.50%. Project has 5486 uncovered lines.
✅ Project coverage is 81.69%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/lib/formatters/local.ts 87.50% ⚠️ 8 Missing and 10 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.68%    81.69%    +0.01%
==========================================
  Files          426       426         —
  Lines        29909     29969       +60
  Branches     19433     19496       +63
==========================================
+ Hits         24431     24483       +52
- Misses        5478      5486        +8
- Partials      2035      2045       +10

Generated by Codecov Action

@MathurAditya724
MathurAditya724 marked this pull request as ready for review July 22, 2026 13:08
@MathurAditya724
MathurAditya724 merged commit b5902f2 into main Jul 22, 2026
45 of 48 checks passed
@MathurAditya724
MathurAditya724 deleted the fix/local-formatter-cloudflare-ai-spans branch July 22, 2026 13:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant