Expand description
Sentry scope helpers for proxy-side upstream error classification.
Adds structured tags + a class-based dynamic event title so each error class becomes a distinct Sentry issue bucket instead of every failure collapsing into one generic “upstream server error” bucket. Also routes log level by status class (info/warn/error).
Title strategy: Sentry’s tracing bridge maps tracing::error! messages
to event titles, and Sentry groups events by title when no fingerprint
is set. We dispatch the report into 5 buckets — auth_error,
bad_input, rate_limited, server_error, transport_error — each
with its own literal-string tracing::error!. Provider/operation/
status live as tags so each bucket is filterable per-provider without
splitting the buckets per-provider.
See issue #81 for the original context; the redesign closes the “Sentry errors really fucking suck” report — generic titles, missing source chains, lying tags.
Enums§
- Upstream
Error Class - Coarse classification of an upstream failure. Each class maps to a
distinct Sentry bucket via a unique literal
tracing::error!/tracing::warn!message — that’s how grouping survives across providers without collapsing every error into one mega-bucket.
Functions§
- capture_
error_ with_ scope - Attach the structured Rust error (with its full
source()chain) to the current Sentry scope and capture it as an exception event. This is what gives the issue page a real “Exception” block with the reqwest /HttpError/McpErrorsource chain — without this, all Sentry sees is the tracing-bridge’s flat title + tags. - is_
no_ records_ body - True when a 404 body looks like a legit “no records” response the caller should treat as an empty result, not an error.
- parse_
upstream_ error - Best-effort parse of common upstream error JSON shapes:
{"error": {"type": "X", "message": "Y"}}(PDL, Stripe, Anthropic){"type": "X", "message": "Y"}(flat){"error": "message string"}(xAI, finnhub flat){"message": "Y"}(generic) - provider_
and_ op - Split a proxy tool reference into
(provider, operation_id). - report_
upstream_ error - Attach structured tags + class-based dynamic title to the current Sentry scope and emit a tracing event at the appropriate level for the upstream status class.
- scrub_
and_ truncate - Scrub obvious PII patterns (UUIDs, emails, IPv4s, long hex tokens) from a
user-facing message and truncate to
max_lenchars. Keeps the short form safe to send to Sentry as a tag-adjacent extra. - set_
jwt_ sentry_ scope - Attach JWT identity (sub, sandbox_id, job_id) to the current Sentry
scope so every event raised during this request is searchable by
those facets. Set once at the start of
/call,/mcp, and/helphandlers. - split_
tool_ name - Back-compat shim for call sites that still don’t know the resolved
provider name. New code should call
provider_and_opdirectly.