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

Examples

Each example is one crate in the examples workspace. Run one with cargo run -p NAME from the examples folder. You can download the whole workspace as examples.zip from the site root. Every example prints a last line starting with ok:, so you can check at a glance that it ran to the end. The table lists what each one prints or stores.

ExampleFolderChapterCommandWhat it does
first-signalexamples/first-signalSetup and first signalcargo run -p first-signalExports one span with attributes and an event to stdout.
tracesexamples/tracesTracescargo run -p tracesPrints tracing spans to stdout, including two nested spans and an async task span.
metricsexamples/metricsMetricscargo run -p metricsPrints counter, histogram and up-down counter data points.
logsexamples/logsLogscargo run -p logsPrints log records emitted through the tracing bridge.
otlp-exportexamples/otlp-exportExporterscargo run -p otlp-exportSends one span to a local collector over OTLP, choosing gRPC or HTTP.
env-configexamples/env-configConfigurationcargo run -p env-configBuilds a tracer provider from OpenTelemetry environment variables, prints the effective service name and sampler, and emits ten spans.
perf-benchexamples/perf-benchPerformancecargo run -p perf-benchPrints nanoseconds per iteration for several instrumentation cases.
sqlite-storeexamples/sqlite-storeSpans in SQLitecargo run -p sqlite-storeStores finished spans in SQLite with a full-text index and queries them.
turso-storeexamples/turso-storeSpans in Tursocargo run -p turso-storeStores finished spans in Turso through libsql.

Run them all

The examples folder is one cargo workspace. All the example crates are its members. Run cargo check --workspace from the examples folder to check every example in one pass. This is the fastest way to confirm that all the code in the guide still compiles together.