← Back to Cookbook

Monitor your pi coding agent sessions with Sentry

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

Category Monitoring
Time
10 minutes
Complexity
Beginner
Steps
5 steps

Before you start

SDKs & packages
  • pi 0.87.0 or later installed and configured
  • Node.js 22.19+ installed
Accounts & access
Knowledge
  • Basic familiarity with pi's settings.json

1
Create a Sentry project

In Sentry, create a new project for your pi monitoring data. Go to 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

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.

@sentry/pi on npm
Terminal
pi install npm:@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.

@sentry/pi configuration options
~/.pi/agent/settings.json
{
  "sentry": {
    "dsn": "https://<your-dsn>@o<org>.ingest.sentry.io/<project-id>",
    "org": "my-org",
    "environment": "local"
  }
}

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 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
Sentry AI Agents dashboard showing pi sessions with invoke_agent root spans, request and execute_tool child spans with token counts and costs, and gen_ai.invoke_agent span details including input, output, and attributes

That's it.

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.

  • 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

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.

Frequently asked questions

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

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

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.

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.

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

Fix it, don't observe it.

Get started with the only application monitoring platform that empowers developers to fix application problems without compromising on velocity.