Skip to main content

autumn_plugin_otel/
lib.rs

1//! Autumn plugin for OpenTelemetry.
2//!
3//! Add [`OtelPlugin`] to the app. Spans, instruments and tracing events export
4//! to the configured OTLP collector over gRPC or HTTP.
5//!
6//! ```rust,no_run
7//! use autumn_plugin_otel::OtelPlugin;
8//!
9//! # async fn run() {
10//! autumn_web::app()
11//!     .plugin(OtelPlugin::new().configure(|c| {
12//!         c.enabled = true;
13//!         c.service_name = "my-app".into();
14//!         c.sample_ratio = 0.1;
15//!     }))
16//!     .run()
17//!     .await;
18//! # }
19//! ```
20//!
21//! The plugin reads `[otel]` in `autumn.toml`. See [`config`] for the keys.
22//!
23//! # What the plugin gives
24//!
25//! - A tier-1 [`TelemetryProvider`](autumn_web::telemetry::TelemetryProvider) that owns
26//!   the global tracing subscriber and wires OTLP exporters for three signals.
27//! - Traces: a `tracing-opentelemetry` layer with a parent-based sampler.
28//! - Metrics: an SDK meter provider installed as the global provider, plus [`metrics`] helpers.
29//! - Logs: a bridge layer that forwards tracing events as OTLP log records.
30//! - [`OtelTelemetry`]: the handle in the app state, with a handler extractor.
31//! - A health indicator that reports the exporter configuration (never the
32//!   collector endpoint).
33//! - A shutdown hook that flushes every provider.
34//!
35//! # Limits
36//!
37//! - The plugin replaces Autumn's default telemetry initializer. The framework's
38//!   log-capture buffer and the `/actuator/loggers` reload handle belong to the
39//!   default provider and are not installed.
40//! - `TelemetryInitError` is `#[non_exhaustive]`, so the provider can not build one.
41//!   An exporter that fails to build falls back to a logging-only subscriber with
42//!   a warning on stderr. A bad `[otel]` configuration stops the boot in the startup hook.
43//! - OTLP has no cheap health probe. The health check reports the exporter
44//!   configuration. It never contacts the collector and never exposes the
45//!   collector endpoint.
46//! - `https` gRPC endpoints need the `tls` crate feature. HTTP uses rustls through reqwest.
47//! - The tracing-to-OTLP log bridge forwards each event's message and target;
48//!   it does not forward every structured field.
49//!
50//! # Shutdown
51//!
52//! Autumn marks the shutdown before it drains the requests. The shutdown hook flushes
53//! the trace, metric and log providers. The exporters stay alive for the drain.
54
55mod client;
56pub mod config;
57mod error;
58mod health;
59pub mod metrics;
60mod plugin;
61
62pub use client::OtelTelemetry;
63pub use config::{ConfigError, DEFAULT_SECTION, OtelConfig, OtelProtocol};
64pub use error::{ErrorKind, OtelError, OtelResultExt};
65pub use metrics::{OtelMetrics, meter, meter_named};
66pub use plugin::{OtelPlugin, PLUGIN_NAME};