Debug Your App with AI: Sentry and Grafana Loki
Your AI can only fix the bug it can see. Two tools give it the evidence: Sentry catches errors with the full story behind them, and Grafana Loki keeps your logs without a big monthly bill.
Video not loading? Watch the reel on Facebook. There's also a reel about Sentry.
"The app is broken, fix it" is the worst prompt you can give an AI. It will guess, change something that looks suspicious, and maybe make it worse. Give it the actual error, the line it happened on and what the user did just before, and it usually fixes the bug on the first try.
The question is where that evidence comes from once your app is live and you can't see your users' screens.
Sentry: catch every error, with context
Sentry watches your live app. When something crashes, it records the error message, the exact line of code, the browser, and the steps that led there, then alerts you. Instead of a user saying "it didn't work", you get the whole story.
For a Next.js app, one command sets it up:
npx @sentry/wizard@latest -i nextjs
The wizard adds a test page, /sentry-example-page, that throws an error on purpose so you can confirm it works. Other frameworks have their own guides in Sentry's docs.
Free plan: one user and 5,000 errors a month, which is plenty for a small app.
Connecting Sentry to your AI
Sentry has an official MCP server, which lets Claude Code, Cursor and other agents read your Sentry errors directly. In Claude Code:
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
You sign in to Sentry in your browser, and then you can ask: "Look at the latest error in Sentry and fix it." The agent reads the error, opens the right file and proposes a fix.
Sentry also has its own AI debugger, Seer, which finds the root cause and can open a fix for you. It is a paid add-on and isn't included in the free plan.
Grafana Loki: logs without the big bill
Errors are only part of the picture. Sometimes nothing crashes and the API just does the wrong thing. For that you need logs: the running diary your app writes about what it's doing.
Paid logging tools get expensive as your app grows, because they charge for every line they index. Grafana Loki is an open-source alternative that indexes only a few labels per log stream (like which app and which server) instead of every word. That makes it much cheaper to run. You search logs in Grafana's dashboard.
Two ways to start:
- Grafana Cloud's free tier includes 50 GB of logs a month, kept for 14 days. Nothing to install on a server.
- Run it yourself with Docker. Loki's docs have a ready-made Docker Compose setup you can start with one command.
Loki is licensed AGPL-3.0. That's fine for running it for your own app; read the license if you plan to change Loki itself and offer it as a service.
Hand the evidence to your AI
Whichever tool you use, the habit is the same. Give your AI:
- the exact error message,
- the log lines from just before it happened,
- what you expected to happen instead.
A prompt you can copy: "Here is the error from Sentry and the log lines from the 30 seconds before it. Expected: the order saves. Actual: a 500 error. Find the cause, explain it in one paragraph, then make the smallest fix."
Asking for the explanation first is the important part. If the AI's explanation doesn't match the evidence, you've caught a guess before it becomes a change.
For visual bugs, a screenshot works better than logs: see Fix Your Website with a Screenshot.
Try them: Sentry · Grafana Loki on GitHub
Follow my Facebook page for the rest of my debugging tools series.