Expand description
§Telemetry Module - Educational Implementation
This module provides production-grade OpenTelemetry integration for a tiny CLI tool. This is intentionally over-engineered for educational purposes!
§Why This Exists
A simple cron parser doesn’t “need” distributed tracing. However, this demonstrates:
- How to add observability to any Rust CLI
- OpenTelemetry patterns that scale from tiny tools to large systems
- Handling async/gRPC in short-lived processes
§Key Features
- Optional at runtime: Zero overhead if
OTEL_EXPORTER_OTLP_ENDPOINTnot set - Multi-backend support: Jaeger, Honeycomb, Grafana Tempo, AWS X-Ray, etc.
- Secure: TLS, header authentication, compression
- Production-ready: Proper resource attributes, propagation, graceful shutdown
§Known Limitation: Short-lived Process Challenge
Short-lived CLIs exit faster than spans can flush:
- CLI execution: ~10ms
- Span flush timeout: 5000ms
- Result: You may see “BatchSpanProcessor.Shutdown.Timeout”
This is expected and cosmetic - spans are still sent asynchronously!
To suppress: export RUST_LOG="warn,opentelemetry_sdk=error"
§Usage in Your Own Projects
- Copy this module
- Add
#[instrument]to functions you want to trace - Call
telemetry::init()at startup - Call
telemetry::shutdown_tracer()before exit - Set
OTEL_EXPORTER_OTLP_ENDPOINTwhen you want tracing
§Dependencies Required
opentelemetry = "0.31.0"
opentelemetry-otlp = { version = "0.31.0", features = ["grpc-tonic", "tls"] }
opentelemetry_sdk = { version = "0.31.0", features = ["rt-tokio"] }
tokio = { version = "1", features = ["rt", "macros"] }
tracing = "0.1"
tracing-opentelemetry = "0.32.0"
tracing-subscriber = "0.3"Functions§
- init
- Initialize logging + (optional) tracing exporter Tracing is enabled if OTEL_EXPORTER_OTLP_ENDPOINT is set (gRPC only).
- shutdown_
tracer - Gracefully shut down tracer provider (noop if not initialized)