Gate Sentry export by span level, add Level enums#11
Open
loks0n wants to merge 1 commit into
Open
Conversation
The Sentry exporter previously sent every span carrying a Throwable and always reported it at `error`. Gate export on the span's level instead: spans at warning or above are sent, each reported at its own level, so a caught exception finished at `warn` shows as a warning and one downgraded to `info`/`debug` is suppressed. Introduce a `Utopia\Span\Level` enum (Grafana Loki `detected_level` vocabulary — `debug/info/warn/error/fatal`) as the type for `finish()`, and a `Utopia\Span\Exporter\Sentry\Level` enum for Sentry's own terms, translating `warn` to Sentry's `warning` on the wire. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
The
spanSentry exporter previously sent every span carrying aThrowableand always reported it aterror. This gates export on the span's level instead:Level::Warnnow shows in Sentry aswarning(noterror).Level::Info/Level::Debugis now suppressed (previously any Throwable was sent).error/fatalbehave as before.Enums (no backward compat)
Utopia\Span\Level— the library's vocabulary, following Grafana Loki'sdetected_levelterms:debug / info / warn / error / fatal(notewarn, notwarning). This is the type accepted bySpan::finish().Utopia\Span\Exporter\Sentry\Level— Sentry's own terms, withfromSpan()translatingwarn→ Sentry'swarningon the wire. Kept distinct so the core stays Loki-native and the Sentry contract lives in the exporter.So a span finished at
Level::Warnreads aswarnin the Stdout/Pretty exporters and serializes to"level":"warning"in the Sentry envelope.Notes
Throwablepasses the gate but produces no event (no stacktrace to send). AcaptureMessage-style path for exception-less warnings could be added later if needed.Span::finish()signature changed from?string $levelto?Level $level. The only in-repo caller (client) usesfinish()with no level arg, so it's unaffected.Testing
bin/monorepo check span(pint/phpstan/rector) andbin/monorepo test span(99 tests) pass.🤖 Generated with Claude Code