# Add AIssue error monitoring to a project

This guide is written for AI coding agents (Claude Code, Cursor, Copilot, …) and works for humans too.

AIssue receives the errors an application throws, groups them into issues, and uses AI plus the project's source code to explain the root cause and suggest a fix. Setting it up means:

1. Getting a **DSN**: the address the SDK sends errors to.
2. Installing a small SDK.
3. Sending one test error to check it works.

## Rules for the agent

- Make the smallest change that works. Do not refactor or reformat unrelated code.
- **Never** write the user's AIssue API token into a file, a commit, a log, or output you show. Keep it in a shell variable for this session only.
- Put the DSN in environment variables (`.env`, `.env.local`, the hosting provider's settings), not in committed code, except where a browser bundle needs it inline (the guide says when). Make sure `.env*` files are git-ignored.
- If the repository holds several applications, or the setup is unusual, ask the user which one to set up.
- If the project restricts new dependencies, ask before installing.



## 1. Detect the stack

| You find | Follow |
|---|---|
| `manage.py`, or `django` in `requirements*.txt` / `pyproject.toml` | https://aissue.yourgenlab.com/install/django.md |
| `next` in `package.json` | https://aissue.yourgenlab.com/install/nextjs.md |
| `react` in `package.json` (without `next`) | https://aissue.yourgenlab.com/install/react.md |
| A Node.js server (`express`, `fastify`, `koa`, `@nestjs/core`, or plain `node`) | https://aissue.yourgenlab.com/install/node.md |
| `flask` in the Python dependencies | https://aissue.yourgenlab.com/install/flask.md |
| `fastapi` or `starlette` in the Python dependencies | https://aissue.yourgenlab.com/install/fastapi.md |
| Other Python: Celery, scripts, workers | https://aissue.yourgenlab.com/install/python.md |
| `go.mod` | https://aissue.yourgenlab.com/install/go.md |
| `Gemfile` (Ruby, Rails) | https://aissue.yourgenlab.com/install/ruby.md |
| `composer.json` (PHP, Laravel, Symfony) | https://aissue.yourgenlab.com/install/php.md |
| `pom.xml`, `build.gradle` or `build.gradle.kts` (Java, Kotlin, Spring) | https://aissue.yourgenlab.com/install/java.md |
| `*.csproj` or `*.sln` (.NET, ASP.NET Core) | https://aissue.yourgenlab.com/install/dotnet.md |
| An existing Sentry SDK (`sentry_sdk`, `@sentry/*`, `sentry-ruby`, …), any language | https://aissue.yourgenlab.com/install/sentry.md (only the DSN changes) |
| Anything else | https://aissue.yourgenlab.com/install/http.md |

A repository with a backend and a frontend of the **same application** (for example Django + React) uses one domain: follow both guides with the same DSN. Separate applications should each get their own domain.

## Get the DSN

The DSN tells the SDK where to send errors. It looks like `https://<key>@aissue.yourgenlab.com/<number>`.

**If the user already gave you a DSN, use it and skip this section.**

Otherwise, ask the user:

> Please paste your AIssue API token. You can create one at https://aissue.yourgenlab.com/app/account/tokens.

Then, in the shell (the token stays in this session only):

```bash
export AISSUE_TOKEN='<the token the user gave you>'
curl -s https://aissue.yourgenlab.com/api/v1/domains -H "Authorization: Bearer $AISSUE_TOKEN"
```

- If one of the listed domains clearly belongs to this project, use its `id` and `dsn`.
- Otherwise create one, named after the project (for example the repository or package name):

```bash
curl -s -X POST https://aissue.yourgenlab.com/api/v1/domains \
  -H "Authorization: Bearer $AISSUE_TOKEN" -H "Content-Type: application/json" \
  -d '{"name": "<project name>"}'
```

The response contains the domain `id` and its `dsn`. If it says the plan's domain limit is reached, tell the user.



## 2. Install and configure

Fetch the guide for the stack you detected and follow its steps. It shows the exact files and lines to add.

With the API token you can also get the steps with the DSN already filled in:

```bash
curl -s "https://aissue.yourgenlab.com/api/v1/domains/<domain id>/setup?framework=<django|nextjs|react|node|flask|fastapi|python|go|ruby|php|java|dotnet|sentry|http>" \
  -H "Authorization: Bearer $AISSUE_TOKEN"
```

## Verify that errors arrive

1. Send a test error with the command in the verification step above.
2. Check that it arrived (needs the API token; if you only have a DSN, ask the user to look at their AIssue dashboard instead):

```bash
curl -s "https://aissue.yourgenlab.com/api/v1/domains/<domain id>/events?limit=5" -H "Authorization: Bearer $AISSUE_TOKEN"
```

   Look for an event titled `RuntimeError: AIssue setup test` (or `Error: AIssue setup test`). It usually appears within a few seconds.
3. Resolve the test issue so it doesn't clutter the dashboard (`issue_id` is in the event):

```bash
curl -s -X POST https://aissue.yourgenlab.com/api/v1/issues/<issue_id>/resolve -H "Authorization: Bearer $AISSUE_TOKEN"
```

If nothing arrives, check:
- the DSN is exactly right;
- the environment variable is loaded where the command ran;
- the machine can reach `aissue.yourgenlab.com`;
- the SDK isn't disabled in development (the guide says how to enable it for the test).

## Finish

Tell the user:
- which files you changed;
- that `AISSUE_DSN` (and any other variables you added) must also be set in their **production** environment, for example in the hosting provider's dashboard;
- that errors are reported from production by default, not from local development.

**Recommend connecting GitHub.** AI analyses can then point at the exact file, line and commit. It needs the user in a browser:

```bash
curl -s https://aissue.yourgenlab.com/api/v1/domains/<domain id>/github -H "Authorization: Bearer $AISSUE_TOKEN"
```

Give the user the `connect_url` from that response.

**Deployed commit.** AIssue reads the exact deployed code when the SDK knows the git commit. This is automatic on Vercel, Render, Railway, Heroku, Cloudflare Pages and GitHub Actions. With Docker or other hosts, set `AISSUE_RELEASE` to the commit SHA at deploy time, for example `--build-arg AISSUE_RELEASE=$(git rev-parse HEAD)` plus `ENV AISSUE_RELEASE=$AISSUE_RELEASE` in the Dockerfile.


## API reference

https://aissue.yourgenlab.com/install/api.md
