---
title: "Track app errors with a Sentry SDK, with while.sh"
url: https://while.sh/en/guides/track-errors-sentry/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-02
---

# Track your app's errors with a Sentry SDK, without a Sentry account, from your AI agent

Your app crashes, and you find out from a customer. With while, its errors arrive through a Sentry SDK, with no Sentry account to open, and a never-seen-before error alerts your AI agent, which reads the stack trace and fixes it.

## Prerequisites

- An app in Node.js, Python, Go or any other language that has a Sentry SDK.
- An AI agent that works in a terminal: Claude Code, Codex, Cursor or Gemini CLI.

## Step 1: Give your agent these instructions

Open your agent in your app's folder, and paste these instructions into it:

```text titre="Instructions"
Connect to while with my account (while.sh/agents), then deploy my app.
```

Your agent adds while's MCP server itself. If it asks you to, restart it. On the first call to while, a page opens in your browser. In Claude Code, if it doesn't open, type /mcp, choose while, then Authenticate. On that page, choose "A new app", then click Authorize.

## Step 2: Stop watching for errors

When a never-seen-before error comes in, your agent is notified, reads the stack trace, fixes the code and offers you the new version.

## What your agent does

It adds the Sentry SDK to your app and connects it to `SENTRY_DSN`, which your app already receives (source 1):

```js titre="instrument.js"
import * as Sentry from '@sentry/node';

Sentry.init({ dsn: process.env.SENTRY_DSN });
```

It loads the SDK before the rest of your app, as Sentry requires:

```json titre="package.json"
"scripts": {
  "start": "node --import ./instrument.js server.js"
}
```

There is nothing to open at Sentry and nothing to configure in while: the address points to while, and it works even if your app has no internet access, which is the default. Errors are grouped, and each one keeps its stack trace.

## Understand what is crashing

> You, to your agent: What has been crashing since the last deployment?

Your agent reads the grouped errors in while, finds the line at fault, fixes it and deploys again.

## Track browser errors too

> You, to your agent: Add the browser errors too.

Your agent connects the Sentry SDK in your pages to `SENTRY_DSN_PUBLIC`, the address made for the browser.

## Connect a Python API

> You, to your agent: Hook up error tracking for our FastAPI API.

The Sentry SDK for Python connects the same way, with the same variable:

```python titre="main.py"
import os
import sentry_sdk

sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"))
```

## Go back to the previous version

> You, to your agent: Go back to the previous version.

In the 30 minutes after a deployment, the previous version comes back in a second. After that, it takes a few seconds. Once the previous version is back, your agent reads what broke in while's logs, fixes it and deploys again.

## Next steps

- [Deploy a Node.js API and its PostgreSQL database](/en/guides/deploy-node-api-postgresql/)
- [Deploy a FastAPI API](/en/guides/deploy-fastapi/)
- [Connect Stripe or Brevo without a key in the code](/en/guides/api-keys-out-of-code/)

## Sources

1. [Sentry, the SDK for Node.js](https://docs.sentry.io/platforms/javascript/guides/node/), 2026-11-02

## Questions

### Do I need a Sentry account?

No. The Sentry SDK sends its errors to while, with no account or subscription at Sentry.

### Which languages?

All the ones that have a Sentry SDK: Node.js, Python, Go, Ruby, PHP, Java…

### Is my agent notified of every error?

Of a never-seen-before error, yes. An error that is already known is counted, without disturbing your agent every time.

### What about my app's logs?

They are kept in while, for 14 days on the Free plan, and your agent reads them too.
