Skip to main content

Module otel_tracing

Module otel_tracing 

Source
Available on crate feature otel-tracing only.
Expand description

OpenTelemetry distributed tracing – span export via OTLP.

Bridges the tracing ecosystem (tracing::span!, #[instrument], tracing::info_span!) to OpenTelemetry spans that get exported via OTLP to a collector or backend (Tempo, Jaeger, Honeycomb, etc.).

Closes the loop on the framework’s W3C traceparent propagation: crate::transport::propagation reads the current OTel context (set externally) and propagates it across transport boundaries. Without this module wired up, internal tracing::span!s never become OTel spans, leaving distributed traces with broken segments.

§Quick start

use hyperi_rustlib::otel_tracing::{OtelTracingConfig, build_tracer_layer};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

let config = OtelTracingConfig {
    service_name: "dfe-loader".into(),
    endpoint: "http://otel-collector:4317".into(),
    ..Default::default()
};
let (otel_layer, _provider) = build_tracer_layer(&config)?;

tracing_subscriber::registry()
    .with(tracing_subscriber::fmt::layer())
    .with(otel_layer)
    .init();

tracing::info_span!("startup").in_scope(|| {
    tracing::info!("application booted");
});

§Why a separate module from otel-metrics

Metrics and traces have independent lifecycles, samplers, and exporters. Mixing them under one feature gate forced consumers who only want one to pull in the other. They share OtelProtocol and the OTLP endpoint discipline but otherwise operate independently.

Structs§

OtelTracingConfig
OpenTelemetry tracing configuration.

Enums§

OtelTracingError
Errors when building the OTel tracer.
OtelTracingProtocol
OTLP transport protocol (mirrors crate::metrics::OtelProtocol).

Functions§

build_tracer_layer
Build an OTel tracer + tracing-subscriber layer ready for composition.