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 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_len chars. 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.