Quickstart for coding agents
This page is a compact path for adding traces, metrics, and logs to an existing Rust service. The examples use stdout exporters so you can inspect output locally.
To get the examples: fetch examples.zip from the site root (relative to any book page: examples.zip), unpack it, and run commands from the examples folder.
Versions named in the chapters
opentelemetry 0.33.1, opentelemetry_sdk 0.33.1, opentelemetry-otlp 0.33.1, opentelemetry-stdout 0.33.1, opentelemetry-appender-tracing 0.33.1, tracing-opentelemetry 0.34.0, tracing 0.1.44, tracing-subscriber 0.3.23, tokio 1.54.1, rusqlite 0.42.0, and libsql 0.10.0. Use the versions relevant to the example you are adapting.
Add signals in this order
- Traces: Follow Traces and adapt the
tracesexample crate. It connectstracingspans and events to OpenTelemetry spans. Runcargo run -p traces. The chapter shows this last line:ok: traces exported. - Metrics: Follow Metrics and adapt the
metricsexample crate. It creates a periodic meter provider and records metric data points. Runcargo run -p metrics. The chapter shows this last line:ok: metrics exported. - Logs: Follow Logs and adapt the
logsexample crate. It bridgestracingevents to OpenTelemetry log records. Runcargo run -p logs. The chapter shows this last line:ok: log records emitted and providers shut down.
These lines confirm the examples reached their final status message; they do not prove delivery to a remote collector.
Environment variables
The Configuration chapter names OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_TRACES_SAMPLER, and OTEL_TRACES_SAMPLER_ARG. That example reads and applies these variables directly.
Failure signs described in the chapters
- Missing provider shutdown can lose buffered spans or metrics.
- Initializing a tracing subscriber more than once can fail.
- An OTLP example can print its final flush line even when no collector is listening; check the collector output to verify delivery.