Skip to main content

Dial9Handle

Struct Dial9Handle 

pub struct Dial9Handle { /* private fields */ }
Available on crate feature dial9 only.
Expand description

Cheap, cloneable handle for recording events and controlling telemetry.

A handle may be in one of two modes:

  • Enabled — backed by a live recorder; methods record events and control recording.
  • Disabled — an inert sentinel returned by Dial9Handle::disabled, and by Dial9Handle::current when neither the calling thread nor the process has a handle installed. All methods are no-ops.

Use is_enabled to distinguish the two modes.

Implementations§

§

impl Dial9Handle

pub fn disabled() -> Dial9Handle

Return an inert handle that is not connected to any recorder. All methods are no-ops.

pub fn is_enabled(&self) -> bool

Whether recording through this handle currently does anything: the handle is connected to a live recorder AND recording is enabled (not paused via disable).

Returns false for handles obtained via Dial9Handle::disabled, for any handle Dial9Handle::current could not resolve, and while a connected recorder is paused.

Check this before doing per-event work that would be wasted while recording is off, such as work leading up to with_encoder. The check can race a concurrent enable/disable, which is benign since the event either lands or is skipped anyway.

To ask only whether the handle is connected at all, regardless of pause state, use is_connected.

pub fn dump_trigger(&self) -> Option<DumpTrigger>

Available on crate feature pipeline only.

On-demand dump trigger for this runtime’s recorder.

Returns None on a disabled handle (see disabled) and when the runtime was built without a dump trigger (with_dump_trigger). The returned DumpTrigger is cheap to clone and every clone shares the configured debounce gate.

pub fn current() -> Dial9Handle

Return the Dial9Handle to record through, resolved in order:

  1. The handle installed on this thread with set_tl_handle, which runtime integrations do for the threads they own.
  2. The process-global handle, if Recorder::install_global_handle has been called.
  3. An inert disabled handle, where recording is a no-op.

Use is_enabled to branch on whether telemetry is live here.

pub fn try_current_thread() -> Option<Dial9Handle>

Return the Dial9Handle installed on this thread with set_tl_handle, or None if there is none.

Unlike current, never falls back to the process-global handle. To record an event, use current.

pub fn enable(&self)

Enable telemetry recording. No-op on a disabled handle.

pub fn disable(&self)

Disable telemetry recording. No-op on a disabled handle.

pub fn track_current_thread(&self) -> Result<ThreadTrackingGuard, Error>

Profile the calling thread.

Per-thread sources, such as the scheduler-event profiler, only sample threads that opt in. Tokio workers opt in on their own, call this from any other thread you want profiled. Profiling lasts until the returned guard drops.

Returns an error if a source could not start on this thread. No-op on a disabled handle.

use dial9_core::buffer::MemoryBuffer;
use dial9_core::recorder::recorder;

let rec = recorder(MemoryBuffer::new(1 << 20)?).build();
let handle = rec.handle().clone();

std::thread::spawn(move || -> std::io::Result<()> {
    let _tracking = handle.track_current_thread()?;
    // work here is sampled by the recorder's per-thread sources
    Ok(())
});

pub fn is_connected(&self) -> bool

Whether this handle is wired to a recorder at all, regardless of whether recording is currently paused.

is_enabled answers the narrower question of whether a record right now would land.

pub fn is_stopped(&self) -> bool

Whether the recorder behind this handle has shut down.

Terminal: a stopped recorder never records again. Returns false for a handle that is merely paused (see disable) and for a disabled handle, neither of which is stopped.

pub fn with_source<T, R>(&self, f: impl FnOnce(&mut T) -> R) -> Option<R>
where T: Source,

Run f against this recorder’s source of type T.

None when the handle is disabled, no T is registered, or the source lock is poisoned.

pub fn with_source_or_insert<T, R>( &self, make: impl FnOnce() -> T, f: impl FnOnce(&mut T) -> R, ) -> Option<R>
where T: Source,

Run f against this recorder’s source of type T, registering the one make builds if there is not one yet.

None when the handle is disabled, the recorder has shut down, or the source lock is poisoned.

pub fn record_event(&self, event: impl Encodable)

Record a custom event into the trace.

Any type implementing dial9_trace_format::TraceEvent (typically via #[derive(TraceEvent)]) works directly. No-op on a disabled handle or when recording is paused.

pub fn record_event_with<E>(&self, make: impl FnOnce() -> E)
where E: Encodable,

Record an event that is only built when recording is on.

Reach for this over record_event when building the event costs something you would rather not pay while recording is paused, such as a clock read or a lookup. make runs only if the event will be recorded.

Trait Implementations§

§

impl Clone for Dial9Handle

§

fn clone(&self) -> Dial9Handle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Dial9Handle

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Dial9HandleTokioExt for Dial9Handle

§

fn attach_tokio_runtime( &self, builder: Builder, options: TokioAttachOptions, ) -> Result<Runtime, Error>

Instrument a builder you configured, build it, and return the runtime. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a rama_grpc::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> RamaFrom<T> for U
where U: From<T>,

§

fn rama_from(value: T) -> U

§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

§

fn rama_into(self) -> U

§

impl<T, U> RamaTryFrom<T> for U
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

§

fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>

§

impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for T
where U: RamaTryFrom<T, CrateMarker>,

§

type Error = <U as RamaTryFrom<T, CrateMarker>>::Error

§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<V, F> ValueFormatter<&V> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &&V)

Write value to writer
§

impl<V, F> ValueFormatter<Arc<V>> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Arc<V>)

Write value to writer
§

impl<V, F> ValueFormatter<Box<V>> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Box<V>)

Write value to writer
§

impl<V, F> ValueFormatter<Cow<'_, V>> for F
where V: ToOwned + ?Sized, F: ValueFormatter<V> + ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)

Write value to writer
§

impl<V, F> ValueFormatter<Option<V>> for F
where F: ValueFormatter<V> + ?Sized,

§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
§

fn format_value(writer: impl ValueWriter, value: &Option<V>)

Write value to writer
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more