AAnvio
Monitoring

Logging

Anvio's structured JSON logs, workspace audit ledgers, and the CLI commands used to inspect them.

3 min read

Anvio's observability model (docs/13-observability.md) is built on three pillars: structured JSON logs, OpenTelemetry traces (see Tracing), and file-based audit ledgers under workspace/audit/ and workspace/sessions/. This page covers logs and the durable audit trail; see Metrics for counters and Tracing for spans.

Anvio is file-first by design (see Docker and the deployment-levels table) — most of what you'd call "logs" in a traditional service are actually durable, greppable files under workspace/, not a centralized log aggregator. That's intentional at Level 1–2; wire OTel + an external sink once you outgrow it.

Session logs and transcripts

Every agent run is recorded under workspace/sessions/. Retrieve a specific session's log via:

anvio logs <sessionId>

For multi-agent orchestration (a manager session delegating to subagents), pull the whole tree:

anvio logs --orchestration <managerSessionId>

For automations specifically:

anvio logs --automation daily-summary

Trajectory export

Full session trajectories (the complete tool-call and message history) can be exported for offline review or sharing:

anvio session export <id>
anvio session export <id> --md    # Markdown-formatted trajectory

Shipped in Phase P14 — see docs/75-phase-p14-priorities.md and the gap register (docs/69-post-v1.17-gap-register.md, item O1).

Audit ledgers

Several append-only JSONL ledgers live under workspace/audit/ and are the durable counterpart to the in-memory metrics registry (see Metrics):

LedgerWritten byFormat
workspace/audit/tokens.jsonlModel completions{"ts":"...","pool":"anthropic","credId":"key2","tokens":1523,"status":"ok"}
workspace/credentials/audit/usage.jsonlCredential pool acquisitions/rotationsUsage and rotation events per credential
workspace/audit/hooks/Hook engine dispatchPer-handler execution logs
workspace/audit/sessions.logExample custom hook output (hooks/on-session-start.sh)Free-form, defined by the hook script author

Query token usage with the CLI rather than grepping the file directly:

anvio usage stats
anvio usage stats --json
anvio usage stats --last 24h

Hook-based custom logging

The event hook system (docs/31-event-hooks.md) is the extension point for custom log handlers — script, MCP, or webhook handlers can be attached to lifecycle events without touching core code:

# workspace/hooks/hooks.yaml
apiVersion: anvio.io/v1
kind: HookRegistry
spec:
  hooks:
    - event: onToolExecuted
      handlers:
        - type: script
          path: hooks/audit-tool.sh
          filter:
            toolName: filesystem.write

A script handler receives the event payload as JSON on stdin and must exit 0 on success:

#!/bin/bash
# hooks/on-session-start.sh
payload=$(cat)
session_id=$(echo "$payload" | jq -r '.sessionId')
echo "[$(date)] Session started: $session_id" >> workspace/audit/sessions.log

Available lifecycle events: onSessionStart, onSessionEnd, onGoalCreated, onGoalCompleted, onTaskAssigned, onTaskCompleted, onToolExecuted, onWorkflowCompleted, onSoulEvolved, onAutomationFailed. See Alerts for using this same mechanism to push notifications rather than just write logs.

OTel-based structured logs (production)

For centralized log/trace correlation beyond the local workspace files, point the same OTLP pipeline used for tracing at your collector:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export OTEL_SERVICE_NAME=anvio
export OTEL_TRACES_EXPORTER=otlp

See Tracing for the full OTLP/Langfuse configuration — logs and traces share the same exporter endpoint convention (OTEL_EXPORTER_OTLP_ENDPOINT).

TODO: No dedicated structured-logging library (pino, winston, etc.) was found wired into packages/ at this pass — logging in the current codebase is primarily the file-based audit ledgers above plus whatever OTel auto-instrumentation captures. If you need application-level structured logs beyond audit ledgers and OTel spans, check for updates in a newer release before assuming a specific logger is in place.

Debugging with logs — quick reference

QuestionWhere to look
Did session X complete, and what did it do?anvio logs <sessionId> or anvio session export <sessionId> --md
How many tokens / what did agent Y cost today?anvio usage stats --last 24h
Is MCP server Z healthy, and has it restarted?anvio mcp health
Did automation "daily-summary" run and what happened?anvio logs --automation daily-summary
Did a delegated subagent run fail?anvio logs --orchestration <managerSessionId>
Edit on GitHub

Last updated on

On this page