Monitoring backends with Sentry: the basics
Why we put Sentry in every backend we ship, what to capture, what to ignore, and how to keep the alert noise down.
The default
Every backend we ship has Sentry from day one. Three lines of setup, and the next time something breaks, we get the stack trace, the request payload, and the user (if available).
It costs less per month than a coffee. Skip it and you debug from log greps.
Setup in FastAPI
import sentry_sdk
sentry_sdk.init(
dsn=os.environ["SENTRY_DSN"],
environment=os.environ.get("ENV", "production"),
traces_sample_rate=0.1,
profiles_sample_rate=0.1,
)
That is it. Errors now go to Sentry with full context.
What to capture
- All unhandled exceptions — automatic
- Warnings and degraded paths —
sentry_sdk.capture_message("payment_intent_retried", level="warning") - Custom context — user ID, tenant, request ID, the relevant business object ID
The custom context is what makes errors actionable. "PaymentError" tells you nothing. "PaymentError for customer cus_abc on subscription sub_xyz" tells you what to look at.
What to ignore
- 404s on unknown URLs — bots hitting WordPress paths
- 400s caused by malformed client input — these are bugs in clients, not your service
- Rate limit responses — expected behavior
Sentry has ignore_errors and before_send for filtering. Use them. An overwhelmed alert channel is the same as no alert channel.
Alert tuning
- Page on: first occurrence of a new error type in production
- Notify (Slack, no page) on: error spikes (>5x baseline) for known errors
- Ignore: known noise that you have triaged
If you get more than 2 pages a week from Sentry, your alert rules are too loose. Tighten them.
What Sentry does not do
- It does not replace logs. Use structured logging for normal operations.
- It does not replace metrics. Use Prometheus or a SaaS for latency, throughput, error rate dashboards.
- It does not replace tracing for distributed systems (Sentry has tracing, but it is OK, not great).
Sentry is the "something broke and here is the context" tool. That is enough.
The honest pitch
Sentry has saved every backend team I know hours of debugging time per month. It pays for itself the first time it catches a bug you would have missed.