owiwi 1.1.0

A library to initialize tracing with opentelemetry
Documentation

Build Status Crates.io Documentation MPL-2.0 license

owiwi

Opinionated tracing subscriber with OpenTelemetry export.

Install

[dependencies]
owiwi = { version = "1.1.0", features = ["console"] }
tracing = "0.1"

Usage

use owiwi::Owiwi;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut owiwi = Owiwi::new();
    owiwi.service_name = "my-service".to_owned();
    let guard = owiwi.try_init_console()?;

    tracing::info!("credential issues");

    guard.shutdown()?;
    Ok(())
}

Hold the returned OwiwiGuard until shutdown. Dropping it stops export.

OTLP export

use std::time::Duration;
use owiwi::{Owiwi, OtlpConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = OtlpConfig::builder()
        .endpoint("http://localhost:4317".parse()?)
        .timeout(Duration::from_secs(10))
        .build();
    let guard = Owiwi::new().try_init(config)?;

    tracing::info!("credential issues");

    guard.shutdown()?;
    Ok(())
}

CLI integration

Flatten Owiwi into your CLI struct. Requires the clap feature.

[dependencies]
clap = { version = "4", features = ["derive"] }
owiwi = { version = "1.1.0", features = ["clap", "honeycomb"] }
tracing = "0.1"
use clap::Parser;
use owiwi::{Owiwi, HoneycombConfig};

#[derive(Debug, Clone, Parser)]
struct Cli {
    #[command(flatten)]
    owiwi: Owiwi,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let cli = Cli::parse();
    let config = HoneycombConfig::builder()
        .endpoint("https://api.honeycomb.io".parse()?)
        .api_key("your-api-key".into())
        .timeout(std::time::Duration::from_secs(5))
        .build();
    let guard = cli.owiwi.try_init(config)?;
    guard.shutdown()?;
    Ok(())
}

Backends

Backend Config type Feature
Any OTLP collector OtlpConfig (default)
Console (stdout) console
Honeycomb HoneycombConfig honeycomb

Environment variables

Per the OpenTelemetry spec. With clap, each has a CLI flag.

Variable Flag
OTEL_SERVICE_NAME --otel-service-name Service name
OTEL_SDK_DISABLED --otel-sdk-disabled Disable telemetry
OTEL_RESOURCE_ATTRIBUTES --otel-resource-attributes key=value,key=value
OTEL_EXPORTER_OTLP_ENDPOINT --otlp-endpoint Exporter endpoint
OTEL_EXPORTER_OTLP_HEADERS --otlp-headers Extra gRPC headers
OTEL_EXPORTER_OTLP_TIMEOUT --otlp-timeout Export timeout
RUST_LOG --trace-directive info · my_crate=debug

Features

Feature Default
clap CLI flags via clap::Args yes
serde Deserialize on config types yes
console Stdout exporters no
honeycomb Honeycomb exporter no
metrics Metrics via SdkMeterProvider no
prometheus Prometheus OTLP export (implies metrics) no

MSRV

1.94.0

Acknowledgments

Inspired by Instrumenting Axum.

License

MPL-2.0