Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

  1. Traces: Follow Traces and adapt the traces example crate. It connects tracing spans and events to OpenTelemetry spans. Run cargo run -p traces. The chapter shows this last line: ok: traces exported.
  2. Metrics: Follow Metrics and adapt the metrics example crate. It creates a periodic meter provider and records metric data points. Run cargo run -p metrics. The chapter shows this last line: ok: metrics exported.
  3. Logs: Follow Logs and adapt the logs example crate. It bridges tracing events to OpenTelemetry log records. Run cargo 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.