o11y - Rust Observability Package
OpenTelemetry instrumentation for Rust applications with unified configuration and flexible deployment options.
Features
- All-in-one or standalone - Use
Telemetryfor coordinated setup or initialize components individually - Config-based - No environment variables, all configuration via structs
- Multiple auth methods - BasicAuth, Bearer tokens, API keys, custom headers per component
- Resource management - Automatic resource building with service identification
- Validation - Config validation with clear error messages
- Runtime metrics - Optional Tokio runtime metrics for meters
- Cargo features - Enable only the observability components you need
- OTLP native - Uses OpenTelemetry Protocol for all backends (Grafana OTLP endpoints)
- Cross-platform - Profiler support on Unix platforms
Cargo Features
By default, all features are enabled. You can selectively enable only what you need:
[]
= { = "*", = false, = ["logger", "tracer"] }
Available features:
logger- Logging via OTLPtracer- Distributed tracingmeter- Metrics collectionprofiler- Continuous profiling (Unix only)
Installation
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick Start
All-in-One Setup
use ;
use LoggerConfig;
use TracerConfig;
use MeterConfig;
async
Standalone Component Setup
use ;
use ResourceConfig;
async
Configuration
Logger Configuration
use LoggerConfig;
let logger_cfg = new
.enabled
.with_endpoint
.with_environment;
Note: Logger endpoint should include /otlp path for Grafana Loki OTLP endpoint.
Tracer Configuration
use TracerConfig;
use Duration;
let tracer_cfg = new
.enabled
.with_endpoint
.with_sample_ratio // Sample 10% of traces
.with_export_timeout;
Note: Tracer uses gRPC endpoint (default port 4317 for Grafana Tempo).
Meter Configuration
use ;
use Duration;
let meter_cfg = new
.enabled
.with_endpoint
.with_export_interval
.with_runtime;
Note: Meter endpoint should include /otlp path for Grafana Mimir OTLP endpoint (default port 9009).
Profiler Configuration
use ProfilerConfig;
use Duration;
let profiler_cfg = new
.enabled
.with_endpoint
.with_sample_rate // Hz
.with_upload_interval;
Resource Configuration
use ResourceConfig;
let resource = new
.with_version
.with_environment
.with_namespace
.with_tenant_id;
Global Providers
All enabled components are automatically registered with OpenTelemetry's global registry:
- Tracer provider →
opentelemetry::global::set_tracer_provider() - Meter provider →
opentelemetry::global::set_meter_provider()
This means you can use the standard OpenTelemetry APIs throughout your application:
use global;
// Get global tracer
let tracer = tracer;
// Get global meter
let meter = meter;
Authentication
Multiple authentication methods are supported per component:
Basic Auth
use Credentials;
let creds = basic_auth;
let logger_cfg = new
.enabled
.with_endpoint
.with_credentials;
Bearer Token
let creds = bearer_token;
API Key
let creds = api_key;
Custom Headers
let creds = custom_header;
Examples
See the examples directory for complete working examples:
Backends
Designed for Grafana observability stack:
- Logger → Grafana Loki (port 3100,
/otlppath) - Tracer → Grafana Tempo (gRPC port 4317)
- Meter → Grafana Mimir (port 9009,
/otlppath) - Profiler → Pyroscope (port 4040)
Error Handling
All operations return Result<T, o11y::Error>:
match setup
Testing
# Unit tests
# All tests
# With specific features
License
[License information]