Crates.io | rust_observer |
lib.rs | rust_observer |
version | 0.2.2 |
source | src |
created_at | 2024-08-01 11:40:29.146473 |
updated_at | 2024-09-03 15:16:23.915955 |
description | Express telemetry rust SDK |
homepage | |
repository | |
max_upload_size | |
id | 1321948 |
size | 63,423 |
Rust Observer is a high-performance, concurrent observability library designed for mission-critical Rust applications. It provides unified logging, tracing, and metrics collection with minimal runtime impact, optimized for systems with strict performance requirements.
Rust Observer is part of the Express Telemetry Project.
Add to Cargo.toml
:
[dependencies]
rust_observer = "0.2.1"
Initialize in your application:
use rust_observer::initialize_observability;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
initialize_observability("config/observability.toml")?;
// Application logic
Ok(())
}
use rust_observer::logging::info;
info!("Transaction processed", attrs: {
"transaction_id" => tx.id,
"amount" => tx.amount,
"currency" => tx.currency,
"status" => tx.status
});
use rust_observer::tracing::{trace, OptionalTraceContext};
#[trace(Server)]
async fn process_order(ctx: OptionalTraceContext, order: Order) -> Result<(), Error> {
validate_order(ctx.clone(), &order)?;
update_inventory(ctx.clone(), &order)?;
process_payment(ctx.clone(), &order)?;
Ok(())
}
use rust_observer::metrics::HttpMetrics;
async fn handle_request(req: Request) -> Response {
let start = Instant::now();
let response = process_request(req).await;
let duration = start.elapsed().as_millis() as u64;
HttpMetrics::increment_counter().await;
HttpMetrics::update_method_count(req.method()).await;
HttpMetrics::update_status_code(response.status()).await;
HttpMetrics::update_request_duration(req.method(), response.status(), duration).await;
response
}
Rust Observer supports fine-grained configuration via TOML:
[project]
name = "falcon-9"
app_name = "flight-computer"
service_name = "telemetry-processor"
[logging]
enabled = true
level = "INFO"
[logging.exporter]
type = "stdout"
format = "extended"
[tracing]
enabled = true
[tracing.exporter]
type = "stdout"
format = "extended"
[metrics]
enabled = true
interval_secs = 5
[metrics.exporter]
type = "stdout"
format = "extended"
[metrics.http]
enabled = true
[metrics.grpc]
enabled = true
[metrics.websockets]
enabled = true
[metrics.system]
enabled = true
[metrics.process]
enabled = true