Expand description
Sentry scope helpers for proxy-side upstream error classification.
Adds structured tags and a per-{provider, operation_id, upstream_status} fingerprint so each root-cause bucket becomes a distinct Sentry issue instead of one “ati command failed” mega-bucket. Also routes log level by status class (info/warn/error).
See issue #81 for context.
Functions§
- 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) - report_
upstream_ error - Attach structured tags + fingerprint to the current Sentry scope and emit a tracing event at the appropriate level for the given 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. - split_
tool_ name - Split a proxy tool_name (
"provider:operation_id") into its parts. Tool names missing a separator are treated as having an unknown operation.