pub struct TelemetryHandles {
pub tracer_provider: SdkTracerProvider,
pub meter_provider: Option<SdkMeterProvider>,
pub logger_provider: Option<SdkLoggerProvider>,
pub profiling_handle: Option<ProfilingHandle>,
/* private fields */
}Expand description
Handles returned by init_telemetry or TelemetryBuilder::init.
Keep alive for the duration of the process. Call shutdown
before exiting to flush pending spans, metrics, and logs.
When dropped, shutdown is attempted with a bounded timeout (default: 5 s). If the timeout expires a warning is logged but the process continues normally.
§Example
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let handles = otel_bootstrap::init_telemetry("my-service")?;
// run your application here …
handles.shutdown()?;
Ok(())
}Fields§
§tracer_provider: SdkTracerProvider§meter_provider: Option<SdkMeterProvider>§logger_provider: Option<SdkLoggerProvider>§profiling_handle: Option<ProfilingHandle>Implementations§
Source§impl TelemetryHandles
impl TelemetryHandles
Sourcepub fn shutdown(&self) -> Result<(), Box<dyn Error>>
pub fn shutdown(&self) -> Result<(), Box<dyn Error>>
Flush pending data and shut down all providers.
Must be called before the tokio runtime shuts down so the batch exporter can send remaining spans over gRPC. Safe to call multiple times — subsequent calls are no-ops.
Best-effort. A provider that cannot flush — collector unreachable,
export deadline exceeded — is logged at warn and shutdown continues
to the next one. Failing to deliver telemetry is not a failure of the
program that produced it, and a service must be able to exit cleanly
when its collector is down. This mirrors what Drop has always done;
the two paths previously disagreed, and shutdown() propagating was
the odd one out.
The Result is retained for API compatibility and so a genuinely
fallible step could be surfaced later; today every provider error is
absorbed.
Historically this returned Ok for metrics purely because nothing
registered instruments, so there was never anything to export. Once
real instruments exist, an unreachable collector turns every shutdown
into a 5-second timeout and an error — which is exactly the situation
this must not turn into a failure.
§Example
let handles = otel_bootstrap::init_telemetry("my-service").unwrap();
// … application logic …
handles.shutdown().expect("telemetry shutdown failed");Trait Implementations§
Source§impl Drop for TelemetryHandles
impl Drop for TelemetryHandles
Auto Trait Implementations§
impl !RefUnwindSafe for TelemetryHandles
impl !UnwindSafe for TelemetryHandles
impl Freeze for TelemetryHandles
impl Send for TelemetryHandles
impl Sync for TelemetryHandles
impl Unpin for TelemetryHandles
impl UnsafeUnpin for TelemetryHandles
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request