Skip to main content

Crate crabka_telemetry

Crate crabka_telemetry 

Source
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§

OtlpConfig
Resolved OTLP configuration. Built by OtlpConfig::from_env; None from that constructor means OTLP is disabled and no exporter is built.
TelemetryGuard
Owns the OTLP SdkTracerProvider so spans are flushed on shutdown. Dropping also flushes (the provider shuts down when its last clone drops), but call TelemetryGuard::shutdown explicitly before exit so the final batch is delivered before the process ends.

Enums§

OtlpProtocol
OTLP transport. Mirrors the OTEL_EXPORTER_OTLP_PROTOCOL spec values.
TelemetryError
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 tracing subscriber: a stdout fmt layer plus, when otlp is Some, a batch OTLP export layer.