pi (tracing)
pi is a minimal terminal coding agent. The @respan/instrumentation-pi package is a pi extension that traces your pi sessions to Respan: every turn, model call, tool execution, and compaction. Nothing is written to disk on your machine; spans are batched in memory and sent straight to Respan.
This page covers interactive pi sessions in the terminal. To trace the @earendil-works/pi-coding-agent SDK inside your own application, see Pi Coding Agent SDK.
Set up Respan
Create an account at platform.respan.ai and grab an API key.
For application setup, follow Agent setup.
Use Respan Gateway
See pi gateway setup to route pi’s model calls through the Respan gateway. Every LLM call is then logged by the gateway with no SDK; the extension on this page adds the agent-level structure (turns, tool calls, threads) on top.
Package README
@respan/instrumentation-piREADME — full option, configuration, and troubleshooting reference
How it works
The extension traces pi by observing it, not by proxying it:
- pi talks to its model provider directly.
- pi’s native extension events notify the extension when sessions start, turns run, models respond, and tools execute.
- The extension turns those events into OpenTelemetry spans and sends them to Respan from inside the pi process. There is no daemon, no local journal, and no log directory: if Respan is unreachable, the batch is retried and then dropped, and pi keeps working. For guaranteed delivery through outages, see Delivery guarantees.
- Credentials come from
RESPAN_API_KEYor from~/.respan/credentials.jsonwritten byrespan auth login; the extension never stores them in its own config.
Each prompt you send appears in Respan as one trace with turn, model call, and tool spans; all traces of a pi session share the session id as thread id. See What gets traced.
Set up tracing
The extension requires pi v0.65.0 or later.
Restart pi
Restart pi so it loads the extension. The footer shows Respan: tracing while active, and after each prompt a widget below the editor shows a link to its trace.
View your trace
Open the Traces page. Each pi session is one trace and every prompt adds a turn to it, even after a restart or a week-long pause; the Threads view shows the whole pi session as a conversation.
What gets traced
Each agent run (one prompt → agent_end) is one root agent span, pi.turn-<n>.agent, displayed as agent.turn-<n> — n is the prompt’s number within the pi session, so a session resumed with pi -c continues at the next turn.
Chat and tool spans are sent the moment they complete, so a long-running turn streams into the dashboard while it is still running; the turn span arrives when the run ends.
Steering
When you send a message while pi is still working, pi does not start a new run. It queues the message and delivers it into the running turn at the next tool boundary, and the agent carries on with the new information. Respan records each delivered message as its own row under the turn, named steer.turn-<n>, at the exact point pi injected it:
Turn numbers. Turn numbers count the session’s user messages, which keeps them stable when a session is resumed in another process. A steered message takes the next number, so a turn-1 run that received three steers (steer.turn-2, steer.turn-3, steer.turn-4) is followed by agent.turn-5. Nothing was skipped: the numbers in between are the steer rows inside the turn.
Find steers across traces. On the Spans page, filter by custom property:
after_steeristrue: exactly the model calls that reacted to a steered message.steer_countis1(or2,3, …): the turn spans that received that many steers.steered_into_turnis1: the steer spans delivered into turn 1, each with its message as input.
A steer is an event inside the run, not a new run: the steps after it stay under the same turn, because the agent usually keeps working on its original task while taking the new message into account.
Steer spans require @respan/instrumentation-pi 0.1.5 or later.
Upgrade with pi update npm:@respan/instrumentation-pi.
Settings
Save non-secret configuration to ~/.pi/agent/respan.json. A project-level .pi/respan.json overrides it, and environment variables override both. The API key is never written to these files.
Trace scope decides what one trace is:
session(default): every prompt of the session joins one trace whose id is derived from the pi session id, so a session resumed withpi -cin another process, or after a week-long pause, keeps adding turns to the same trace. Respan shows the turns as multiple roots under one synthetic root, ordered by time; the trace’s duration spans from the first to the latest turn. No span is ever held open across idle time.run: every prompt is its own trace with its own cost and latency. All traces of the session still sharethread_identifier= the pi session id, so the Threads view shows the whole session in order.
To switch:
Common workflows
Install for one project only
This records the extension in the project’s .pi/settings.json instead of ~/.pi/agent/settings.json.
Turn tracing off temporarily
For a persistent change, ask your coding agent to set enabled: false in the tracing configuration. The package remains installed.
Non-interactive runs
pi -p "..." runs are traced the same way; the extension flushes before pi exits.
Upgrade
Uninstall
Delivery guarantees
Inside the pi process, spans are batched in memory and posted to Respan with retries. Nothing is written to your disk, so nothing piles up on the machine, and a session that sits idle for days costs nothing. The trade-off is that if Respan is unreachable for longer than the retry window while pi is running, that batch is lost.
If you need at-least-once delivery through outages and restarts, run the Respan Collector (see the CLI) next to pi and point the extension at it:
The collector keeps a bounded on-disk queue that drains as soon as Respan acknowledges the data; it never grows without limit.
Troubleshooting
Traces do not appear. Check the following, in order:
- Verify the extension is installed:
pi listshould shownpm:@respan/instrumentation-pi. - Verify the key is available:
RESPAN_API_KEYis set, orrespan auth statusshows you are logged in. If credentials are missing, use the setup prompt above. - Verify tracing is enabled:
enabledis notfalsein~/.pi/agent/respan.jsonor.pi/respan.json, andRESPAN_PI_TRACINGis not set tofalse. - Restart pi after any configuration change, then run at least one prompt; the turn span is sent when the run ends.
- Run
RESPAN_PI_DEBUG=1 pito print the extension’s diagnostics to stderr (initialization, export errors).
Tracing failures never interrupt pi: the session keeps working even when traces do not appear, and the footer shows Respan: tracing unavailable: <reason>.
Turn numbers skip, for example agent.turn-1 is followed by agent.turn-5. The turn in between received steered messages, and each one took a number. Expand the turn to see the steer.turn-<n> rows. See Steering.
The trace link widget does not appear. The widget is only shown in interactive mode, after the first completed prompt, and only for the Respan cloud endpoint (self-hosted or collector-routed setups show the footer status only).
Resources
@respan/instrumentation-pion npm- Package README — full configuration reference
- Pi Coding Agent SDK — trace pi inside your own application
- CLI: collector commands
- pi documentation