Expand description
Generic OTLP distributed-tracing pipeline for Crabka services.
The consuming service always installs a tracing_subscriber fmt layer
(stdout, gated by the usual RUST_LOG EnvFilter). When OTLP export is
configured via the environment, a second tracing-opentelemetry layer is
attached that converts tracing spans into OpenTelemetry spans and
batch-exports them over OTLP to a collector (gRPC :4317 or
HTTP/protobuf :4318).
§Enabling
OTLP is off by default — a service with no OTLP environment behaves
byte-for-byte as before. It turns on when any endpoint is set
(CRABKA_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
OTEL_EXPORTER_OTLP_ENDPOINT) or CRABKA_OTLP_ENABLED=true, and is
force-disabled by OTEL_SDK_DISABLED=true.
§Resolve OTLP settings without touching the environment
use crabka_telemetry::{OtlpConfig, OtlpProtocol};
let cfg = OtlpConfig::from_env(
|key| (key == "CRABKA_OTLP_ENABLED").then(|| "true".to_string()),
"broker-1",
"0.1.0",
"crabka-broker",
)
.unwrap();
assert_eq!(cfg.protocol, OtlpProtocol::Grpc);
assert_eq!(cfg.endpoint, "http://localhost:4317");Structs§
- Otlp
Config - Resolved OTLP configuration. Built by
OtlpConfig::from_env;Nonefrom that constructor means OTLP is disabled and no exporter is built. - Telemetry
Guard - Owns the OTLP
SdkTracerProviderso spans are flushed on shutdown. Dropping also flushes (the provider shuts down when its last clone drops), but callTelemetryGuard::shutdownexplicitly before exit so the final batch is delivered before the process ends.
Enums§
- Otlp
Protocol - OTLP transport. Mirrors the
OTEL_EXPORTER_OTLP_PROTOCOLspec values. - Telemetry
Error - Errors building the OTLP pipeline. Carries the underlying exporter build failure so a misconfigured endpoint surfaces a clear message rather than a silent no-export.
Functions§
- init
- Install the global
tracingsubscriber: a stdoutfmtlayer plus, whenotlpisSome, a batch OTLP export layer.