| Crates.io | rust_mobile_telemetry |
| lib.rs | rust_mobile_telemetry |
| version | 0.1.3 |
| created_at | 2025-11-23 10:09:06.333024+00 |
| updated_at | 2025-11-23 11:31:21.702644+00 |
| description | Observability instrumentation (tracing + metrics) for mobile-backend applications or embedded / edge services. |
| homepage | |
| repository | https://github.com/emorilebo/rust_mobile_telemetry |
| max_upload_size | |
| id | 1946363 |
| size | 82,178 |
Observability made simple for mobile backends and edge services.
rust_mobile_telemetry is a production-ready Rust crate that helps you understand exactly what is happening in your application. It provides tracing (timelines of operations) and metrics (counters, gauges) with minimal setup, tailored for mobile-backend environments where device metadata (like OS version or Device ID) is critical for debugging.
Add this to your Cargo.toml:
[dependencies]
rust_mobile_telemetry = "0.1.1"
Call init_telemetry at the start of your main function. This sets up the global tracer and meter.
use rust_mobile_telemetry::{ConfigBuilder, ExporterType, init_telemetry, MobileMetadata};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// 1. Define metadata about the client (optional but recommended)
let metadata = MobileMetadata {
app_version: Some("1.0.0".to_string()),
device_os: Some("iOS 17.2".to_string()),
device_id: Some("user-device-uuid-123".to_string()),
};
// 2. Build configuration
let config = ConfigBuilder::new()
.service_name("my-mobile-backend")
.exporter_type(ExporterType::Console) // Use Console for local dev, Otlp for production
.mobile_metadata(metadata)
.build();
// 3. Initialize!
init_telemetry(config)?;
println!("Telemetry initialized! 📡");
// ... your app logic ...
// 4. Ensure data is flushed before exit
rust_mobile_telemetry::init::shutdown_telemetry();
Ok(())
}
Wrap operations in spans to track how long they take.
use rust_mobile_telemetry::with_span;
fn process_user_login() {
with_span("process_login", || {
// Your logic here...
println!("Logging in user...");
std::thread::sleep(std::time::Duration::from_millis(50));
});
}
Count events or measure latencies.
use rust_mobile_telemetry::instrumentation::{get_counter, get_histogram};
fn handle_request() {
// Counters: Good for "how many times did X happen?"
let requests = get_counter("http_requests_total", "Total HTTP requests");
requests.add(1, &[]);
// Histograms: Good for "how long did X take?"
let latency = get_histogram("http_request_duration", "Request duration in seconds");
latency.record(0.123, &[]);
}
You can configure the library using the ConfigBuilder or Environment Variables.
| Option | Builder Method | Env Variable | Description |
|---|---|---|---|
| Service Name | .service_name("name") |
OTEL_SERVICE_NAME |
Name of your service (e.g., auth-api). |
| Exporter | .exporter_type(type) |
N/A | Where to send data: Console (stdout) or Otlp (collector). |
| OTLP Endpoint | .otlp_endpoint("url") |
OTEL_EXPORTER_OTLP_ENDPOINT |
URL for OTLP exporter (default: http://localhost:4317). |
| Metrics | .enable_metrics(bool) |
N/A | Enable/disable metrics collection. |
| Tracing | .enable_tracing(bool) |
N/A | Enable/disable tracing. |
For production, you typically want to send data to an OpenTelemetry Collector or a vendor (like Honeycomb/Datadog).
let config = ConfigBuilder::new()
.service_name("production-backend")
.exporter_type(ExporterType::Otlp) // Send over network
.otlp_endpoint("http://otel-collector:4317")
.build();
If you see os error 32 during build or publish, it's likely an antivirus or the OS locking the build directory.
Fix: Restart your terminal or computer.
Ensure you initialized with ExporterType::Console and that your application runs long enough to flush data (or call shutdown_telemetry()).
MIT License. See LICENSE for details.