pub struct Telemetry { /* private fields */ }Expand description
The installed stack handed to callers: an installed global subscriber is a process-wide singleton, so the handle carries only what callers need afterwards.
Telemetry is Send + Sync; clone-free sharing is by design —
hand the Telemetry::metrics registry Arc to workers instead.
Implementations§
Source§impl Telemetry
impl Telemetry
Sourcepub fn init(config: TelemetryConfig) -> Result<Self, TelemetryError>
pub fn init(config: TelemetryConfig) -> Result<Self, TelemetryError>
Bootstrap the estate telemetry stack and install it as the global tracing subscriber.
Installs, in one call:
- a
tracing_subscriberEnvFilter— built from the configuredlog_level, withRUST_LOGwinning when set and non-empty — and afmtlayer (LogFormat::Jsonvia thejsonfeature,LogFormat::Prettyotherwise); - a metrics-kit
Registryunder themetricsfeature, sized bymetrics_budgetand handed to the caller throughTelemetry::metrics; - with the
otlpfeature and an endpoint configured: anopentelemetry-otlpspan exporter (HTTP/protobuf, batch) wired as atracing-opentelemetrylayer, withservice.nameandservice.versionresource attributes and the configured sample rate.
§Errors
TelemetryError::AlreadyInitialized— the global subscriber is already installed (this crate init’ed twice, or another crate owns the global). The process-wide subscriber can only be set once; this is a typed error, never a panic.TelemetryError::InitFailed— theenv-filterdirective does not parse,LogFormat::Jsonwas requested without thejsonfeature, or the OTLP exporter could not be built.
Sourcepub fn metrics(&self) -> Arc<Registry> ⓘ
pub fn metrics(&self) -> Arc<Registry> ⓘ
The metrics registry for hot-path handle registration.
Handles register through this Arc; every clone of the returned
Arc renders identically. Under no-default-features (no
metrics feature) this method does not exist.
Sourcepub fn shutdown(&self) -> Result<(), TelemetryError>
pub fn shutdown(&self) -> Result<(), TelemetryError>
Explicitly flush and tear down the export pipeline.
Idempotent: the first call flushes and shuts down the OTLP tracer
provider (when one was built); every later call returns Ok(())
without touching anything. After shutdown, spans are no longer
exported; the log subscriber keeps working for the process
lifetime.
§Errors
TelemetryError::InitFailed if the first call’s provider
shutdown fails; later calls never fail.