o11y

Crates.ioo11y
lib.rso11y
version0.0.1
created_at2025-10-27 00:05:12.457913+00
updated_at2025-10-28 23:06:02.313713+00
descriptionObservability library for Rust: logging, metrics, tracing, and profiling.
homepagehttps://github.com/mfahmialkautsar/rust-o11y
repositoryhttps://github.com/mfahmialkautsar/rust-o11y
max_upload_size
id1902039
size184,854
Fahmi Al (mfahmialkautsar)

documentation

https://docs.rs/o11y

README

o11y

CI Docs codecov Crates.io Docs.rs MSRV License

Observability building blocks for Rust services: unified configuration for logging, tracing, metrics, and continuous profiling on top of OpenTelemetry.

Highlights

  • Unified bootstrapTelemetry::new wires logger, tracer, meter, and profiler from one config.
  • Modular features – enable only the components you need via Cargo features.
  • Credential helpers – convenience constructors for basic auth, bearer tokens, API keys, and custom headers.
  • Resource defaults – consistent service metadata with optional environment overrides.
  • Tokio runtime metrics – optional gauges for runtime worker state when meters are global.

Installation

cargo add o11y --features="logger tracer meter profiler"

The crate targets Rust 1.85 or newer (2024 edition). Tokio is required when using async components:

[dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }

Quick Start

use o11y::{Config, Telemetry};
use o11y::logger::LoggerConfig;
use o11y::meter::{MeterConfig, RuntimeConfig};
use o11y::tracer::TracerConfig;

fn main() -> anyhow::Result<()> {
    let config = Config::new("billing-service")
        .with_logger(
            LoggerConfig::new("billing-service")
                .with_endpoint("http://localhost:3100/otlp"),
        )
        .with_tracer(
            TracerConfig::new("billing-service")
                .with_endpoint("http://localhost:4317")
                .use_global(true),
        )
        .with_meter(
            MeterConfig::new("billing-service")
                .with_endpoint("http://localhost:9009/otlp")
                .with_runtime(RuntimeConfig::default())
                .use_global(true),
        );

    let telemetry = Telemetry::new(config)?;
    // Emit logs, traces, and metrics using OpenTelemetry APIs here.
    telemetry.shutdown();
    Ok(())
}

See tests/telemetry_all_in_one.rs for an end-to-end example that exercises logs, traces, and metrics against Grafana backends.

Feature Flags

Feature Description
logger OTLP logging with Loki-compatible exporters
tracer Distributed tracing via OTLP/Tempo
meter Metrics export with optional Tokio runtime stats
profiler Pyroscope integration (Unix only)
[dependencies]
o11y = { version = "0.0.1", default-features = false, features = ["logger", "tracer"] }

Configuration Overview

  • ResourceConfig controls service metadata (name, version, namespace, environment).
  • Component configs (LoggerConfig, TracerConfig, MeterConfig, ProfilerConfig) expose builder-style APIs for endpoints, auth, timeouts, sampling, and runtime behavior.
  • Authentication helpers live in o11y::auth::Credentials.
  • Global registration is optional per component; use use_global(true) to apply providers to OpenTelemetry globals.

Refer to module-level docs on docs.rs for the complete API surface.

Testing

cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features

Integration scenarios mirror README samples:

cargo test --test telemetry_all_in_one
cargo test --test telemetry_standalone

License

This project is licensed under the GNU GPLv3 only.

Commit count: 0

cargo fmt