Why tracing matters
Tracing helps you understand:- LLM costs — Token counts per role, per session, per day
- Performance — Request latency, timeouts, bottlenecks
- Quality — Prompt/completion pairs, tool call sequences, agent reasoning
- Errors — Failures, retries, fallback triggers
Lerim uses minimal stderr logging by design. Detailed telemetry goes through OTel spans instead of cluttering your terminal.
What gets traced
When tracing is enabled, Lerim captures:| Event type | Details captured |
|---|---|
| Model calls | Provider, model, prompt, completion, tokens (input/output), latency |
| Tool calls | Tool name, arguments, results, duration |
| Agent iterations | Lead agent reasoning steps, explorer subagent calls |
| Extraction | DSPy pipeline execution, window processing, candidate generation |
| Maintain | Merge decisions, archive operations, decay calculations |
| HTTP requests | API request/response bodies (if include_httpx = true) |
By default, prompt and completion text is included in traces (
include_content = true). If you handle sensitive data, set include_content = false to exclude LLM inputs/outputs from traces.Setting up Logfire
Lerim uses Logfire as the default tracing backend. Logfire is built by Pydantic and has a generous free tier (includes 500M spans/month as of 2024).One-time setup
- Install Logfire:
- Authenticate:
- Create a project:
What if I already have a Logfire account?
What if I already have a Logfire account?
If you already have a Logfire account:Lerim will use your default Logfire project. You can create a new project specifically for Lerim with:
Enabling tracing
There are two ways to enable tracing:Option 1: Environment variable (quick toggle)
SetLERIM_TRACING=1 before running Lerim commands:
- Testing tracing without changing config files
- One-off debugging sessions
- CI/CD environments
Option 2: Configuration file (persistent)
Enable tracing in your config file:~/.lerim/config.toml (global):
<repo>/.lerim/config.toml (project-specific):
The daemon (
lerim up or lerim serve) loads tracing config once at startup. If you enable tracing while the daemon is running, restart it: lerim down && lerim upViewing traces
Open the Logfire web UI:Understanding traces
Each Lerim operation creates a trace with nested spans:- Full prompt and completion
- Token counts (input/output)
- Request duration
- Tool call arguments and results
- Error details (if any)
Tracing configuration
The[tracing] section in config.toml controls tracing behavior:
Enable OpenTelemetry tracing. Can also be enabled with
LERIM_TRACING=1.Capture raw HTTP request/response bodies in traces. Useful for debugging provider API issues, but increases trace size.
Include prompt and completion text in trace spans. Set to
false if you handle sensitive data and want to exclude LLM inputs/outputs from traces.Example configurations
Default (content included, no HTTP bodies):Environment variable override
TheLERIM_TRACING environment variable overrides the [tracing].enabled config setting:
| Config | Env var | Result |
|---|---|---|
enabled = false | (not set) | Tracing OFF |
enabled = false | LERIM_TRACING=1 | Tracing ON |
enabled = true | (not set) | Tracing ON |
enabled = true | LERIM_TRACING=0 | Tracing ON (env var must be 1, true, yes, or on to enable) |
The env var only enables tracing — it doesn’t disable it. To turn off tracing, set
enabled = false in config or unset the env var.Use cases
Debugging extraction failures
Iflerim sync fails to extract memories from sessions:
-
Enable tracing:
- Open Logfire and find the failed sync run
-
Look at the extraction spans:
- Did the model call succeed?
- Were candidates generated?
- What was the prompt?
- What was the output?
Monitoring token usage
To understand which role uses the most tokens:-
Enable tracing in config:
-
Run Lerim for a day:
-
Open Logfire and create a dashboard:
- Chart 1: Token count by model (lead, explorer, extract, summarize)
- Chart 2: Cost per role (if provider reports cost)
- Chart 3: Request count per role
Measuring sync performance
To see how long sync takes and where time is spent:-
Enable tracing:
- Open the sync trace in Logfire
-
Check span durations:
- Index sessions: < 1s (scanning files)
- Extract candidates: 3-10s (LLM calls)
- Lead agent: 5-20s (LLM + tool calls)
[roles.extract].
Investigating errors
If Lerim errors out:- Check traces in Logfire
- Find the error span (marked red)
-
View error details:
- Exception type and message
- Stack trace
- Inputs that caused the error
- Retries and fallbacks
Disabling tracing
To turn off tracing:-
Remove env var:
-
Or set config:
-
Restart daemon if running:
Disabling tracing doesn’t delete existing traces from Logfire — they remain in your project history. To delete traces, use the Logfire web UI.
Alternative backends
Lerim uses PydanticAI’s OpenTelemetry instrumentation, which means you can send traces to any OTel-compatible backend:- Logfire (default, recommended)
- Datadog APM
- Honeycomb
- New Relic
- Jaeger
- Zipkin
Troubleshooting
Tracing enabled but no spans in Logfire
Cause: Logfire isn’t configured or credentials are invalid. Fix:“logfire not installed” error
Cause: Logfire package is missing. Fix:Traces show “[REDACTED]” instead of content
Cause:include_content = false in config.
Fix: Set include_content = true:
Tracing slows down Lerim
Cause: Tracing adds overhead (span creation, network calls to Logfire). Fix:-
Disable
include_httpx(reduces trace size): -
Or disable tracing for fast operations:
“API key not found” in Logfire
Cause: Logfire credentials expired or missing. Fix:Best practices
Enable tracing during development
Keep tracing on while testing Lerim:Disable tracing in production (optional)
If you’re concerned about trace volume or cost:Use include_content wisely
If you handle sensitive data (passwords, API keys, PII):Review traces weekly
Set a recurring calendar event to review Logfire dashboards:- Token usage trends
- Error rates
- Slow operations
- Cost by role
Next steps
Model roles
Configure models for each role to optimize cost and performance
Config reference
See all tracing configuration options