# Monitor your pi coding agent sessions with Sentry

> Add Sentry AI observability to pi in minutes with @sentry/pi. Track tool calls, LLM calls, token usage, and model costs across every pi coding session.

**URL:** https://sentry.io/cookbook/monitor-pi-with-sentry/

---

Add the official @sentry/pi extension to get full visibility into tool calls, token usage, and model costs across every pi session.

**Time:** 10 minutes | **Difficulty:** Beginner

## What You'll Learn

- Installed the @sentry/pi extension into pi

- Connected pi sessions to Sentry AI Observability

- Tracked tool calls, LLM calls, token usage, and costs per prompt

- Explored per-session conversations and traces in Sentry

**Topics:** Tracing, AI Observability, Agent Tracing

## Before you start

**SDKs & packages**

- [pi](https://pi.dev/) 0.87.0 or later installed and configured

- Node.js 22.19+ installed

**Accounts & access**

- [Sentry account](https://sentry.io/signup/) with a Node.js project created

**Knowledge**

- Basic familiarity with pi's `settings.json`

## Steps

### 1. Create a Sentry project

In Sentry, create a new project for your pi monitoring data. Go to [Settings → Projects](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/) and click **Create Project**. Select **Node.js** as the platform, give it a name like `pi`, and copy the DSN from the project settings — you'll need it in step 3.

[Creating a Sentry project](https://docs.sentry.io/product/sentry-basics/getting-started-tutorial/create-new-project/)

### 2. Install the extension

Install `@sentry/pi` with the `pi install` command. It's installed globally, so it covers every pi session on your machine.

```bash
pi install npm:@sentry/pi
```

[@sentry/pi on npm](https://www.npmjs.com/package/@sentry/pi)

### 3. Configure your DSN

Add a `sentry` object to pi's global settings at `~/.pi/agent/settings.json` with your DSN. Set `org` to your organization slug to get a link to the current conversation in pi's status bar. You can also set any option with an environment variable, like `SENTRY_PI_DSN`, which takes priority over `settings.json`.

```json
{
  "sentry": {
    "dsn": "https://<your-dsn>@o<org>.ingest.sentry.io/<project-id>",
    "org": "my-org",
    "environment": "local"
  }
}
```

[@sentry/pi configuration options](https://github.com/getsentry/sentry-agent-tracing/tree/main/packages/pi#configuration)

### 4. Verify the setup

Start pi and run the `/sentry` command. It shows whether tracing is enabled and where each setting comes from, so you can confirm your DSN was picked up.

### 5. Explore traces in Sentry

Send a few prompts and then head to [Explore > Agents](https://sentry.io/orgredirect/organizations/:orgslug/explore/agents/) in Sentry and open the **Traces** tab. Each prompt appears as an `invoke_agent` root span, and all prompts in a pi session are grouped into one conversation. Expand any trace to see `chat` spans for each model request, including token usage and cost, and `execute_tool` spans for every tool call.

[AI Observability documentation](https://docs.sentry.io/product/agents/)

## Summary

**Every tool call, tracked.**

You get a complete picture of how pi uses models and tools across your sessions — including token usage and costs — so you can tune it, debug it, and understand exactly what it's doing.

## Pro Tips

- Set `org` in your settings to get a "Go to conversation" link in pi's status bar that opens the current session in Sentry.

- Use `environment` to separate sessions, for example `work` and `personal`. A trusted project can also set its own `environment` in `.pi/settings.json`.

## Common Pitfalls

- Putting the DSN in a project's `.pi/settings.json` — it's ignored. A project can only set `environment` and turn data collection off, so the DSN must live in `~/.pi/agent/settings.json` or `SENTRY_PI_DSN`.

- Without a DSN the extension does nothing — run `/sentry` in pi to confirm tracing is enabled.

## FAQ

**Does this work with all LLM providers in pi?**

Yes. The extension instruments pi's session, model request, and tool layer, so it captures data regardless of which model provider you have configured.

**Will this slow down my coding sessions?**

No. Sentry uses asynchronous, non-blocking transport. Spans are batched and sent in the background with negligible performance impact.

**How much does it cost in Sentry?**

Tracing is billed by span volume. Every prompt sends one trace, with a span for each model request and tool call. Sentry's free Developer plan includes 5M spans/month — more than enough to get started.

**Can I keep my prompts and code out of Sentry?**

Yes. Set `dataCollection.genAI.inputs` to `false` to leave out prompts, system prompts, and tool arguments, and `dataCollection.genAI.outputs` to `false` to leave out responses, summaries, and tool results. You still get timings, token usage, and costs.

**Can I use this in a team setting?**

Yes. Each developer installs the extension and configures the same Sentry DSN, using `environment` to filter sessions per developer or team.

## Next Steps

- [Set up alerts on token spend](https://sentry.io/orgredirect/organizations/:orgslug/monitors/alerts/): Create a Sentry alert to notify you when token usage or cost spikes unexpectedly across your pi sessions.

- [Explore full trace details](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/): Use the Trace Explorer to drill into individual pi sessions and see every LLM call and tool invocation.

- [AI Observability docs](https://docs.sentry.io/product/agents/): Learn more about how Sentry tracks token usage, model costs, and tool calls for AI applications.

---

*Source: [sentry.io/cookbook/monitor-pi-with-sentry/](https://sentry.io/cookbook/monitor-pi-with-sentry/)*
