pub struct Context { /* private fields */ }Expand description
A metric context.
Implementations§
Source§impl Context
impl Context
Sourcepub fn from_static_name(name: &'static str) -> Self
pub fn from_static_name(name: &'static str) -> Self
Creates a new Context from the given static name.
Sourcepub fn from_static_parts(name: &'static str, tags: &[&'static str]) -> Self
pub fn from_static_parts(name: &'static str, tags: &[&'static str]) -> Self
Creates a new Context from the given static name and given static tags.
Sourcepub fn from_parts<S: Into<MetaString>>(name: S, tags: impl Into<TagSet>) -> Self
pub fn from_parts<S: Into<MetaString>>(name: S, tags: impl Into<TagSet>) -> Self
Creates a new Context from the given name and given tags.
Sourcepub fn with_name<S: Into<MetaString>>(&self, name: S) -> Self
pub fn with_name<S: Into<MetaString>>(&self, name: S) -> Self
Clones this context, and uses the given name for the cloned context.
Clones this context, and uses the given tags for the cloned context.
The name and origin tags of this context are preserved.
Clones this context, and uses the given origin tags for the cloned context.
The name and instrumented tags of this context are preserved.
Clones this context, replacing both instrumented tags and origin tags in a single allocation.
Preferred over two separate with_tags / with_origin_tags calls when both sets need to
be replaced, as it halves the number of Arc allocations.
Returns the instrumented tags of this context.
Returns the origin tags of this context.
Mutates the instrumented tags of this context via a closure.
Uses copy-on-write semantics: if this context shares its inner data with other clones, the inner data is cloned first so that mutations do not affect other holders. If this context is the sole owner, the mutation happens in place.
The context key is automatically recomputed after the closure returns.
Mutates the origin tags of this context via a closure.
Uses copy-on-write semantics: if this context shares its inner data with other clones, the inner data is cloned first so that mutations do not affect other holders. If this context is the sole owner, the mutation happens in place.
The context key is automatically recomputed after the closure returns.
Sourcepub fn with_tag_sets_mut(&mut self, f: impl FnOnce(&mut TagSet, &mut TagSet))
pub fn with_tag_sets_mut(&mut self, f: impl FnOnce(&mut TagSet, &mut TagSet))
Mutates both instrumented tags and origin tags via a single closure.
Uses copy-on-write semantics: if this context shares its inner data with other clones, the inner data is cloned first so that mutations do not affect other holders. If this context is the sole owner, the mutation happens in place.
The context key is recomputed once after the closure returns.
Creates a lazy copy-on-write mutable view over this context’s tag sets.
The returned view supports mutations (e.g. retain_tags)
without immediately triggering an Arc clone. The actual clone, mutation, and context key
recomputation only happen when TagSetMutView::finish is called, and only if changes
were actually recorded.
state provides reusable scratch space for tracking pending changes. Holding a
long-lived TagSetMutViewState across calls amortizes any vector allocations.
Sourcepub fn size_of(&self) -> usize
pub fn size_of(&self) -> usize
Returns the size of this context in bytes.
A context’s size is the sum of the sizes of its fields and the size of the Context struct itself, and
includes:
- the context name
- the context tags (both instrumented and origin)
Since origin tags can potentially be expensive to calculate, this method will cache the size of the origin tags when this method is first called.
Additionally, the value returned by this method does not compensate for externalities such as origin tags potentially being shared by multiple contexts, or whether or not tags are inlined, interned, or heap allocated. This means that the value returned is essentially the worst-case usage, and should be used as a rough estimate.
Trait Implementations§
impl Eq for Context
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl !UnwindSafe for Context
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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§impl<T> Track for T
impl<T> Track for T
§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked wrapper. Read more