Skip to main content

Module instrument

Module instrument 

Source
Expand description

Conditional instrumentation support for profiling.

This module provides tracing integration when the profiling feature is enabled. When disabled, instrumentation compiles to zero-cost no-ops.

§Features

  • profiling - Base feature enabling tracing spans (no backend)
  • trace-file - Trace file output in Chrome JSON (.json) or Perfetto (.pftrace) format

§Usage

For method-level instrumentation, use the #[cfg_attr] pattern:

#[cfg_attr(feature = "profiling", tracing::instrument(skip(self)))]
pub async fn my_method(&self) -> Result<T, Error> {
    // ...
}

For manual span creation within functions:

#[cfg(feature = "profiling")]
let _span = tracing::info_span!("operation_name", field = value).entered();

// ... code to profile

#[cfg(feature = "profiling")]
drop(_span);  // Optional: explicitly end span early

§Trace Output

When built with the trace-file feature, traces can be written to files:

  • .json extension → Chrome JSON format (viewable in Perfetto UI)
  • .pftrace extension → Native Perfetto format (viewable in Perfetto UI)

Use --trace-file path.json or --trace-file path.pftrace to select format.

Modules§

instrument
Attach a span to a std::future::Future.

Macros§

debug
Constructs an event at the debug level.
debug_span
Constructs a span at the debug level.
error
Constructs an event at the error level.
error_span
Constructs a span at the error level.
info
Constructs an event at the info level.
info_span
Constructs a span at the info level.
trace
Constructs an event at the trace level.
trace_span
Constructs a span at the trace level.
warn
Constructs an event at the warn level.
warn_span
Constructs a span at the warn level.

Structs§

Level
Describes the level of verbosity of a span or event.
Span
A handle representing a span, with the capability to enter the span if it exists.

Traits§

Instrument
Attaches spans to a std::future::Future.

Attribute Macros§

instrument
Instruments a function to create and enter a tracing span every time the function is called.