← Catalog

@the-agency/pi-observability

Record tool usage, tokens, models, skills, and sessions as OpenTelemetry GenAI spans.

Package

Install

Install with PiG

pig install npm:@the-agency/pi-observability

Install with Pi

pi install npm:@the-agency/pi-observability
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.4.0 (README.md). PiG does not review it.

@the-agency/pi-observability

NPM Downloads

Pi extension that emits one OTel GenAI-compatible span per assistant turn. Spans are always exported — to an OTLP collector when one is configured, or to local JSONL files otherwise.

What it captures

Each span represents one LLM API call and includes:

  • OTel GenAI semantic convention attributes (gen_ai.*)
  • Token usage and cost per turn (gen_ai.usage.*, cost.*)
  • Full assistant text, thinking blocks, tool calls, and tool results
  • User message text (skill injection blocks stripped)
  • Session context: working directory, session file, session ID, active skills, tools, and registered commands
  • Model and provider info, thinking level, response ID
  • A stable pi.turn.exchange_id grouping all turns from one user prompt

Sinks

File sink (default)

When no OTLP endpoint is configured, spans are written to daily JSONL files:

~/.pi/observability/YYYY-MM-DD.jsonl

One JSON object per line, one file per day. Useful for local inspection with jq or importing into any tool that accepts JSONL.

The status bar shows ⬡ otlp:file.

OTLP sink

Set OTEL_EXPORTER_OTLP_ENDPOINT to send spans to any OTLP-compatible backend (Grafana Tempo, Jaeger, Elastic APM, Honeycomb, Datadog, etc.).

VariableDescription
OTEL_EXPORTER_OTLP_ENDPOINTOTLP collector URL (e.g. http://localhost:4318)
OTEL_EXPORTER_OTLP_HEADERSComma-separated key=value auth headers
OTEL_EXPORTER_OTLP_PROTOCOLhttp/json (default), http/protobuf, or grpc
OTEL_SERVICE_NAMEOverrides the default service name (pi-coding-agent)

These are the standard OpenTelemetry environment variables — no extension-specific configuration required.

The status bar shows ⬡ otlp:<host> where <host> is the collector's hostname and port.

Span attributes

AttributeTypeDescription
gen_ai.systemkeywordNormalized provider name (e.g. anthropic, openai)
gen_ai.operation.namekeywordAlways chat
gen_ai.request.modelkeywordModel ID sent in the request
gen_ai.response.modelkeywordModel ID returned in the response
gen_ai.response.finish_reasonskeyword[]Stop reason(s) from the provider
gen_ai.usage.input_tokenslong
gen_ai.usage.output_tokenslong
gen_ai.usage.cache_read_input_tokenslong
gen_ai.usage.cache_creation_input_tokenslong
gen_ai.usage.total_tokenslong
message.user.texttextUser prompt text
message.assistant.texttextAssistant response text
message.assistant.thinkingtextThinking block content, if present
tool_callsjson{id, name, arguments, arguments_text} per call
tool_resultsjson{tool_call_id, tool_name, output} per result
turn.tool_call_countlong
turn.tool_result_countlong
pi.session.idkeywordStable session UUID (also used as OTel trace ID)
pi.session.cwdkeywordWorking directory
pi.session.startISO-8601Session start time
pi.session.filekeywordPath to the .pi session file
pi.session.skillsjson{name, path, source, scope} for each loaded skill
pi.session.skill_nameskeyword[]Skill names only
pi.session.toolsjson{name, source, scope} for each active tool
pi.session.active_toolskeyword[]Active tool names only
pi.session.commandskeyword[]Registered slash command names
pi.turn.exchange_idkeywordUUID shared across all turns in one user prompt
pi.model.providerkeywordRaw provider name from pi
pi.model.apikeywordAPI identifier
pi.thinking_levelkeywordThinking level if set
pi.thinking.presentbooleanWhether a thinking block was present
pi.response_idkeywordProvider response ID
cost.total_usdfloat
cost.input_usdfloat
cost.output_usdfloat

Attributes with no value are omitted.

Installation

Project-local

Add to .pi/settings.json in your project:

{
  "packages": ["npm:@the-agency/pi-observability"]
}

Global

pi install npm:@the-agency/pi-observability

Examples

Local file sink (no configuration needed)

pi chat
# spans written to ~/.pi/observability/YYYY-MM-DD.jsonl

Inspect with jq:

jq '.attributes["gen_ai.usage.input_tokens"]' ~/.pi/observability/$(date +%Y-%m-%d).jsonl

Send to a local OTel collector

export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
pi chat

Send to Elastic APM

export OTEL_EXPORTER_OTLP_ENDPOINT=https://your-cluster.apm.us-east-1.aws.cloud.es.io
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your_secret_token"
pi chat