Skip to main content

Module sentry_scope

Module sentry_scope 

Source
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§

UpstreamErrorClass
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 / McpError source 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_len chars. 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 /help handlers.
split_tool_name
Back-compat shim for call sites that still don’t know the resolved provider name. New code should call provider_and_op directly.