otel-log-wrapper
Zero-config OpenTelemetry setup for Rust services that use tracing.
This crate wraps init-tracing-opentelemetry with the one-line initialization
style used by qrt-log-utils.
No-Brain Init
init!?;
info!;
The macro derives the service metadata from the calling crate:
service.name:env!("CARGO_PKG_NAME")service.version:env!("CARGO_PKG_VERSION")
Builder Init
Use the builder when you want an explicit service name or config.
use LoggerConfig;
builder.init?;
With build metadata from shadow-rs:
shadow!;
builder
.service_version
.commit_short
.commit_hash
.branch
.build_time
.init?;
otel-log-wrapper does not depend on shadow-rs; it only accepts the static
strings generated by the application.
Build metadata is merged into OTEL_RESOURCE_ATTRIBUTES before initialization,
so the OpenTelemetry SDK picks it up as resource attributes.
Defaults
The default setup:
- sets
OTEL_SERVICE_NAMEfrom the service name when unset - sets
OTEL_EXPORTER_OTLP_ENDPOINTtohttp://localhost:4317when unset - sets
OTEL_EXPORTER_OTLP_PROTOCOLtogrpcwhen unset - respects
RUST_LOG, thenOTEL_LOG_LEVEL, then falls back toinfo - uses human-readable stdout logs by default
- initializes a global
tracing-subscriber - exports OpenTelemetry traces and metrics
- prints a one-line startup message
Example startup message:
otel-log-wrapper init service=my-service version=0.1.0 commit=abc1234 endpoint=http://localhost:4317 protocol=grpc format=human metrics=true level=RUST_LOG|OTEL_LOG_LEVEL|info
Customization
use ;
use LevelFilter;
builder
.endpoint
.format
.default_level
.startup_message
.init?;
Available formats:
LoggerFormat::HumanLoggerFormat::PrettyLoggerFormat::FullLoggerFormat::CompactLoggerFormat::Json
If you want to own shutdown explicitly instead of storing a global guard:
let _guard = builder
.global_subscriber
.init_guard?;