#[non_exhaustive]pub struct DiagnosticsContext { /* private fields */ }Expand description
Diagnostic context for a Cosmos DB operation.
This is an immutable type containing detailed information about request execution including RU consumption, regions contacted, retry attempts, and timing information.
§Immutability
Once created from a DiagnosticsContextBuilder, a DiagnosticsContext is fully
immutable. All data is frozen at completion time, and no further mutations are possible.
This enables lock-free access and efficient sharing via Arc.
§Efficient Multi-Read
The requests method returns Arc<Vec<RequestDiagnostics>>,
allowing multiple readers to share the same allocation without cloning. This is
efficient for repeated access patterns.
§JSON Caching
JSON serialization via to_json_string is lazily cached.
The first call computes the JSON; subsequent calls return the cached string.
§JSON Verbosity Levels
- Summary: Optimized for size constraints, deduplicates similar requests
- Detailed: Full information about every request
Implementations§
Source§impl DiagnosticsContext
impl DiagnosticsContext
Sourcepub fn activity_id(&self) -> &ActivityId
pub fn activity_id(&self) -> &ActivityId
Returns the operation’s activity ID.
Sourcepub fn duration(&self) -> Duration
pub fn duration(&self) -> Duration
Returns the operation duration.
This is the total time from operation start to completion.
Sourcepub fn status(&self) -> Option<&CosmosStatus>
pub fn status(&self) -> Option<&CosmosStatus>
Returns the operation-level combined HTTP status and sub-status code.
This is the final status after all retries and failovers.
Sourcepub fn total_request_charge(&self) -> RequestCharge
pub fn total_request_charge(&self) -> RequestCharge
Returns the total request charge (RU) across all requests.
Sourcepub fn request_count(&self) -> usize
pub fn request_count(&self) -> usize
Returns the number of requests made during this operation.
Sourcepub fn regions_contacted(&self) -> Vec<Region>
pub fn regions_contacted(&self) -> Vec<Region>
Returns all regions contacted during this operation.
Sourcepub fn requests(&self) -> Arc<Vec<RequestDiagnostics>> ⓘ
pub fn requests(&self) -> Arc<Vec<RequestDiagnostics>> ⓘ
Returns a shared reference to all request diagnostics.
This returns an Arc<Vec<RequestDiagnostics>>, enabling efficient
sharing without cloning the entire vector. Cloning the Arc is
a cheap atomic increment (~5 CPU cycles).
§Example
let requests = diagnostics.requests();
for req in requests.iter() {
println!("Request to {} took {}ms", req.endpoint, req.duration_ms);
}
// requests can be stored or passed elsewhere cheaplySourcepub fn hedge_diagnostics(&self) -> Option<&HedgeDiagnostics>
pub fn hedge_diagnostics(&self) -> Option<&HedgeDiagnostics>
Returns the hedging diagnostics for this operation, if hedging was selected.
This is Some(_) if and only
if should_hedge() returned true and execute_hedged() was
entered — even when the primary won before the threshold elapsed.
None means hedging was not selected for this operation (no
strategy resolved, strategy Disabled, or eligibility check failed).
Sourcepub fn machine_id(&self) -> Option<&str>
pub fn machine_id(&self) -> Option<&str>
Returns the machine identifier, if available.
On Azure VMs this is "vmId_{vm-id}" from IMDS; off Azure it is
"uuid_{generated-uuid}" (stable for process lifetime).
Sourcepub fn fault_injection_enabled(&self) -> bool
pub fn fault_injection_enabled(&self) -> bool
Returns whether fault injection was enabled when this operation executed.
Sourcepub fn to_json_string(&self, verbosity: Option<DiagnosticsVerbosity>) -> &str
pub fn to_json_string(&self, verbosity: Option<DiagnosticsVerbosity>) -> &str
Serializes diagnostics to a JSON string.
The result is lazily cached - the first call computes the JSON, subsequent calls return the cached string (for the same verbosity level).
§Arguments
verbosity- Output verbosity level. PassNoneto use the default from options.
§Returns
JSON string representation of diagnostics, truncated in Summary mode to fit within configured size limits.
Trait Implementations§
Source§impl Clone for DiagnosticsContext
impl Clone for DiagnosticsContext
Source§impl Debug for DiagnosticsContext
impl Debug for DiagnosticsContext
Source§impl Display for DiagnosticsContext
impl Display for DiagnosticsContext
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
{ctx} — one-line summary suitable for tracing fields and log
lines: activity=… duration=…ms requests=N charge=…RU [status=…].
{ctx:#} — the one-line summary followed by the summarized
diagnostics JSON (DiagnosticsVerbosity::Summary). The detailed
JSON remains available via
to_json_string.
impl Eq for DiagnosticsContext
Source§impl PartialEq for DiagnosticsContext
impl PartialEq for DiagnosticsContext
Auto Trait Implementations§
impl !Freeze for DiagnosticsContext
impl RefUnwindSafe for DiagnosticsContext
impl Send for DiagnosticsContext
impl Sync for DiagnosticsContext
impl Unpin for DiagnosticsContext
impl UnsafeUnpin for DiagnosticsContext
impl UnwindSafe for DiagnosticsContext
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.