Add production error monitoring via Sentry - #53
Open
derekl-beep wants to merge 2 commits into
Open
Conversation
Cheap, currently absent, and the last production bug (chat session corruption) was caught by a user pasting a stack trace rather than an alert firing. No Sentry account exists in this environment, so this wires the SDK fully rather than partially: sentry_sdk.init(dsn=None) is a documented no-op, so it's safe to leave SENTRY_DSN unset in dev/CI — the moment someone sets it in production (e.g. a free Sentry account on Railway), monitoring goes live with no further code changes. Explicit capture_exception() calls at the two spots that already catch and swallow exceptions (api/server.py's chat_stream_endpoint generator, agent/main.py's _run_tools handler-failure path) — Sentry's automatic FastAPI instrumentation only sees uncaught exceptions, and both of these are caught on purpose (to keep a stream/batch alive), so they'd otherwise never reach Sentry at all. send_default_pii is explicitly set to False: the SDK auto-instruments the anthropic client, and every Claude call here carries real expense/ income text — that must never leave this app for a third party. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qz6JBNFwhgem5GY3i2BEMY
main moved forward with PRs #50 (usage instrumentation + session persistence) and #51 (proactive nudges) since this branch was cut. The one real conflict was tests/test_agent.py, where both this branch (a Sentry capture_exception test) and main (serialize_block/session_lock tests) added new tests at the same location — kept both, no logic changes beyond the merge itself.
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
Cheap, currently absent, and the last production bug (chat session corruption) was caught by a user pasting a stack trace rather than an alert firing.
No Sentry account exists in this environment, so this wires the SDK fully rather than partially:
sentry_sdk.init(dsn=None)is a documented no-op, so it's safe to leaveSENTRY_DSNunset in dev/CI — the moment someone sets it in production (e.g. a free Sentry account on Railway), monitoring goes live with no further code changes.capture_exception()calls at the two spots that already catch and swallow exceptions (api/server.py'schat_stream_endpointgenerator,agent/main.py's_run_toolshandler-failure path) — Sentry's automatic FastAPI instrumentation only sees uncaught exceptions, and both of these are caught on purpose (to keep a stream/batch alive), so they'd otherwise never reach Sentry at all.send_default_piiis explicitly set toFalse: the SDK auto-instruments theanthropicclient, and every Claude call here carries real expense/income text — that must never leave this app for a third party.Test plan
uv run pytest tests/— 170 passed (new tests confirmcapture_exceptionfires at both swallowed-exception sites)uv run ruff check .— cleannpm run build/npm run lint— cleannpx playwright test— 78 passed, mobile + desktopuv run python -c "import api.server"still succeeds with noSENTRY_DSNset (matches the CI import-smoke-check)🤖 Generated with Claude Code
https://claude.ai/code/session_01Qz6JBNFwhgem5GY3i2BEMY
Generated by Claude Code