pub struct CurrentTrace;Expand description
The trace the current task is running under.
A tokio::task_local, the same mechanism the server uses for the tenant —
and with the same caveat: a bare tokio::spawn does not inherit it, so a
delegation that spawns must re-enter the scope inside the spawned task.
Implementations§
Source§impl CurrentTrace
impl CurrentTrace
Sourcepub async fn scope<F, R>(trace: TraceContext, f: F) -> Rwhere
F: Future<Output = R>,
pub async fn scope<F, R>(trace: TraceContext, f: F) -> Rwhere
F: Future<Output = R>,
Runs f with trace as the ambient context.
Sourcepub fn current() -> Option<TraceContext>
pub fn current() -> Option<TraceContext>
The ambient trace, if any scope is open.
Sourcepub fn start_root() -> TraceContext
pub fn start_root() -> TraceContext
Starts a new trace, for an agent that is the first hop in a chain.
Sampled, deliberately. An unsampled root is dropped by most
collectors, which would make the whole chain invisible — and an agent
that goes to the trouble of starting a trace means it to be recorded.
A caller wanting the other answer builds one with
TraceContext::from_bytes.
§Panics
Never, and structurally rather than improbably.
TraceContext::from_bytes rejects exactly one input — an all-zero
identifier — and a v4 UUID cannot produce one: byte 6 carries the
version nibble in its high half, so it is always in 0x40..=0x4f and
never 0x00. Both the 16-byte trace id and the 8-byte span id, which
is bytes[..8], therefore contain that byte. This is a property of
RFC 9562 §5.4, not a probability argument.
Trait Implementations§
Source§impl Clone for CurrentTrace
impl Clone for CurrentTrace
Source§fn clone(&self) -> CurrentTrace
fn clone(&self) -> CurrentTrace
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CurrentTrace
Auto Trait Implementations§
impl Freeze for CurrentTrace
impl RefUnwindSafe for CurrentTrace
impl Send for CurrentTrace
impl Sync for CurrentTrace
impl Unpin for CurrentTrace
impl UnsafeUnpin for CurrentTrace
impl UnwindSafe for CurrentTrace
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> 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 moreSource§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