Observability with OpenTelemetry
poly can export traces and metrics to an OpenTelemetry collector. Export is opt-in twice: the
binary must be built with the otel cargo feature, and an OTLP endpoint must be set in the
environment. A default build links no OpenTelemetry crate at all, and a binary built with the
feature stays silent until an endpoint is configured.
The engine libraries (poly-core, poly-engine-api, poly-host-services,
poly-component-host and poly-mcp) never link an exporter: they emit tracing spans, and
poly-cli is the single exporter (ADR 0109).
Build with the feature
Section titled “Build with the feature”cargo build -p poly-cli --features otelThe default dependency tree contains no opentelemetry* crate:
cargo tree -p poly-cli | grep opentelemetry # no outputcargo tree -p poly-cli --features otel | grep opentelemetryThe feature adds OTLP over gRPC and over HTTP/protobuf, selected by the standard protocol variables. HTTP export uses rustls; gRPC uses rustls with the bundled webpki roots.
Turn export on
Section titled “Turn export on”There are no poly flags for telemetry: the process environment is the whole configuration
surface. Export starts only when OTEL_EXPORTER_OTLP_ENDPOINT or
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is set and non-empty.
| Variable | Meaning | Default |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
Collector endpoint for every signal. HTTP appends /v1/traces and /v1/metrics. |
none — export stays off |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT |
Trace-specific endpoint; wins over the generic one. | none |
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL |
grpc or http/protobuf for traces. |
http/protobuf |
OTEL_EXPORTER_OTLP_PROTOCOL |
Protocol for every signal when the signal-specific variable is unset. | http/protobuf |
OTEL_EXPORTER_OTLP_HEADERS |
Comma-separated k=v headers sent with every export. |
none |
OTEL_EXPORTER_OTLP_TRACES_HEADERS |
Trace-specific headers; wins over the generic list. | none |
OTEL_EXPORTER_OTLP_TIMEOUT |
Export timeout in milliseconds. | SDK default |
OTEL_SERVICE_NAME |
service.name resource attribute. |
poly (or service.name from OTEL_RESOURCE_ATTRIBUTES) |
OTEL_RESOURCE_ATTRIBUTES |
Comma-separated resource attributes appended to every signal. | none |
OTEL_TRACES_SAMPLER |
always_on, always_off, traceidratio, or a parentbased_* variant. |
parentbased_always_on |
OTEL_TRACES_SAMPLER_ARG |
Ratio for traceidratio / parentbased_traceidratio. |
1.0 |
OTEL_SDK_DISABLED |
true disables export even when an endpoint is set. |
unset |
TRACEPARENT / TRACESTATE |
W3C context of the job that started this run; parents the root span. | unset |
Traces
Section titled “Traces”- One root span per
poly lintorpoly fmtrun (poly.lint,poly.fmt). - A child
enginespan per engine call, nested under the run’s phase spans, withengineandlanguageattributes. - A
toolspan per subprocess tool call, withtool,kindandoutcome.toolis a bounded identity — the catalog tool or binary name — never the executable path, which can contain a home directory. - A
poly.mcp.toolspan per MCP tool call, withtool; the request’straceparentandtracestateare used to parent it (see Propagation).
Engine timings come from the run’s own timings collection, which the otel feature switches on for
the run; a run without telemetry pays nothing for it.
Metrics
Section titled “Metrics”| Name | Type | Attributes |
|---|---|---|
poly.run.duration |
histogram, seconds | command (lint, fmt, mcp.check, mcp.fix), outcome (clean, findings, error, ok) |
poly.engine.duration |
histogram, seconds | engine |
poly.engine.files |
counter | engine |
poly.findings |
counter | engine, severity (error, warning, info, hint) |
poly.cache.operations |
counter | outcome (hit, miss) |
poly.tool.duration |
histogram, seconds | tool, kind (per_file, probe, unit), outcome (ok, timeout, failed) |
poly.tool.timeouts |
counter | tool |
poly.tool.failures |
counter | tool |
poly.component.downloads |
counter | component, outcome (success, failure) |
poly.component.verifications |
counter | component, outcome (success, failure) |
Propagation
Section titled “Propagation”- Inbound. A valid
TRACEPARENT(withTRACESTATE) in the environment parents the run’s root span, so a CI step joins the trace of the job that started it. An invalid header is ignored and the run starts a new trace. - Outbound to tools. A subprocess started by
polyreceivesTRACEPARENTandTRACESTATEnaming that tool call’s span, so a tool that exports its own telemetry joins the trace. - MCP. A request whose
_metacarriestraceparent(and optionallytracestate) is exported as a child of that trace. This applies to the in-process server (bundled-mcp, the default build). A call served by the downloadedmcpcomponent receives the metadata itself, but trace context does not yet cross the component ABI, so it exports as a new root.
What is not exported
Section titled “What is not exported”The exporter is the privacy boundary, not just a transport. It keeps an allow-list of span
attributes — engine, language, phase, tool, kind, outcome, command — and drops every
other attribute, every span event and every span link. So no span or metric carries a file path, a
diagnostic message or source text. tool stays the tool’s bounded identity even when a pinned
download resolved an executable path.
Log records are not exported either: only traces and metrics leave the process, so a diagnostic
message cannot reach the collector through a log. Beyond the standard OTEL_* variables there is
no sampler or span-processor plugin API.
When the collector is unreachable
Section titled “When the collector is unreachable”The collector is observability infrastructure. An unreachable collector, a bad endpoint or a
failed export is logged once at warn and otherwise ignored: the exit code, the findings and the
report on stdout are exactly those of a run without telemetry. The exporter is flushed on every
exit path, including a failed run and Ctrl-C. A run interrupted by Ctrl-C exports only the spans
that had already ended, so it appears in the trace as its finished children rather than as a
complete run.
Try it
Section titled “Try it”Point poly at any OTLP-compatible collector (otelcol, Jaeger, Tempo, an OpenTelemetry Collector
sidecar) and run:
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 poly lint .# gRPC instead of HTTP/protobuf:OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4317 OTEL_EXPORTER_OTLP_PROTOCOL=grpc poly lint .