Skip to content

Commit

Permalink
docs: document span.in_scope() at top-level (#1344)
Browse files Browse the repository at this point in the history
## Motivation

`span.in_scope()` had a link def in the main tracing docs which was
unused, this function is quite handy to know about and I almost
re-implemented something similar to it.

I almost reimplemented this as a macro.


## Solution

Document it at top-level!

Co-authored-by: Eliza Weisman <[email protected]>
  • Loading branch information
Fishrock123 and hawkw committed Apr 30, 2021
1 parent 88b176c commit 848ee2d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@
//! # fn main() {}
//! ```
//!
//! For functions which don't have built-in tracing support and can't have
//! the `#[instrument]` attribute applied (such as from an external crate,
//! the [`Span` struct][`Span`] has a [`in_scope()` method][`in_scope`]
//! which can be used to easily wrap synchonous code in a span.
//!
//! For example:
//! ```rust
//! use tracing::info_span;
//!
//! # fn doc() -> Result<(), ()> {
//! # mod serde_json {
//! # pub(crate) fn from_slice(buf: &[u8]) -> Result<(), ()> { Ok(()) }
//! # }
//! # let buf: [u8; 0] = [];
//! let json = info_span!("json.parse").in_scope(|| serde_json::from_slice(&buf))?;
//! # let _ = json; // suppress unused variable warning
//! # Ok(())
//! # }
//! ```
//!
//! You can find more examples showing how to use this crate [here][examples].
//!
Expand Down

0 comments on commit 848ee2d

Please sign in to comment.