Struct TelemetryHandle
pub struct TelemetryHandle { /* private fields */ }dial9 only.Expand description
Cheap, cloneable handle for controlling telemetry from anywhere.
A handle may be in one of two modes:
- Enabled — backed by a real telemetry session; methods record events, control recording, and wrap spawned futures with wake tracking.
- Disabled — an inert sentinel returned by
TelemetryHandle::disabledand byTelemetryHandle::currentwhen called from a thread that is not owned by a dial9 runtime. All methods are no-ops;spawnfalls back to [tokio::spawn] without wake tracking.
Use is_enabled to distinguish the two modes.
Implementations§
§impl TelemetryHandle
impl TelemetryHandle
pub fn disabled() -> TelemetryHandle
pub fn disabled() -> TelemetryHandle
Return an inert handle that is not connected to any telemetry
session. All methods are no-ops; spawn falls
back to [tokio::spawn] without wake tracking.
pub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether this handle is connected to a live telemetry session.
Returns false for handles obtained via
TelemetryHandle::disabled, and for handles returned by
TelemetryHandle::current when called from a thread that is
not owned by a dial9 runtime.
pub fn current() -> TelemetryHandle
pub fn current() -> TelemetryHandle
Return the TelemetryHandle for the current thread.
On threads owned by a dial9 runtime (workers and blocking
threads — installed via the runtime’s on_thread_start hook,
cleared on on_thread_stop) this returns the live handle for
that runtime.
On any other thread (including the caller of
runtime.block_on(...) on a current_thread runtime, threads
outside any tokio context, and threads owned by a runtime built
with telemetry disabled) this returns an inert handle whose
methods are all no-ops — see TelemetryHandle::disabled.
Use is_enabled when you need to branch on
whether telemetry is actually live on the current thread.
pub fn try_current() -> Option<TelemetryHandle>
pub fn try_current() -> Option<TelemetryHandle>
Return the TelemetryHandle installed for the current thread,
or None if no dial9 runtime has claimed this thread.
Prefer current instead.
pub fn enable(&self)
pub fn enable(&self)
Enable telemetry recording. No-op on a disabled handle.
pub fn disable(&self)
pub fn disable(&self)
Disable telemetry recording. No-op on a disabled handle.
pub fn spawn<F>(&self, future: F) -> JoinHandle<<F as Future>::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> JoinHandle<<F as Future>::Output> ⓘ
Spawn a future on the ambient tokio runtime.
On an enabled handle, the future is wrapped with wake-event
tracking. On a disabled handle, this is a passthrough to
[tokio::spawn].
§Panics
Panics if called from outside a tokio runtime context (same
as [tokio::spawn]).
pub fn spawn_with<F, S>(
&self,
future: F,
spawn_fn: impl FnOnce(TracedFuture<F>) -> S,
) -> S
pub fn spawn_with<F, S>( &self, future: F, spawn_fn: impl FnOnce(TracedFuture<F>) -> S, ) -> S
Spawn an instrumented future through a user-supplied spawn function.
spawn_fn must synchronously perform a real Tokio spawn (or an
equivalent operation) before returning; do not defer the future or run
it with block_on. To record the resulting task as instrumented, spawn
on a dial9-traced runtime with task tracking enabled. The closure’s
return value is forwarded back to the caller, so you can keep the
[tokio::task::JoinHandle], [tokio::task::AbortHandle], or whatever
the spawn function returns.
§Examples
Spawn into a [tokio::task::JoinSet]:
let handle = TelemetryHandle::current();
let mut set: JoinSet<()> = JoinSet::new();
handle.spawn_with(work(), |f| set.spawn(f));Spawn into a [tokio::task::JoinSet] on a specific runtime:
let handle = TelemetryHandle::current();
let mut set: JoinSet<()> = JoinSet::new();
handle.spawn_with(work(), |f| set.spawn_on(f, runtime.handle()));Trait Implementations§
§impl Clone for TelemetryHandle
impl Clone for TelemetryHandle
§fn clone(&self) -> TelemetryHandle
fn clone(&self) -> TelemetryHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TelemetryHandle
impl RefUnwindSafe for TelemetryHandle
impl Send for TelemetryHandle
impl Sync for TelemetryHandle
impl Unpin for TelemetryHandle
impl UnsafeUnpin for TelemetryHandle
impl UnwindSafe for TelemetryHandle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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