Sentry for Pi Durable
Learn how to send Pi Durable agent runs, model requests, tool calls, and errors to Sentry with the Sentry SDK.
Pi Durable is Earendil's durable agent harness, built on the same foundations as the Pi coding agent. It runs many conversations at once and survives crashes, picking each run up from its last checkpoint. This guide sets up the Sentry SDK in a Pi Durable app so agent runs, model requests, tool calls, and errors flow into Sentry Agent Tracing.
Pi Durable is experimental, and its API can change between releases. The Sentry integration supports @earendil-works/pi-durable >=1.0.0 <2.0.0 and requires JavaScript SDK version 11.6.0 or later.
Before you begin, you need:
- A Sentry account and project. The project's DSN tells the SDK where to send data.
- A Node.js application using
@earendil-works/pi-durableversion1.0.0or later. @sentry/nodeversion11.6.0or later. Browser runtimes are not supported.
Choose the features you want to configure, and this guide will show you how:
Install the Sentry Node SDK:
npm install @sentry/node@^11.6.0
npm install @sentry/node@^11.6.0
yarn add @sentry/node@^11.6.0
pnpm add @sentry/node@^11.6.0
npm install @sentry/node@^11.6.0 @sentry/profiling-node@^11.6.0
npm install @sentry/node@^11.6.0 @sentry/profiling-node@^11.6.0
yarn add @sentry/node@^11.6.0 @sentry/profiling-node@^11.6.0
pnpm add @sentry/node@^11.6.0 @sentry/profiling-node@^11.6.0
Create an instrument file that calls Sentry.init(). The Pi Durable integration is enabled by default, so you don't add it to integrations:
instrument.mjsimport * as Sentry from "@sentry/node";
// ___PRODUCT_OPTION_START___ profiling
import { nodeProfilingIntegration } from "@sentry/profiling-node";
// ___PRODUCT_OPTION_END___ profiling
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ profiling
// Add our Profiling integration
nodeProfilingIntegration(),
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of spans for tracing.
// We recommend adjusting this value in production.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/node/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
// Set profileSessionSampleRate to 1.0 to profile every session.
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#profileSessionSampleRate
profileSessionSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ profiling
});
import * as Sentry from "@sentry/node";
// ___PRODUCT_OPTION_START___ profiling
import { nodeProfilingIntegration } from "@sentry/profiling-node";
// ___PRODUCT_OPTION_END___ profiling
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ profiling
// Add our Profiling integration
nodeProfilingIntegration(),
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of spans for tracing.
// We recommend adjusting this value in production.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/node/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
// Set profileSessionSampleRate to 1.0 to profile every session.
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#profileSessionSampleRate
profileSessionSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ profiling
});
Preload the instrument file with the --import flag when you start your app:
package.json{
"scripts": {
"start": "node --import ./instrument.mjs server.mjs"
}
}
{
"scripts": {
"start": "node --import ./instrument.mjs server.mjs"
}
}
The SDK instruments Harness.open() while Node.js loads @earendil-works/pi-durable, so Sentry has to start before your app imports it. If you import the instrument file from your app instead of preloading it, the SDK can't instrument Pi Durable. If you bundle your server and can't pass --import, use the bundler plugin instead.
Your Pi Durable code doesn't change. Every Harness your app opens is traced, whichever storage and execution environment it uses:
server.mjsimport { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
import { createModels } from "@earendil-works/pi-ai/models";
import { openaiProvider } from "@earendil-works/pi-ai/providers/openai";
import { createRegistry, Harness } from "@earendil-works/pi-durable";
import { openNodeSqliteStorage } from "@earendil-works/pi-durable/storage/sqlite/node";
const context = BACKGROUND_CONTEXT;
const models = createModels();
models.setProvider(openaiProvider());
const harness = await Harness.open(
await openNodeSqliteStorage("./agent.sqlite"),
{ models, registry: createRegistry() },
context,
);
harness.resume();
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
import { createModels } from "@earendil-works/pi-ai/models";
import { openaiProvider } from "@earendil-works/pi-ai/providers/openai";
import { createRegistry, Harness } from "@earendil-works/pi-durable";
import { openNodeSqliteStorage } from "@earendil-works/pi-durable/storage/sqlite/node";
const context = BACKGROUND_CONTEXT;
const models = createModels();
models.setProvider(openaiProvider());
const harness = await Harness.open(
await openNodeSqliteStorage("./agent.sqlite"),
{ models, registry: createRegistry() },
context,
);
harness.resume();
With this setup, Sentry captures errors thrown by your tools and extensions, and AI spans for every run (agent runs, model requests, tool calls, token usage, and latency). Manual spans you start inside a tool nest under that tool's span. Prompts and model outputs are recorded on your AI spans by default.
To review what's captured and turn recording of prompts and responses off, see Control the Data You Send to Sentry below.
By default, the SDK sends user identity data (IP address, ID, and similar) and other data like HTTP bodies and URL query parameters. This will give you rich debugging context.
The SDK always filters sensitive values whose keys match a built-in denylist, such as auth or password, and sends [Filtered] instead.
To send less data, turn off the categories you don't need in the dataCollection option. For the full list of categories and their defaults, see the dataCollection options.
Sentry.init({
dsn: "___PUBLIC_DSN___",
dataCollection: {
userInfo: false,
// other categories
},
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
dataCollection: {
userInfo: false,
// other categories
},
});
To change recording for Pi Durable only, pass recordInputs and recordOutputs to the integration. They take precedence over dataCollection:
instrument.mjsSentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.piDurableIntegration({
recordInputs: false,
recordOutputs: false,
}),
],
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.piDurableIntegration({
recordInputs: false,
recordOutputs: false,
}),
],
});
Sentry groups the runs of a Pi Durable conversation into a single Conversation automatically — there's no Sentry-specific setup. The SDK sets gen_ai.conversation.id on the agent, model, and tool spans of every run to <harness id>:<conversation id>.
Pi Durable numbers conversations per storage, starting from 1, so the SDK prefixes a random id for each opened Harness to keep root conversations from different storages apart. This id changes when the Harness reopens, for example after a process restart or after a Durable Object restarts. Runs from before and after a restart then show up as separate conversations in Sentry.
A subagent runs in a conversation of its own. Its first run nests under the tool call that created it, so the subagent shows up inside the parent's trace.
Submit a message to one of your conversations, ideally one that calls a tool. Then open Explore → Agents in Sentry. Select the conversation to open its detail. The timeline shows the agent run, model requests, tool calls, token usage, latency, and any errors your tools threw.
If no data appears, confirm that:
- The
dsnbelongs to the Sentry project you're viewing. tracesSampleRateis greater than0.- Your app completed at least one run after you added the setup.
- No AI spans at all. Confirm the instrument file is preloaded with
--import, or that your bundle is built with the Sentry bundler plugin. Importing it at the top of your entry file runs too late, because@earendil-works/pi-durableis already loaded by then. - OpenAI, Anthropic, or Google Gen AI calls outside Pi Durable stopped showing up. Once a Pi Durable run starts, the SDK turns off these provider integrations for the whole process, so Pi Durable's model requests aren't counted twice. See What gets captured? below.
- Track AI agent spend with dashboards and alerts: build a dashboard for cost, tokens, models, and conversations.
- Pi Durable's README: conversations, tasks, extensions, and storage, from the Pi side.
- Use the appropriate JavaScript framework guide for application monitoring in a separate frontend or service.
@sentry/node:>=11.6.0@sentry/cloudflare:>=11.6.0@sentry/deno:>=11.6.0@sentry/bun:>=11.6.0@earendil-works/pi-durable:>=1.0.0 <2.0.0
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").