Struct TracedRuntime
pub struct TracedRuntime { /* private fields */ }dial9 only.Expand description
A tokio runtime paired with its (optional) dial9 telemetry guard.
The guard, when present, must outlive the runtime so traces are flushed
on drop — keeping both inside one struct enforces that ordering at the
type level (fields drop top-to-bottom, so runtime drops before guard).
Construct one of two ways:
- High-level: from a
crate::Dial9ConfigviaTracedRuntime::new(panicking, used by the#[dial9_tokio_telemetry::main]macro) orTracedRuntime::try_new(fallible). - Low-level: via
TracedRuntime::builder→TracedRuntimeBuilder::build_and_startfor direct control over the raw [tokio::runtime::Builder] andcrate::telemetry::TraceWriter. This is the path used by example code, benchmarks, and integration tests that want to wire acrate::telemetry::NullWriteror other custom writer.
Implementations§
§impl TracedRuntime
impl TracedRuntime
pub fn builder() -> TracedRuntimeBuilder
pub fn builder() -> TracedRuntimeBuilder
Create a new TracedRuntimeBuilder.
pub fn build_disabled(
builder: Builder,
) -> Result<(Runtime, TelemetryGuard), Error>
pub fn build_disabled( builder: Builder, ) -> Result<(Runtime, TelemetryGuard), Error>
Build a plain runtime with no telemetry installed.
The returned TelemetryGuard is in its disabled mode — see
TelemetryGuard::is_enabled.
pub fn build(
builder: Builder,
writer: impl TraceWriter + 'static,
) -> Result<(Runtime, TelemetryGuard), Error>
pub fn build( builder: Builder, writer: impl TraceWriter + 'static, ) -> Result<(Runtime, TelemetryGuard), Error>
Build the traced runtime. Recording starts disabled.
pub fn build_and_start(
builder: Builder,
writer: impl TraceWriter + 'static,
) -> Result<(Runtime, TelemetryGuard), Error>
pub fn build_and_start( builder: Builder, writer: impl TraceWriter + 'static, ) -> Result<(Runtime, TelemetryGuard), Error>
Build the traced runtime and immediately enable recording.
§impl TracedRuntime
impl TracedRuntime
pub fn new<C>(config: C) -> TracedRuntime
pub fn new<C>(config: C) -> TracedRuntime
Build a TracedRuntime from a config, panicking with the
underlying error on failure. Used by the
#[dial9_tokio_telemetry::main] macro.
Reach for this directly when the macro doesn’t fit — e.g. when an
application owns multiple tokio runtimes, when you need to control
runtime lifetime explicitly, or when you want to drive
TelemetryGuard::graceful_shutdown before the runtime drops.
Generic over any input that converts into a TracedRuntime: in
practice that means either the fluent
crate::Dial9Config (returned by
Dial9Config::builder) or the
deprecated positional crate::config::Dial9Config. The generic
shape is what keeps the macro source-compatible across these
input types.
§Panics
Panics if the underlying conversion fails — i.e. if the tokio
runtime cannot be built or the telemetry background worker fails
to start. When constructing from the fluent
crate::Dial9Config, writer-transport I/O has already been
validated by
Dial9ConfigBuilder::build,
so the only remaining failure modes are tokio-builder and
telemetry-core startup I/O.
For fallible construction, use try_new.
use dial9_tokio_telemetry::{Dial9Config, TracedRuntime};
let cfg = Dial9Config::builder()
.base_path("trace.bin")
.max_file_size(64 * 1024 * 1024)
.max_total_size(1024 * 1024 * 1024)
.build()?;
let rt = TracedRuntime::new(cfg);
rt.block_on(async { /* ... */ });pub fn try_new<C>(
config: C,
) -> Result<TracedRuntime, <C as TryInto<TracedRuntime>>::Error>where
C: TryInto<TracedRuntime>,
pub fn try_new<C>(
config: C,
) -> Result<TracedRuntime, <C as TryInto<TracedRuntime>>::Error>where
C: TryInto<TracedRuntime>,
Fallible counterpart to new.
Returns the conversion error directly: when constructing from
crate::Dial9Config that’s a TelemetryRuntimeError; when
constructing from the deprecated crate::config::Dial9Config
it’s a std::io::Error. Use this when you want to handle
runtime construction failure rather than panic.
use dial9_tokio_telemetry::{Dial9Config, TracedRuntime};
let cfg = Dial9Config::builder()
.base_path("trace.bin")
.max_file_size(64 * 1024 * 1024)
.max_total_size(1024 * 1024 * 1024)
.build()?;
let rt = TracedRuntime::try_new(cfg)?;
rt.block_on(async { /* ... */ });pub fn runtime(&self) -> &Runtime
pub fn runtime(&self) -> &Runtime
Borrow the underlying tokio runtime.
pub fn guard(&self) -> &TelemetryGuard
pub fn guard(&self) -> &TelemetryGuard
Borrow the telemetry guard.
The guard is always present, regardless of whether telemetry was
installed. Use TelemetryGuard::is_enabled to distinguish a
live telemetry session from an inert (disabled) guard.
pub fn block_on<F>(&self, fut: F) -> <F as Future>::Output
pub fn block_on<F>(&self, fut: F) -> <F as Future>::Output
Run fut to completion on the runtime.
The future is always spawned through the guard’s
TelemetryHandle. On an enabled guard this records poll and
wake events; on a disabled guard the handle’s spawn falls
through to plain [tokio::spawn].
Trait Implementations§
§impl Debug for TracedRuntime
impl Debug for TracedRuntime
§impl TryFrom<Dial9Config> for TracedRuntime
impl TryFrom<Dial9Config> for TracedRuntime
§type Error = TelemetryRuntimeError
type Error = TelemetryRuntimeError
§fn try_from(
config: Dial9Config,
) -> Result<TracedRuntime, <TracedRuntime as TryFrom<Dial9Config>>::Error>
fn try_from( config: Dial9Config, ) -> Result<TracedRuntime, <TracedRuntime as TryFrom<Dial9Config>>::Error>
§impl TryFrom<Dial9Config> for TracedRuntime
Bridge for the deprecated positional config API at
crate::config::Dial9Config so that it remains compatible with
TracedRuntime::new (and therefore the
#[dial9_tokio_telemetry::main] macro).
impl TryFrom<Dial9Config> for TracedRuntime
Bridge for the deprecated positional config API at
crate::config::Dial9Config so that it remains compatible with
TracedRuntime::new (and therefore the
#[dial9_tokio_telemetry::main] macro).
§fn try_from(
config: Dial9Config,
) -> Result<TracedRuntime, <TracedRuntime as TryFrom<Dial9Config>>::Error>
fn try_from( config: Dial9Config, ) -> Result<TracedRuntime, <TracedRuntime as TryFrom<Dial9Config>>::Error>
Auto Trait Implementations§
impl !Freeze for TracedRuntime
impl !RefUnwindSafe for TracedRuntime
impl !UnwindSafe for TracedRuntime
impl Send for TracedRuntime
impl Sync for TracedRuntime
impl Unpin for TracedRuntime
impl UnsafeUnpin for TracedRuntime
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more