Expand description
klieo-otel — OpenTelemetry OTLP exporter wiring for klieo agent
runtimes.
The klieo runtime is instrumented with tracing spans on every
Agent::run_steps call, every LLM
invocation, and every tool dispatch. Field names follow the
OpenTelemetry GenAI semantic
conventions,
so any OTel-aware backend (Tempo, Jaeger, Honeycomb, Datadog, …)
ingests them once you wire up an exporter.
This crate is that exporter. One function call:
use klieo_otel::{install, OtelConfig, Protocol};
use std::time::Duration;
let _guard = install(
OtelConfig::new("my-agent")
.service_version(env!("CARGO_PKG_VERSION"))
.gen_ai_system("ollama")
.endpoint("http://localhost:4317")
.protocol(Protocol::Grpc)
.timeout(Duration::from_secs(5)),
)?;
// run agents here — spans flow to the configured collector
// until `_guard` is dropped.§Defaults
- Endpoint —
OTEL_EXPORTER_OTLP_ENDPOINTenv var (the standard OTel SDK convention) is honoured if set; otherwise the value passed toOtelConfig::endpointis used; otherwisehttp://localhost:4317. - Protocol — gRPC (
Protocol::Grpc). Switch withOtelConfig::protocol. - Resource attributes —
service.name,service.version,gen_ai.systemare emitted on every span, per OTel semantic conventions.
§Guard semantics
OtelGuard’s Drop impl force-flushes any in-flight batch and
shuts the provider down cleanly. Bind it to a binding that lives
for the lifetime of your process (e.g. in main):
let _otel = install(OtelConfig::new("my-agent"))?;
// … run server … the guard drops at end of main, flushing spans.Prefix the binding with _ (not _otel = … then unused) to
suppress the unused-variable warning while keeping the binding
alive — let _ = … would drop the guard immediately and discard
every export.
§Composition with existing subscribers
install sets a global tracing subscriber that combines:
- an
env-filterlayer respectingRUST_LOG, - the OpenTelemetry layer that exports spans over OTLP,
- a human-readable
fmtlayer on stderr.
If you already call tracing_subscriber::fmt().init() (or any
other subscriber installer) earlier in main, install will
return OtelError::AlreadyInitialized. Call this crate first
(or skip the other call) to avoid a double-install.
Modules§
- test_
utils - Test utilities for asserting against emitted
tracingspans without an OTLP collector.
Structs§
- Otel
Config - Configuration for
crate::install. - Otel
Guard - Guard that flushes and shuts down the OTel tracer provider on
Drop.
Enums§
- Otel
Error - Failure modes for
crate::install. - Protocol
- OTLP wire protocol selector.
Constants§
- OTEL_
EXPORTER_ OTLP_ ENDPOINT_ ENV - Standard OTel SDK environment variable: when set, overrides
OtelConfig::endpoint.
Traits§
- Open
Telemetry Span Ext - Utility functions to allow tracing
Spans to accept and return OpenTelemetryContexts.
Functions§
- install
- Install a global OpenTelemetry tracing subscriber.
- install_
or_ replace - Install klieo’s OpenTelemetry exporter, tolerating an already-installed
tracingsubscriber.