Module config

Module config 

Source
Available on crate feature tracing_subscriber_ext only.
Expand description

Flexible tracing configuration with builder pattern.

Provides TracingConfig for configurable tracing setup with format options, output destinations, level filtering, and OpenTelemetry integration.

§Example

use init_tracing_opentelemetry::TracingConfig;

// Use preset with global subscriber (default)
let _guard = TracingConfig::development().init_subscriber()?;

// Custom configuration with global subscriber
let _guard = TracingConfig::default()
    .with_json_format()
    .with_stderr()
    .with_log_directives("debug")
    .init_subscriber()?;

// Non-global subscriber (thread-local)
let guard = TracingConfig::development()
    .with_global_subscriber(false)
    .init_subscriber()?;
// Guard must be kept alive for subscriber to remain active
assert!(guard.is_non_global());

// Without OpenTelemetry (just logging)
let guard = TracingConfig::minimal()
    .with_otel(false)
    .init_subscriber()?;
// Works fine - guard.otel_guard is None
assert!(!guard.has_otel());
assert!(guard.otel_guard.is_none());

// Direct field access is also possible
if let Some(otel_guard) = &guard.otel_guard {
    // Use otel_guard...
}

Structs§

FeatureSet
Configuration for optional tracing features
Guard
Combined guard that handles both OtelGuard and optional DefaultGuard
LevelConfig
Configuration for log level filtering
OtelConfig
Configuration for OpenTelemetry integration
TracingConfig
Main configuration builder for tracing setup Default create a new tracing configuration with sensible defaults

Enums§

LogFormat
Configuration for log output format
LogTimer
WriterConfig
Configuration for log output destination