Observability (OpenTelemetry)¶
Particles can emit traces, metrics, and trace-correlated logs via OpenTelemetry. It is off by default and is an opt-in optional dependency: a stock install ships only the no-op OTel API and pays nothing.
The motivating case: on the client-server topology (the
remote engine) a request runs in a different
process from the CLI that issued it. When a client deposit hangs while the
engine is busy, the engine logs nothing until the request finishes, so a hung
request is invisible. With observability on, the request is a traceparent-
propagated span tree that shows exactly where its time went (URL fetch vs
write-lock wait vs blob write vs LLM call) across the process boundary.
Turn it on¶
- Install the extra (the base install does not include the OTel SDK):
The engine's container image already carries it; skip this step there and see In a container.
- Enable it in
config.yaml:
observability:
enabled: true
exporter: console # print spans/metrics to the log (zero infra)
# exporter: otlp # or ship to a collector / SaaS backend
# endpoint: "http://localhost:4318"
service_name: "particles"
traces: true
metrics: true
logs: true
sample_ratio: 1.0 # always-on (correct for single-operator volume)
Or per-process, without editing the file:
The bootstrap runs at every process entry point: the CLI, the MCP server, and
the FastAPI engine (particles engine serve wires the FastAPI server span). With
enabled: false or the otel extra absent, every span/metric call is a
cheap no-op.
Exporters¶
exporter selects where signals go. One OTLP code path, three targets:
exporter |
Where it goes | Use |
|---|---|---|
console |
printed to the log | zero-infra, diagnose-now (resolves the hung-request case) |
otlp |
endpoint (OTLP/HTTP) |
a local collector (http://localhost:4318) or a SaaS backend |
none |
nowhere (provider only) | tests / pure no-op |
The collector and SaaS cases are the same otlp setting pointed at a
different endpoint.
The exporter credential is a secret¶
endpoint (a URL) is non-secret and lives in config.yaml. The credential an
authenticated collector or SaaS backend requires is a secret and is read
from the environment; never put it in config.yaml:
Headers are never sent over http:// to a collector that is not loopback.
For such an endpoint no OTLP exporter is installed and one warning names the
reason. Use https:// or a loopback collector, or set
observability.allow_plaintext_headers: true for a network you trust end to
end. The same rule covers headers set through the SDK's own
OTEL_EXPORTER_OTLP_HEADERS.
With endpoint unset, the exporter sends where the OpenTelemetry SDK would:
OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT, then OTEL_EXPORTER_OTLP_ENDPOINT,
then http://localhost:4318. That resolved URL is the one network.egress
checks and the one the exporter is given.
What you get¶
- Traces: auto-instrumented FastAPI (server spans, recorded by route
template such as
/particles/{particle_id}), httpx (client spans, plustraceparentpropagation), and hand-rolledextract.snapshot→embed.batch/llm.completespans on the extraction path. SECURITY.md states what a span may and may not carry (paths, queries, exception messages, bound values), and what an httpx client span carries when traces are off. The SQLAlchemy instrumentation is installed too, but with the SQLAlchemy release the project locks it exports no database span. - Metrics: LLM- and embed-call duration histograms, the
particles.extractedthroughput counter, and theparticles.sqlite.busycounter, incremented on everydatabase is lockedat the DB boundary, so it measures cross-process write-lock contention (a direct-I/O CLI verb on the engine host vs. the always-on engine) regardless of which writer lost the lock; plus the engine's per-requesthttp.serverduration from the FastAPI instrumentation. - Nightly consolidation gauges, set once at the end of each run, where the
run happens (the engine's daemon, or
particles memory consolidate): the pending-snapshot backlog the run left (particles_consolidation_backlog), snapshots it extracted, its LLM cost, the extraction pass's spend, budget and rounds, which reason stopped the pass (particles_consolidation_extract_stop, 1 for that reason and 0 for the others), and when it finished. Three*_to_dategauges sum cost, extraction spend and snapshots over every stored run record, so a panel can read what a span of nights spent even across an engine restart. Each carries astorelabel. A night that skipped extraction leaves the backlog unset rather than reporting zero. - Logs: the existing stdlib logs, with the active trace/span ID injected so a log line ties back to its span.
Grafana dashboard¶
A ready-made dashboard ships alongside this page:
particles-dashboard.json. It covers HTTP RED
(request rate, errors, and latency by route), the Particles-internal metrics
(extraction throughput, SQLite write-lock contention, LLM + embedding call
latency), outbound httpx calls, a recent-traces table, log volume + a live log
panel, and host CPU / memory / load / network / disk.
Import it: Grafana → Dashboards → New → Import → upload the JSON, then pick your Prometheus, Tempo, and Loki data sources when prompted. The dashboard uses data source variables, so it adapts to your setup rather than hard-coding UIDs.
Assumptions. The metric panels expect OTLP metrics to reach Prometheus via
a collector (Grafana Alloy or the OTel Collector) that renders them in the
Prometheus idiom (http_server_duration_milliseconds_*,
particles_sqlite_busy_total, particles_llm_duration_seconds_*, …) and maps
service.name onto the job label (so job="particles", the default
service_name). A pipeline that keeps dotted OTLP names, or exports straight to
a non-Prometheus backend, will name things differently and the queries won't
match. Host panels read node_exporter (node_*) metrics.
What lights up when. The HTTP-server and Particles-internal metrics come from
the engine (particles engine serve) and its extraction / LLM paths; the CLI
and MCP server emit traces and logs but not those metrics. OTLP metrics export
every 60 s by default; set OTEL_METRIC_EXPORT_INTERVAL (milliseconds) lower if
you want the rate() panels to fill in sooner. The live-logs panel needs a logs
pipeline into Loki; since OTLP log export is deferred (above), that means
tailing the engine's log file into Loki today.
For network exposure of the engine itself, see Remote engine; observability rides whatever channel (Tailscale / SSH tunnel) that uses. The longest-running spans you will see belong to the nightly passes; what they are is Scheduled consolidation.
In a container¶
The engine image carries the otel extra, with observability off in its baked
config. Turning it on is a configuration change, not a rebuild:
add an observability block to the config you mount over
/etc/particles/config.yaml, or set the PARTICLES_OBSERVABILITY_*
overrides in the container's environment
(Overriding configuration).
Inside the container, localhost is the container itself, so point
endpoint at a collector the container can reach:
observability:
enabled: true
exporter: otlp
# Docker Desktop: the host's own ports, including ones bound to 127.0.0.1.
endpoint: "http://host.docker.internal:4318"
# Or a collector on the same Docker network: "http://alloy:4318"
service_name: particles-engine
On Linux Docker Engine, host.docker.internal needs
extra_hosts: ["host.docker.internal:host-gateway"] in the compose service,
and reaches only host ports bound to the bridge address, not to 127.0.0.1;
a shared Docker network is the simpler route there. A collector that is down
costs nothing but the dropped telemetry: the engine starts and serves either
way.
A distinct service_name keeps the engine's spans and metrics apart from the
client's (the client keeps the default, particles). The dashboard above
selects job="particles"; widen it to job=~"particles.*" to show both. The
OTLP metric export interval defaults to 60 s; set OTEL_METRIC_EXPORT_INTERVAL
(milliseconds) in the container's environment to fill the rate() panels
sooner.
Logs are not exported over OTLP (above), so the engine's logs are its container
stdout. A collector that reads the container runtime's logs ships them to Loki,
for example Grafana Alloy's loki.source.docker with the Docker socket mounted
read-only. Label the engine's stream with service_name equal to its
service.name, so Grafana's trace-to-logs link finds it. The engine's log
lines do not carry the trace id today, so that link matches by service and
time window (filterByTraceID: false on the Tempo data source).
To check whether an image carries the SDK:
docker run --rm --network none --entrypoint python IMAGE -c "import importlib.util as u; print(u.find_spec('opentelemetry.sdk') is not None)"
It prints True for an image that carries the extra. An image built from a
release before the extra was added prints False, and observability.enabled
in its config does nothing there.