Create a new project
1
Create a new Rust project
2
Add dependencies
Add the following to your
Cargo.toml:Cargo.toml
3
Write the code
Replace the contents of
src/main.rs with the complete example below.4
Run the application
Complete example
This example demonstrates all three telemetry signals:src/main.rs
Understanding the example
Let’s break down the key components:Resource
A resource identifies your service and provides context for all telemetry:Providers
Providers manage the lifecycle of telemetry pipelines:- TracerProvider - Creates tracers and manages span exporters
- MeterProvider - Creates meters and manages metric exporters
- LoggerProvider - Manages log exporters and bridges to logging frameworks
Always call
shutdown() on providers when your application exits to ensure all telemetry is flushed.Creating spans
Spans represent units of work in distributed tracing:Recording metrics
Metrics track measurements over time:Emitting logs
Logs provide structured event data:Metrics example
Here’s a focused example showing different metric instrument types:src/main.rs
Using OTLP exporter
To send telemetry to an OpenTelemetry Collector or OTLP-compatible backend:1
Update dependencies
Cargo.toml
2
Replace exporter initialization
3
Configure endpoint (optional)
By default, the OTLP exporter sends to
http://localhost:4318. Configure a different endpoint:Environment variables
Configure OTLP exporters using environment variables:Common patterns
Error handling
Context propagation
Instrumentation scope
Next steps
API Reference
Explore the complete API documentation
Examples
Browse more examples in the GitHub repository
OTLP Configuration
Learn about OTLP exporter configuration
Semantic Conventions
Use standard attribute names and values