Skip to content

Add production error monitoring via Sentry - #53

Open
derekl-beep wants to merge 2 commits into
mainfrom
claude/error-monitoring
Open

Add production error monitoring via Sentry#53
derekl-beep wants to merge 2 commits into
mainfrom
claude/error-monitoring

Conversation

@derekl-beep

Copy link
Copy Markdown
Owner

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 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.
  • Error capture only, no performance tracing — that's a separate cost/scope this app doesn't need yet.

Test plan

  • uv run pytest tests/ — 170 passed (new tests confirm capture_exception fires at both swallowed-exception sites)
  • uv run ruff check . — clean
  • npm run build / npm run lint — clean
  • npx playwright test — 78 passed, mobile + desktop
  • Verified uv run python -c "import api.server" still succeeds with no SENTRY_DSN set (matches the CI import-smoke-check)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qz6JBNFwhgem5GY3i2BEMY


Generated by Claude Code

claude added 2 commits July 16, 2026 02:14
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants