pub struct Runtime { /* private fields */ }Expand description
Shared telemetry runtime.
Share one runtime across crate boundaries so metric registration, span collection, and export setup are owned once per service. Register metric groups during construction, then keep updating the returned metric handles directly on hot paths.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new(config: RuntimeConfig) -> Arc<Self>
pub fn new(config: RuntimeConfig) -> Arc<Self>
Create a runtime wrapped in Arc for parent/child sharing.
Sourcepub fn config(&self) -> &RuntimeConfig
pub fn config(&self) -> &RuntimeConfig
Return this runtime’s configuration.
Sourcepub fn span_collector(&self) -> &Arc<SpanCollector>
pub fn span_collector(&self) -> &Arc<SpanCollector>
Return the shared span collector owned by this runtime.
Clone this once when wiring exporters. Hot-path span creation should use
start_span or keep this borrowed through the
shared runtime rather than cloning an Arc per operation.
Sourcepub fn start_span(
&self,
name: impl Into<Cow<'static, str>>,
kind: SpanKind,
) -> Span
pub fn start_span( &self, name: impl Into<Cow<'static, str>>, kind: SpanKind, ) -> Span
Create a new root span with a fresh trace ID.
This forwards to the runtime’s shared SpanCollector, keeping the
collector service shared across crate boundaries.
Sourcepub fn start_span_from_traceparent(
&self,
traceparent: Option<&str>,
name: impl Into<Cow<'static, str>>,
kind: SpanKind,
) -> Span
pub fn start_span_from_traceparent( &self, traceparent: Option<&str>, name: impl Into<Cow<'static, str>>, kind: SpanKind, ) -> Span
Create a root span from an incoming W3C traceparent header.
This forwards to the runtime’s shared SpanCollector.
Sourcepub fn flush_local_spans(&self)
pub fn flush_local_spans(&self)
Flush spans recorded on the current thread into the shared collector.
Sourcepub fn drain_spans_into(&self, buf: &mut Vec<CompletedSpan>)
pub fn drain_spans_into(&self, buf: &mut Vec<CompletedSpan>)
Drain completed spans from the shared collector into buf.
Sourcepub fn register_metrics<M>(
&self,
scope: MetricScope,
metrics: M,
) -> RegisteredMetrics<M>
pub fn register_metrics<M>( &self, scope: MetricScope, metrics: M, ) -> RegisteredMetrics<M>
Register a metric group and return direct handles to it.
Registry work happens here. Recording should use the returned
RegisteredMetrics value, or handles pre-resolved inside metrics.
Sourcepub fn visit_metrics<V>(&self, visitor: &mut V)where
V: MetricVisitor,
pub fn visit_metrics<V>(&self, visitor: &mut V)where
V: MetricVisitor,
Visit all registered metric groups as structured cumulative metrics.
Sourcepub fn visit_metrics_for_scope<V>(&self, scope: &MetricScope, visitor: &mut V)where
V: MetricVisitor,
pub fn visit_metrics_for_scope<V>(&self, scope: &MetricScope, visitor: &mut V)where
V: MetricVisitor,
Visit registered metric groups that match scope.
Sourcepub fn registered_metrics_len(&self) -> usize
pub fn registered_metrics_len(&self) -> usize
Return the number of registered metric groups.
Sourcepub fn scopes(&self) -> Vec<MetricScope>
pub fn scopes(&self) -> Vec<MetricScope>
Return the registered metric scopes.
Auto Trait Implementations§
impl !Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl !UnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
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
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