summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tracing/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/tracing/src
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tracing/src')
-rw-r--r--third_party/rust/tracing/src/dispatcher.rs152
-rw-r--r--third_party/rust/tracing/src/field.rs62
-rw-r--r--third_party/rust/tracing/src/instrument.rs194
-rw-r--r--third_party/rust/tracing/src/level_filters.rs81
-rw-r--r--third_party/rust/tracing/src/lib.rs1035
-rw-r--r--third_party/rust/tracing/src/macros.rs2369
-rw-r--r--third_party/rust/tracing/src/span.rs1283
-rw-r--r--third_party/rust/tracing/src/stdlib.rs55
-rw-r--r--third_party/rust/tracing/src/subscriber.rs68
9 files changed, 5299 insertions, 0 deletions
diff --git a/third_party/rust/tracing/src/dispatcher.rs b/third_party/rust/tracing/src/dispatcher.rs
new file mode 100644
index 0000000000..4041c994fb
--- /dev/null
+++ b/third_party/rust/tracing/src/dispatcher.rs
@@ -0,0 +1,152 @@
+//! Dispatches trace events to [`Subscriber`]s.
+//!
+//! The _dispatcher_ is the component of the tracing system which is responsible
+//! for forwarding trace data from the instrumentation points that generate it
+//! to the subscriber that collects it.
+//!
+//! # Using the Trace Dispatcher
+//!
+//! Every thread in a program using `tracing` has a _default subscriber_. When
+//! events occur, or spans are created, they are dispatched to the thread's
+//! current subscriber.
+//!
+//! ## Setting the Default Subscriber
+//!
+//! By default, the current subscriber is an empty implementation that does
+//! nothing. To use a subscriber implementation, it must be set as the default.
+//! There are two methods for doing so: [`with_default`] and
+//! [`set_global_default`]. `with_default` sets the default subscriber for the
+//! duration of a scope, while `set_global_default` sets a default subscriber
+//! for the entire process.
+//!
+//! To use either of these functions, we must first wrap our subscriber in a
+//! [`Dispatch`], a cloneable, type-erased reference to a subscriber. For
+//! example:
+//! ```rust
+//! # pub struct FooSubscriber;
+//! # use tracing_core::{
+//! # dispatcher, Event, Metadata,
+//! # span::{Attributes, Id, Record}
+//! # };
+//! # impl tracing_core::Subscriber for FooSubscriber {
+//! # fn new_span(&self, _: &Attributes) -> Id { Id::from_u64(0) }
+//! # fn record(&self, _: &Id, _: &Record) {}
+//! # fn event(&self, _: &Event) {}
+//! # fn record_follows_from(&self, _: &Id, _: &Id) {}
+//! # fn enabled(&self, _: &Metadata) -> bool { false }
+//! # fn enter(&self, _: &Id) {}
+//! # fn exit(&self, _: &Id) {}
+//! # }
+//! # impl FooSubscriber { fn new() -> Self { FooSubscriber } }
+//! use dispatcher::Dispatch;
+//!
+//! let my_subscriber = FooSubscriber::new();
+//! let my_dispatch = Dispatch::new(my_subscriber);
+//! ```
+//! Then, we can use [`with_default`] to set our `Dispatch` as the default for
+//! the duration of a block:
+//! ```rust
+//! # pub struct FooSubscriber;
+//! # use tracing_core::{
+//! # dispatcher, Event, Metadata,
+//! # span::{Attributes, Id, Record}
+//! # };
+//! # impl tracing_core::Subscriber for FooSubscriber {
+//! # fn new_span(&self, _: &Attributes) -> Id { Id::from_u64(0) }
+//! # fn record(&self, _: &Id, _: &Record) {}
+//! # fn event(&self, _: &Event) {}
+//! # fn record_follows_from(&self, _: &Id, _: &Id) {}
+//! # fn enabled(&self, _: &Metadata) -> bool { false }
+//! # fn enter(&self, _: &Id) {}
+//! # fn exit(&self, _: &Id) {}
+//! # }
+//! # impl FooSubscriber { fn new() -> Self { FooSubscriber } }
+//! # let my_subscriber = FooSubscriber::new();
+//! # let my_dispatch = dispatcher::Dispatch::new(my_subscriber);
+//! // no default subscriber
+//!
+//! # #[cfg(feature = "std")]
+//! dispatcher::with_default(&my_dispatch, || {
+//! // my_subscriber is the default
+//! });
+//!
+//! // no default subscriber again
+//! ```
+//! It's important to note that `with_default` will not propagate the current
+//! thread's default subscriber to any threads spawned within the `with_default`
+//! block. To propagate the default subscriber to new threads, either use
+//! `with_default` from the new thread, or use `set_global_default`.
+//!
+//! As an alternative to `with_default`, we can use [`set_global_default`] to
+//! set a `Dispatch` as the default for all threads, for the lifetime of the
+//! program. For example:
+//! ```rust
+//! # pub struct FooSubscriber;
+//! # use tracing_core::{
+//! # dispatcher, Event, Metadata,
+//! # span::{Attributes, Id, Record}
+//! # };
+//! # impl tracing_core::Subscriber for FooSubscriber {
+//! # fn new_span(&self, _: &Attributes) -> Id { Id::from_u64(0) }
+//! # fn record(&self, _: &Id, _: &Record) {}
+//! # fn event(&self, _: &Event) {}
+//! # fn record_follows_from(&self, _: &Id, _: &Id) {}
+//! # fn enabled(&self, _: &Metadata) -> bool { false }
+//! # fn enter(&self, _: &Id) {}
+//! # fn exit(&self, _: &Id) {}
+//! # }
+//! # impl FooSubscriber { fn new() -> Self { FooSubscriber } }
+//! # let my_subscriber = FooSubscriber::new();
+//! # let my_dispatch = dispatcher::Dispatch::new(my_subscriber);
+//! // no default subscriber
+//!
+//! dispatcher::set_global_default(my_dispatch)
+//! // `set_global_default` will return an error if the global default
+//! // subscriber has already been set.
+//! .expect("global default was already set!");
+//!
+//! // `my_subscriber` is now the default
+//! ```
+//! <div class="information">
+//! <div class="tooltip ignore" style="">ⓘ<span class="tooltiptext">Note</span></div>
+//! </div>
+//! <div class="example-wrap" style="display:inline-block">
+//! <pre class="ignore" style="white-space:normal;font:inherit;">
+//! <strong>Note</strong>: The thread-local scoped dispatcher (<code>with_default</code>)
+//! requires the Rust standard library. <code>no_std</code> users should
+//! use <a href="fn.set_global_default.html"><code>set_global_default</code></a>
+//! instead.
+//! </pre></div>
+//!
+//! ## Accessing the Default Subscriber
+//!
+//! A thread's current default subscriber can be accessed using the
+//! [`get_default`] function, which executes a closure with a reference to the
+//! currently default `Dispatch`. This is used primarily by `tracing`
+//! instrumentation.
+//!
+//! [`Subscriber`]: struct.Subscriber.html
+//! [`with_default`]: fn.with_default.html
+//! [`set_global_default`]: fn.set_global_default.html
+//! [`get_default`]: fn.get_default.html
+//! [`Dispatch`]: struct.Dispatch.html
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+pub use tracing_core::dispatcher::set_default;
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+pub use tracing_core::dispatcher::with_default;
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+pub use tracing_core::dispatcher::DefaultGuard;
+pub use tracing_core::dispatcher::{
+ get_default, set_global_default, Dispatch, SetGlobalDefaultError,
+};
+
+/// Private API for internal use by tracing's macros.
+///
+/// This function is *not* considered part of `tracing`'s public API, and has no
+/// stability guarantees. If you use it, and it breaks or disappears entirely,
+/// don't say we didn;'t warn you.
+#[doc(hidden)]
+pub use tracing_core::dispatcher::has_been_set;
diff --git a/third_party/rust/tracing/src/field.rs b/third_party/rust/tracing/src/field.rs
new file mode 100644
index 0000000000..2514336585
--- /dev/null
+++ b/third_party/rust/tracing/src/field.rs
@@ -0,0 +1,62 @@
+//! Structured data associated with `Span`s and `Event`s.
+pub use tracing_core::field::*;
+
+use crate::Metadata;
+
+/// Trait implemented to allow a type to be used as a field key.
+///
+/// <div class="information">
+/// <div class="tooltip ignore" style="">ⓘ<span class="tooltiptext">Note</span></div>
+/// </div>
+/// <div class="example-wrap" style="display:inline-block">
+/// <pre class="ignore" style="white-space:normal;font:inherit;">
+/// <strong>Note</strong>: Although this is implemented for both the
+/// <a href="./struct.Field.html"><code>Field</code></a> type <em>and</em> any
+/// type that can be borrowed as an <code>&str</code>, only <code>Field</code>
+/// allows <em>O</em>(1) access.
+/// Indexing a field with a string results in an iterative search that performs
+/// string comparisons. Thus, if possible, once the key for a field is known, it
+/// should be used whenever possible.
+/// </pre>
+pub trait AsField: crate::sealed::Sealed {
+ /// Attempts to convert `&self` into a `Field` with the specified `metadata`.
+ ///
+ /// If `metadata` defines this field, then the field is returned. Otherwise,
+ /// this returns `None`.
+ fn as_field(&self, metadata: &Metadata<'_>) -> Option<Field>;
+}
+
+// ===== impl AsField =====
+
+impl AsField for Field {
+ #[inline]
+ fn as_field(&self, metadata: &Metadata<'_>) -> Option<Field> {
+ if self.callsite() == metadata.callsite() {
+ Some(self.clone())
+ } else {
+ None
+ }
+ }
+}
+
+impl<'a> AsField for &'a Field {
+ #[inline]
+ fn as_field(&self, metadata: &Metadata<'_>) -> Option<Field> {
+ if self.callsite() == metadata.callsite() {
+ Some((*self).clone())
+ } else {
+ None
+ }
+ }
+}
+
+impl AsField for str {
+ #[inline]
+ fn as_field(&self, metadata: &Metadata<'_>) -> Option<Field> {
+ metadata.fields().field(&self)
+ }
+}
+
+impl crate::sealed::Sealed for Field {}
+impl<'a> crate::sealed::Sealed for &'a Field {}
+impl crate::sealed::Sealed for str {}
diff --git a/third_party/rust/tracing/src/instrument.rs b/third_party/rust/tracing/src/instrument.rs
new file mode 100644
index 0000000000..d1070ba8e2
--- /dev/null
+++ b/third_party/rust/tracing/src/instrument.rs
@@ -0,0 +1,194 @@
+use crate::stdlib::pin::Pin;
+use crate::stdlib::task::{Context, Poll};
+use crate::stdlib::{future::Future, marker::Sized};
+use crate::{dispatcher, span::Span, Dispatch};
+use pin_project_lite::pin_project;
+
+/// Attaches spans to a `std::future::Future`.
+///
+/// Extension trait allowing futures to be
+/// instrumented with a `tracing` [span].
+///
+/// [span]: ../struct.Span.html
+pub trait Instrument: Sized {
+ /// Instruments this type with the provided `Span`, returning an
+ /// `Instrumented` wrapper.
+ ///
+ /// The attached `Span` will be [entered] every time the instrumented `Future` is polled.
+ ///
+ /// # Examples
+ ///
+ /// Instrumenting a future:
+ ///
+ /// ```rust
+ /// use tracing::Instrument;
+ ///
+ /// # async fn doc() {
+ /// let my_future = async {
+ /// // ...
+ /// };
+ ///
+ /// my_future
+ /// .instrument(tracing::info_span!("my_future"))
+ /// .await
+ /// # }
+ /// ```
+ ///
+ /// [entered]: ../struct.Span.html#method.enter
+ fn instrument(self, span: Span) -> Instrumented<Self> {
+ Instrumented { inner: self, span }
+ }
+
+ /// Instruments this type with the [current] `Span`, returning an
+ /// `Instrumented` wrapper.
+ ///
+ /// If the instrumented type is a future, stream, or sink, the attached `Span`
+ /// will be [entered] every time it is polled. If the instrumented type
+ /// is a future executor, every future spawned on that executor will be
+ /// instrumented by the attached `Span`.
+ ///
+ /// This can be used to propagate the current span when spawning a new future.
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// use tracing::Instrument;
+ ///
+ /// # async fn doc() {
+ /// let span = tracing::info_span!("my_span");
+ /// let _enter = span.enter();
+ ///
+ /// // ...
+ ///
+ /// let future = async {
+ /// tracing::debug!("this event will occur inside `my_span`");
+ /// // ...
+ /// };
+ /// tokio::spawn(future.in_current_span());
+ /// # }
+ /// ```
+ ///
+ /// [current]: ../struct.Span.html#method.current
+ /// [entered]: ../struct.Span.html#method.enter
+ #[inline]
+ fn in_current_span(self) -> Instrumented<Self> {
+ self.instrument(Span::current())
+ }
+}
+
+/// Extension trait allowing futures to be instrumented with
+/// a `tracing` [`Subscriber`].
+///
+/// [`Subscriber`]: ../trait.Subscriber.html
+pub trait WithSubscriber: Sized {
+ /// Attaches the provided [`Subscriber`] to this type, returning a
+ /// `WithDispatch` wrapper.
+ ///
+ /// The attached subscriber will be set as the [default] when the returned `Future` is polled.
+ ///
+ /// [`Subscriber`]: ../trait.Subscriber.html
+ /// [default]: https://docs.rs/tracing/latest/tracing/dispatcher/index.html#setting-the-default-subscriber
+ fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
+ where
+ S: Into<Dispatch>,
+ {
+ WithDispatch {
+ inner: self,
+ dispatch: subscriber.into(),
+ }
+ }
+
+ /// Attaches the current [default] [`Subscriber`] to this type, returning a
+ /// `WithDispatch` wrapper.
+ ///
+ /// When the wrapped type is a future, stream, or sink, the attached
+ /// subscriber will be set as the [default] while it is being polled.
+ /// When the wrapped type is an executor, the subscriber will be set as the
+ /// default for any futures spawned on that executor.
+ ///
+ /// This can be used to propagate the current dispatcher context when
+ /// spawning a new future.
+ ///
+ /// [`Subscriber`]: ../trait.Subscriber.html
+ /// [default]: https://docs.rs/tracing/latest/tracing/dispatcher/index.html#setting-the-default-subscriber
+ #[inline]
+ fn with_current_subscriber(self) -> WithDispatch<Self> {
+ WithDispatch {
+ inner: self,
+ dispatch: dispatcher::get_default(|default| default.clone()),
+ }
+ }
+}
+
+pin_project! {
+ /// A future that has been instrumented with a `tracing` subscriber.
+ #[derive(Clone, Debug)]
+ #[must_use = "futures do nothing unless you `.await` or poll them"]
+ pub struct WithDispatch<T> {
+ #[pin]
+ inner: T,
+ dispatch: Dispatch,
+ }
+}
+
+pin_project! {
+ /// A future that has been instrumented with a `tracing` span.
+ #[derive(Debug, Clone)]
+ #[must_use = "futures do nothing unless you `.await` or poll them"]
+ pub struct Instrumented<T> {
+ #[pin]
+ inner: T,
+ span: Span,
+ }
+}
+
+impl<T: Future> Future for Instrumented<T> {
+ type Output = T::Output;
+
+ fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
+ let this = self.project();
+ let _enter = this.span.enter();
+ this.inner.poll(cx)
+ }
+}
+
+impl<T: Sized> Instrument for T {}
+
+impl<T> Instrumented<T> {
+ /// Borrows the `Span` that this type is instrumented by.
+ pub fn span(&self) -> &Span {
+ &self.span
+ }
+
+ /// Mutably borrows the `Span` that this type is instrumented by.
+ pub fn span_mut(&mut self) -> &mut Span {
+ &mut self.span
+ }
+
+ /// Borrows the wrapped type.
+ pub fn inner(&self) -> &T {
+ &self.inner
+ }
+
+ /// Mutably borrows the wrapped type.
+ pub fn inner_mut(&mut self) -> &mut T {
+ &mut self.inner
+ }
+
+ /// Get a pinned reference to the wrapped type.
+ pub fn inner_pin_ref(self: Pin<&Self>) -> Pin<&T> {
+ self.project_ref().inner
+ }
+
+ /// Get a pinned mutable reference to the wrapped type.
+ pub fn inner_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> {
+ self.project().inner
+ }
+
+ /// Consumes the `Instrumented`, returning the wrapped type.
+ ///
+ /// Note that this drops the span.
+ pub fn into_inner(self) -> T {
+ self.inner
+ }
+}
diff --git a/third_party/rust/tracing/src/level_filters.rs b/third_party/rust/tracing/src/level_filters.rs
new file mode 100644
index 0000000000..df9405b5e4
--- /dev/null
+++ b/third_party/rust/tracing/src/level_filters.rs
@@ -0,0 +1,81 @@
+//! Trace verbosity level filtering.
+//!
+//! # Compile time filters
+//!
+//! Trace verbosity levels can be statically disabled at compile time via Cargo
+//! features, similar to the [`log` crate]. Trace instrumentation at disabled
+//! levels will be skipped and will not even be present in the resulting binary
+//! unless the verbosity level is specified dynamically. This level is
+//! configured separately for release and debug builds. The features are:
+//!
+//! * `max_level_off`
+//! * `max_level_error`
+//! * `max_level_warn`
+//! * `max_level_info`
+//! * `max_level_debug`
+//! * `max_level_trace`
+//! * `release_max_level_off`
+//! * `release_max_level_error`
+//! * `release_max_level_warn`
+//! * `release_max_level_info`
+//! * `release_max_level_debug`
+//! * `release_max_level_trace`
+//!
+//! These features control the value of the `STATIC_MAX_LEVEL` constant. The
+//! instrumentation macros macros check this value before recording an event or
+//! constructing a span. By default, no levels are disabled.
+//!
+//! For example, a crate can disable trace level instrumentation in debug builds
+//! and trace, debug, and info level instrumentation in release builds with the
+//! following configuration:
+//!
+//! ```toml
+//! [dependencies]
+//! tracing = { version = "0.1", features = ["max_level_debug", "release_max_level_warn"] }
+//! ```
+//!
+//! *Compiler support: requires rustc 1.39+*
+//!
+//! [`log` crate]: https://docs.rs/log/0.4.6/log/#compile-time-filters
+pub use tracing_core::{metadata::ParseLevelFilterError, LevelFilter};
+
+/// The statically configured maximum trace level.
+///
+/// See the [module-level documentation] for information on how to configure
+/// this.
+///
+/// This value is checked by the `event!` and `span!` macros. Code that
+/// manually constructs events or spans via the `Event::record` function or
+/// `Span` constructors should compare the level against this value to
+/// determine if those spans or events are enabled.
+///
+/// [module-level documentation]: ../index.html#compile-time-filters
+pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL;
+
+cfg_if! {
+ if #[cfg(all(not(debug_assertions), feature = "release_max_level_off"))] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::OFF;
+ } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_error"))] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::ERROR;
+ } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_warn"))] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::WARN;
+ } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_info"))] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::INFO;
+ } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_debug"))] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::DEBUG;
+ } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_trace"))] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::TRACE;
+ } else if #[cfg(feature = "max_level_off")] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::OFF;
+ } else if #[cfg(feature = "max_level_error")] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::ERROR;
+ } else if #[cfg(feature = "max_level_warn")] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::WARN;
+ } else if #[cfg(feature = "max_level_info")] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::INFO;
+ } else if #[cfg(feature = "max_level_debug")] {
+ const MAX_LEVEL: LevelFilter = LevelFilter::DEBUG;
+ } else {
+ const MAX_LEVEL: LevelFilter = LevelFilter::TRACE;
+ }
+}
diff --git a/third_party/rust/tracing/src/lib.rs b/third_party/rust/tracing/src/lib.rs
new file mode 100644
index 0000000000..5fc5382642
--- /dev/null
+++ b/third_party/rust/tracing/src/lib.rs
@@ -0,0 +1,1035 @@
+//! A scoped, structured logging and diagnostics system.
+//!
+//! # Overview
+//!
+//! `tracing` is a framework for instrumenting Rust programs to collect
+//! structured, event-based diagnostic information.
+//!
+//! In asynchronous systems like Tokio, interpreting traditional log messages can
+//! often be quite challenging. Since individual tasks are multiplexed on the same
+//! thread, associated events and log lines are intermixed making it difficult to
+//! trace the logic flow. `tracing` expands upon logging-style diagnostics by
+//! allowing libraries and applications to record structured events with additional
+//! information about *temporality* and *causality* — unlike a log message, a span
+//! in `tracing` has a beginning and end time, may be entered and exited by the
+//! flow of execution, and may exist within a nested tree of similar spans. In
+//! addition, `tracing` spans are *structured*, with the ability to record typed
+//! data as well as textual messages.
+//!
+//! The `tracing` crate provides the APIs necessary for instrumenting libraries
+//! and applications to emit trace data.
+//!
+//! *Compiler support: [requires `rustc` 1.40+][msrv]*
+//!
+//! [msrv]: #supported-rust-versions
+//! # Core Concepts
+//!
+//! The core of `tracing`'s API is composed of _spans_, _events_ and
+//! _subscribers_. We'll cover these in turn.
+//!
+//! ## Spans
+//!
+//! To record the flow of execution through a program, `tracing` introduces the
+//! concept of [spans]. Unlike a log line that represents a _moment in
+//! time_, a span represents a _period of time_ with a beginning and an end. When a
+//! program begins executing in a context or performing a unit of work, it
+//! _enters_ that context's span, and when it stops executing in that context,
+//! it _exits_ the span. The span in which a thread is currently executing is
+//! referred to as that thread's _current_ span.
+//!
+//! For example:
+//! ```
+//! use tracing::{span, Level};
+//! # fn main() {
+//! let span = span!(Level::TRACE, "my_span");
+//! // `enter` returns a RAII guard which, when dropped, exits the span. this
+//! // indicates that we are in the span for the current lexical scope.
+//! let _enter = span.enter();
+//! // perform some work in the context of `my_span`...
+//! # }
+//!```
+//!
+//! The [`span` module][span]'s documentation provides further details on how to
+//! use spans.
+//!
+//! <div class="information">
+//! <div class="tooltip compile_fail" style="">&#x26a0; &#xfe0f;<span class="tooltiptext">Warning</span></div>
+//! </div><div class="example-wrap" style="display:inline-block"><pre class="compile_fail" style="white-space:normal;font:inherit;">
+//! <strong>Warning</strong>: In asynchronous code that uses async/await syntax,
+//! <code>Span::enter</code> may produce incorrect traces if the returned drop
+//! guard is held across an await point. See
+//! <a href="span/struct.Span.html#in-asynchronous-code">the method documentation</a>
+//! for details.
+//! </pre></div>
+//!
+//! ## Events
+//!
+//! An [`Event`] represents a _moment_ in time. It signifies something that
+//! happened while a trace was being recorded. `Event`s are comparable to the log
+//! records emitted by unstructured logging code, but unlike a typical log line,
+//! an `Event` may occur within the context of a span.
+//!
+//! For example:
+//! ```
+//! use tracing::{event, span, Level};
+//!
+//! # fn main() {
+//! // records an event outside of any span context:
+//! event!(Level::INFO, "something happened");
+//!
+//! let span = span!(Level::INFO, "my_span");
+//! let _guard = span.enter();
+//!
+//! // records an event within "my_span".
+//! event!(Level::DEBUG, "something happened inside my_span");
+//! # }
+//!```
+//!
+//! In general, events should be used to represent points in time _within_ a
+//! span — a request returned with a given status code, _n_ new items were
+//! taken from a queue, and so on.
+//!
+//! The [`Event` struct][`Event`] documentation provides further details on using
+//! events.
+//!
+//! ## Subscribers
+//!
+//! As `Span`s and `Event`s occur, they are recorded or aggregated by
+//! implementations of the [`Subscriber`] trait. `Subscriber`s are notified
+//! when an `Event` takes place and when a `Span` is entered or exited. These
+//! notifications are represented by the following `Subscriber` trait methods:
+//!
+//! + [`event`][Subscriber::event], called when an `Event` takes place,
+//! + [`enter`], called when execution enters a `Span`,
+//! + [`exit`], called when execution exits a `Span`
+//!
+//! In addition, subscribers may implement the [`enabled`] function to _filter_
+//! the notifications they receive based on [metadata] describing each `Span`
+//! or `Event`. If a call to `Subscriber::enabled` returns `false` for a given
+//! set of metadata, that `Subscriber` will *not* be notified about the
+//! corresponding `Span` or `Event`. For performance reasons, if no currently
+//! active subscribers express interest in a given set of metadata by returning
+//! `true`, then the corresponding `Span` or `Event` will never be constructed.
+//!
+//! # Usage
+//!
+//! First, add this to your `Cargo.toml`:
+//!
+//! ```toml
+//! [dependencies]
+//! tracing = "0.1"
+//! ```
+//!
+//! *Compiler support: requires rustc 1.39+*
+//!
+//! ## Recording Spans and Events
+//!
+//! Spans and events are recorded using macros.
+//!
+//! ### Spans
+//!
+//! The [`span!`] macro expands to a [`Span` struct][`Span`] which is used to
+//! record a span. The [`Span::enter`] method on that struct records that the
+//! span has been entered, and returns a [RAII] guard object, which will exit
+//! the span when dropped.
+//!
+//! For example:
+//!
+//! ```rust
+//! use tracing::{span, Level};
+//! # fn main() {
+//! // Construct a new span named "my span" with trace log level.
+//! let span = span!(Level::TRACE, "my span");
+//!
+//! // Enter the span, returning a guard object.
+//! let _enter = span.enter();
+//!
+//! // Any trace events that occur before the guard is dropped will occur
+//! // within the span.
+//!
+//! // Dropping the guard will exit the span.
+//! # }
+//! ```
+//!
+//! The [`#[instrument]`][instrument] attribute provides an easy way to
+//! add `tracing` spans to functions. A function annotated with `#[instrument]`
+//! will create and enter a span with that function's name every time the
+//! function is called, with arguments to that function will be recorded as
+//! fields using `fmt::Debug`.
+//!
+//! For example:
+//! ```ignore
+//! # // this doctest is ignored because we don't have a way to say
+//! # // that it should only be run with cfg(feature = "attributes")
+//! use tracing::{Level, event, instrument};
+//!
+//! #[instrument]
+//! pub fn my_function(my_arg: usize) {
+//! // This event will be recorded inside a span named `my_function` with the
+//! // field `my_arg`.
+//! event!(Level::INFO, "inside my_function!");
+//! // ...
+//! }
+//! # fn main() {}
+//! ```
+//!
+//!
+//! You can find more examples showing how to use this crate [here][examples].
+//!
+//! [RAII]: https://github.com/rust-unofficial/patterns/blob/master/patterns/RAII.md
+//! [examples]: https://github.com/tokio-rs/tracing/tree/master/examples
+//!
+//! ### Events
+//!
+//! [`Event`]s are recorded using the [`event!`] macro:
+//!
+//! ```rust
+//! # fn main() {
+//! use tracing::{event, Level};
+//! event!(Level::INFO, "something has happened!");
+//! # }
+//! ```
+//!
+//! ## Using the Macros
+//!
+//! The [`span!`] and [`event!`] macros use fairly similar syntax, with some
+//! exceptions.
+//!
+//! ### Configuring Attributes
+//!
+//! Both macros require a [`Level`] specifying the verbosity of the span or
+//! event. Optionally, the [target] and [parent span] may be overridden. If the
+//! target and parent span are not overridden, they will default to the
+//! module path where the macro was invoked and the current span (as determined
+//! by the subscriber), respectively.
+//!
+//! For example:
+//!
+//! ```
+//! # use tracing::{span, event, Level};
+//! # fn main() {
+//! span!(target: "app_spans", Level::TRACE, "my span");
+//! event!(target: "app_events", Level::INFO, "something has happened!");
+//! # }
+//! ```
+//! ```
+//! # use tracing::{span, event, Level};
+//! # fn main() {
+//! let span = span!(Level::TRACE, "my span");
+//! event!(parent: &span, Level::INFO, "something has happened!");
+//! # }
+//! ```
+//!
+//! The span macros also take a string literal after the level, to set the name
+//! of the span.
+//!
+//! ### Recording Fields
+//!
+//! Structured fields on spans and events are specified using the syntax
+//! `field_name = field_value`. Fields are separated by commas.
+//!
+//! ```
+//! # use tracing::{event, Level};
+//! # fn main() {
+//! // records an event with two fields:
+//! // - "answer", with the value 42
+//! // - "question", with the value "life, the universe and everything"
+//! event!(Level::INFO, answer = 42, question = "life, the universe, and everything");
+//! # }
+//! ```
+//!
+//! As shorthand, local variables may be used as field values without an
+//! assignment, similar to [struct initializers]. For example:
+//!
+//! ```
+//! # use tracing::{span, Level};
+//! # fn main() {
+//! let user = "ferris";
+//!
+//! span!(Level::TRACE, "login", user);
+//! // is equivalent to:
+//! span!(Level::TRACE, "login", user = user);
+//! # }
+//!```
+//!
+//! Field names can include dots, but should not be terminated by them:
+//! ```
+//! # use tracing::{span, Level};
+//! # fn main() {
+//! let user = "ferris";
+//! let email = "ferris@rust-lang.org";
+//! span!(Level::TRACE, "login", user, user.email = email);
+//! # }
+//!```
+//!
+//! Since field names can include dots, fields on local structs can be used
+//! using the local variable shorthand:
+//! ```
+//! # use tracing::{span, Level};
+//! # fn main() {
+//! # struct User {
+//! # name: &'static str,
+//! # email: &'static str,
+//! # }
+//! let user = User {
+//! name: "ferris",
+//! email: "ferris@rust-lang.org",
+//! };
+//! // the span will have the fields `user.name = "ferris"` and
+//! // `user.email = "ferris@rust-lang.org"`.
+//! span!(Level::TRACE, "login", user.name, user.email);
+//! # }
+//!```
+//!
+//! Fields with names that are not Rust identifiers, or with names that are Rust reserved words,
+//! may be created using quoted string literals. However, this may not be used with the local
+//! variable shorthand.
+//! ```
+//! # use tracing::{span, Level};
+//! # fn main() {
+//! // records an event with fields whose names are not Rust identifiers
+//! // - "guid:x-request-id", containing a `:`, with the value "abcdef"
+//! // - "type", which is a reserved word, with the value "request"
+//! span!(Level::TRACE, "api", "guid:x-request-id" = "abcdef", "type" = "request");
+//! # }
+//!```
+//!
+//! The `?` sigil is shorthand that specifies a field should be recorded using
+//! its [`fmt::Debug`] implementation:
+//! ```
+//! # use tracing::{event, Level};
+//! # fn main() {
+//! #[derive(Debug)]
+//! struct MyStruct {
+//! field: &'static str,
+//! }
+//!
+//! let my_struct = MyStruct {
+//! field: "Hello world!"
+//! };
+//!
+//! // `my_struct` will be recorded using its `fmt::Debug` implementation.
+//! event!(Level::TRACE, greeting = ?my_struct);
+//! // is equivalent to:
+//! event!(Level::TRACE, greeting = tracing::field::debug(&my_struct));
+//! # }
+//! ```
+//!
+//! The `%` sigil operates similarly, but indicates that the value should be
+//! recorded using its [`fmt::Display`] implementation:
+//! ```
+//! # use tracing::{event, Level};
+//! # fn main() {
+//! # #[derive(Debug)]
+//! # struct MyStruct {
+//! # field: &'static str,
+//! # }
+//! #
+//! # let my_struct = MyStruct {
+//! # field: "Hello world!"
+//! # };
+//! // `my_struct.field` will be recorded using its `fmt::Display` implementation.
+//! event!(Level::TRACE, greeting = %my_struct.field);
+//! // is equivalent to:
+//! event!(Level::TRACE, greeting = tracing::field::display(&my_struct.field));
+//! # }
+//! ```
+//!
+//! The `%` and `?` sigils may also be used with local variable shorthand:
+//!
+//! ```
+//! # use tracing::{event, Level};
+//! # fn main() {
+//! # #[derive(Debug)]
+//! # struct MyStruct {
+//! # field: &'static str,
+//! # }
+//! #
+//! # let my_struct = MyStruct {
+//! # field: "Hello world!"
+//! # };
+//! // `my_struct.field` will be recorded using its `fmt::Display` implementation.
+//! event!(Level::TRACE, %my_struct.field);
+//! # }
+//! ```
+//!
+//! Additionally, a span may declare fields with the special value [`Empty`],
+//! which indicates that that the value for that field does not currently exist
+//! but may be recorded later. For example:
+//!
+//! ```
+//! use tracing::{trace_span, field};
+//!
+//! // Create a span with two fields: `greeting`, with the value "hello world", and
+//! // `parting`, without a value.
+//! let span = trace_span!("my_span", greeting = "hello world", parting = field::Empty);
+//!
+//! // ...
+//!
+//! // Now, record a value for parting as well.
+//! span.record("parting", &"goodbye world!");
+//! ```
+//!
+//! Note that a span may have up to 32 fields. The following will not compile:
+//!
+//! ```rust,compile_fail
+//! # use tracing::Level;
+//! # fn main() {
+//! let bad_span = span!(
+//! Level::TRACE,
+//! "too many fields!",
+//! a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, i = 9,
+//! j = 10, k = 11, l = 12, m = 13, n = 14, o = 15, p = 16, q = 17,
+//! r = 18, s = 19, t = 20, u = 21, v = 22, w = 23, x = 24, y = 25,
+//! z = 26, aa = 27, bb = 28, cc = 29, dd = 30, ee = 31, ff = 32, gg = 33
+//! );
+//! # }
+//! ```
+//!
+//! Finally, events may also include human-readable messages, in the form of a
+//! [format string][fmt] and (optional) arguments, **after** the event's
+//! key-value fields. If a format string and arguments are provided,
+//! they will implicitly create a new field named `message` whose value is the
+//! provided set of format arguments.
+//!
+//! For example:
+//!
+//! ```
+//! # use tracing::{event, Level};
+//! # fn main() {
+//! let question = "the answer to the ultimate question of life, the universe, and everything";
+//! let answer = 42;
+//! // records an event with the following fields:
+//! // - `question.answer` with the value 42,
+//! // - `question.tricky` with the value `true`,
+//! // - "message", with the value "the answer to the ultimate question of life, the
+//! // universe, and everything is 42."
+//! event!(
+//! Level::DEBUG,
+//! question.answer = answer,
+//! question.tricky = true,
+//! "the answer to {} is {}.", question, answer
+//! );
+//! # }
+//! ```
+//!
+//! Specifying a formatted message in this manner does not allocate by default.
+//!
+//! [struct initializers]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#using-the-field-init-shorthand-when-variables-and-fields-have-the-same-name
+//! [target]: struct.Metadata.html#method.target
+//! [parent span]: span/struct.Attributes.html#method.parent
+//! [determined contextually]: span/struct.Attributes.html#method.is_contextual
+//! [`fmt::Debug`]: https://doc.rust-lang.org/std/fmt/trait.Debug.html
+//! [`fmt::Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html
+//! [fmt]: https://doc.rust-lang.org/std/fmt/#usage
+//! [`Empty`]: field/struct.Empty.html
+//!
+//! ### Shorthand Macros
+//!
+//! `tracing` also offers a number of macros with preset verbosity levels.
+//! The [`trace!`], [`debug!`], [`info!`], [`warn!`], and [`error!`] behave
+//! similarly to the [`event!`] macro, but with the [`Level`] argument already
+//! specified, while the corresponding [`trace_span!`], [`debug_span!`],
+//! [`info_span!`], [`warn_span!`], and [`error_span!`] macros are the same,
+//! but for the [`span!`] macro.
+//!
+//! These are intended both as a shorthand, and for compatibility with the [`log`]
+//! crate (see the next section).
+//!
+//! [`span!`]: macro.span.html
+//! [`event!`]: macro.event.html
+//! [`trace!`]: macro.trace.html
+//! [`debug!`]: macro.debug.html
+//! [`info!`]: macro.info.html
+//! [`warn!`]: macro.warn.html
+//! [`error!`]: macro.error.html
+//! [`trace_span!`]: macro.trace_span.html
+//! [`debug_span!`]: macro.debug_span.html
+//! [`info_span!`]: macro.info_span.html
+//! [`warn_span!`]: macro.warn_span.html
+//! [`error_span!`]: macro.error_span.html
+//! [`Level`]: struct.Level.html
+//!
+//! ### For `log` Users
+//!
+//! Users of the [`log`] crate should note that `tracing` exposes a set of
+//! macros for creating `Event`s (`trace!`, `debug!`, `info!`, `warn!`, and
+//! `error!`) which may be invoked with the same syntax as the similarly-named
+//! macros from the `log` crate. Often, the process of converting a project to
+//! use `tracing` can begin with a simple drop-in replacement.
+//!
+//! Let's consider the `log` crate's yak-shaving example:
+//!
+//! ```rust,ignore
+//! use std::{error::Error, io};
+//! use tracing::{debug, error, info, span, warn, Level};
+//!
+//! // the `#[tracing::instrument]` attribute creates and enters a span
+//! // every time the instrumented function is called. The span is named after the
+//! // the function or method. Parameters passed to the function are recorded as fields.
+//! #[tracing::instrument]
+//! pub fn shave(yak: usize) -> Result<(), Box<dyn Error + 'static>> {
+//! // this creates an event at the DEBUG level with two fields:
+//! // - `excitement`, with the key "excitement" and the value "yay!"
+//! // - `message`, with the key "message" and the value "hello! I'm gonna shave a yak."
+//! //
+//! // unlike other fields, `message`'s shorthand initialization is just the string itself.
+//! debug!(excitement = "yay!", "hello! I'm gonna shave a yak.");
+//! if yak == 3 {
+//! warn!("could not locate yak!");
+//! // note that this is intended to demonstrate `tracing`'s features, not idiomatic
+//! // error handling! in a library or application, you should consider returning
+//! // a dedicated `YakError`. libraries like snafu or thiserror make this easy.
+//! return Err(io::Error::new(io::ErrorKind::Other, "shaving yak failed!").into());
+//! } else {
+//! debug!("yak shaved successfully");
+//! }
+//! Ok(())
+//! }
+//!
+//! pub fn shave_all(yaks: usize) -> usize {
+//! // Constructs a new span named "shaving_yaks" at the TRACE level,
+//! // and a field whose key is "yaks". This is equivalent to writing:
+//! //
+//! // let span = span!(Level::TRACE, "shaving_yaks", yaks = yaks);
+//! //
+//! // local variables (`yaks`) can be used as field values
+//! // without an assignment, similar to struct initializers.
+//! let span = span!(Level::TRACE, "shaving_yaks", yaks);
+//! let _enter = span.enter();
+//!
+//! info!("shaving yaks");
+//!
+//! let mut yaks_shaved = 0;
+//! for yak in 1..=yaks {
+//! let res = shave(yak);
+//! debug!(yak, shaved = res.is_ok());
+//!
+//! if let Err(ref error) = res {
+//! // Like spans, events can also use the field initialization shorthand.
+//! // In this instance, `yak` is the field being initalized.
+//! error!(yak, error = error.as_ref(), "failed to shave yak!");
+//! } else {
+//! yaks_shaved += 1;
+//! }
+//! debug!(yaks_shaved);
+//! }
+//!
+//! yaks_shaved
+//! }
+//! ```
+//!
+//! ## In libraries
+//!
+//! Libraries should link only to the `tracing` crate, and use the provided
+//! macros to record whatever information will be useful to downstream
+//! consumers.
+//!
+//! ## In executables
+//!
+//! In order to record trace events, executables have to use a `Subscriber`
+//! implementation compatible with `tracing`. A `Subscriber` implements a
+//! way of collecting trace data, such as by logging it to standard output.
+//!
+//! This library does not contain any `Subscriber` implementations; these are
+//! provided by [other crates](#related-crates).
+//!
+//! The simplest way to use a subscriber is to call the [`set_global_default`]
+//! function:
+//!
+//! ```
+//! extern crate tracing;
+//! # pub struct FooSubscriber;
+//! # use tracing::{span::{Id, Attributes, Record}, Metadata};
+//! # impl tracing::Subscriber for FooSubscriber {
+//! # fn new_span(&self, _: &Attributes) -> Id { Id::from_u64(0) }
+//! # fn record(&self, _: &Id, _: &Record) {}
+//! # fn event(&self, _: &tracing::Event) {}
+//! # fn record_follows_from(&self, _: &Id, _: &Id) {}
+//! # fn enabled(&self, _: &Metadata) -> bool { false }
+//! # fn enter(&self, _: &Id) {}
+//! # fn exit(&self, _: &Id) {}
+//! # }
+//! # impl FooSubscriber {
+//! # fn new() -> Self { FooSubscriber }
+//! # }
+//! # fn main() {
+//!
+//! let my_subscriber = FooSubscriber::new();
+//! tracing::subscriber::set_global_default(my_subscriber)
+//! .expect("setting tracing default failed");
+//! # }
+//! ```
+//!
+//! <div class="information">
+//! <div class="tooltip compile_fail" style="">&#x26a0; &#xfe0f;<span class="tooltiptext">Warning</span></div>
+//! </div><div class="example-wrap" style="display:inline-block"><pre class="compile_fail" style="white-space:normal;font:inherit;">
+//! <strong>Warning</strong>: In general, libraries should <em>not</em> call
+//! <code>set_global_default()</code>! Doing so will cause conflicts when
+//! executables that depend on the library try to set the default later.
+//! </pre></div>
+//!
+//! This subscriber will be used as the default in all threads for the
+//! remainder of the duration of the program, similar to setting the logger
+//! in the `log` crate.
+//!
+//! In addition, the default subscriber can be set through using the
+//! [`with_default`] function. This follows the `tokio` pattern of using
+//! closures to represent executing code in a context that is exited at the end
+//! of the closure. For example:
+//!
+//! ```rust
+//! # pub struct FooSubscriber;
+//! # use tracing::{span::{Id, Attributes, Record}, Metadata};
+//! # impl tracing::Subscriber for FooSubscriber {
+//! # fn new_span(&self, _: &Attributes) -> Id { Id::from_u64(0) }
+//! # fn record(&self, _: &Id, _: &Record) {}
+//! # fn event(&self, _: &tracing::Event) {}
+//! # fn record_follows_from(&self, _: &Id, _: &Id) {}
+//! # fn enabled(&self, _: &Metadata) -> bool { false }
+//! # fn enter(&self, _: &Id) {}
+//! # fn exit(&self, _: &Id) {}
+//! # }
+//! # impl FooSubscriber {
+//! # fn new() -> Self { FooSubscriber }
+//! # }
+//! # fn main() {
+//!
+//! let my_subscriber = FooSubscriber::new();
+//! # #[cfg(feature = "std")]
+//! tracing::subscriber::with_default(my_subscriber, || {
+//! // Any trace events generated in this closure or by functions it calls
+//! // will be collected by `my_subscriber`.
+//! })
+//! # }
+//! ```
+//!
+//! This approach allows trace data to be collected by multiple subscribers
+//! within different contexts in the program. Note that the override only applies to the
+//! currently executing thread; other threads will not see the change from with_default.
+//!
+//! Any trace events generated outside the context of a subscriber will not be collected.
+//!
+//! Once a subscriber has been set, instrumentation points may be added to the
+//! executable using the `tracing` crate's macros.
+//!
+//! ## `log` Compatibility
+//!
+//! The [`log`] crate provides a simple, lightweight logging facade for Rust.
+//! While `tracing` builds upon `log`'s foundation with richer structured
+//! diagnostic data, `log`'s simplicity and ubiquity make it the "lowest common
+//! denominator" for text-based logging in Rust — a vast majority of Rust
+//! libraries and applications either emit or consume `log` records. Therefore,
+//! `tracing` provides multiple forms of interoperability with `log`: `tracing`
+//! instrumentation can emit `log` records, and a compatibility layer enables
+//! `tracing` [`Subscriber`]s to consume `log` records as `tracing` [`Event`]s.
+//!
+//! ### Emitting `log` Records
+//!
+//! This crate provides two feature flags, "log" and "log-always", which will
+//! cause [spans] and [events] to emit `log` records. When the "log" feature is
+//! enabled, if no `tracing` `Subscriber` is active, invoking an event macro or
+//! creating a span with fields will emit a `log` record. This is intended
+//! primarily for use in libraries which wish to emit diagnostics that can be
+//! consumed by applications using `tracing` *or* `log`, without paying the
+//! additional overhead of emitting both forms of diagnostics when `tracing` is
+//! in use.
+//!
+//! Enabling the "log-always" feature will cause `log` records to be emitted
+//! even if a `tracing` `Subscriber` _is_ set. This is intended to be used in
+//! applications where a `log` `Logger` is being used to record a textual log,
+//! and `tracing` is used only to record other forms of diagnostics (such as
+//! metrics, profiling, or distributed tracing data). Unlike the "log" feature,
+//! libraries generally should **not** enable the "log-always" feature, as doing
+//! so will prevent applications from being able to opt out of the `log` records.
+//!
+//! See [here][flags] for more details on this crate's feature flags.
+//!
+//! The generated `log` records' messages will be a string representation of the
+//! span or event's fields, and all additional information recorded by `log`
+//! (target, verbosity level, module path, file, and line number) will also be
+//! populated. Additionally, `log` records are also generated when spans are
+//! entered, exited, and closed. Since these additional span lifecycle logs have
+//! the potential to be very verbose, and don't include additional fields, they
+//! will always be emitted at the `Trace` level, rather than inheriting the
+//! level of the span that generated them. Furthermore, they are are categorized
+//! under a separate `log` target, "tracing::span" (and its sub-target,
+//! "tracing::span::active", for the logs on entering and exiting a span), which
+//! may be enabled or disabled separately from other `log` records emitted by
+//! `tracing`.
+//!
+//! ### Consuming `log` Records
+//!
+//! The [`tracing-log`] crate provides a compatibility layer which
+//! allows a `tracing` [`Subscriber`] to consume `log` records as though they
+//! were `tracing` [events]. This allows applications using `tracing` to record
+//! the logs emitted by dependencies using `log` as events within the context of
+//! the application's trace tree. See [that crate's documentation][log-tracer]
+//! for details.
+//!
+//! [log-tracer]: https://docs.rs/tracing-log/latest/tracing_log/#convert-log-records-to-tracing-events
+//!
+//! ## Related Crates
+//!
+//! In addition to `tracing` and `tracing-core`, the [`tokio-rs/tracing`] repository
+//! contains several additional crates designed to be used with the `tracing` ecosystem.
+//! This includes a collection of `Subscriber` implementations, as well as utility
+//! and adapter crates to assist in writing `Subscriber`s and instrumenting
+//! applications.
+//!
+//! In particular, the following crates are likely to be of interest:
+//!
+//! - [`tracing-futures`] provides a compatibility layer with the `futures`
+//! crate, allowing spans to be attached to `Future`s, `Stream`s, and `Executor`s.
+//! - [`tracing-subscriber`] provides `Subscriber` implementations and
+//! utilities for working with `Subscriber`s. This includes a [`FmtSubscriber`]
+//! `FmtSubscriber` for logging formatted trace data to stdout, with similar
+//! filtering and formatting to the [`env_logger`] crate.
+//! - [`tracing-log`] provides a compatibility layer with the [`log`] crate,
+//! allowing log messages to be recorded as `tracing` `Event`s within the
+//! trace tree. This is useful when a project using `tracing` have
+//! dependencies which use `log`. Note that if you're using
+//! `tracing-subscriber`'s `FmtSubscriber`, you don't need to depend on
+//! `tracing-log` directly.
+//! - [`tracing-appender`] provides utilities for outputting tracing data,
+//! including a file appender and non blocking writer.
+//!
+//! Additionally, there are also several third-party crates which are not
+//! maintained by the `tokio` project. These include:
+//!
+//! - [`tracing-timing`] implements inter-event timing metrics on top of `tracing`.
+//! It provides a subscriber that records the time elapsed between pairs of
+//! `tracing` events and generates histograms.
+//! - [`tracing-opentelemetry`] provides a subscriber for emitting traces to
+//! [OpenTelemetry]-compatible distributed tracing systems.
+//! - [`tracing-honeycomb`] Provides a layer that reports traces spanning multiple machines to [honeycomb.io]. Backed by [`tracing-distributed`].
+//! - [`tracing-distributed`] Provides a generic implementation of a layer that reports traces spanning multiple machines to some backend.
+//! - [`tracing-actix`] provides `tracing` integration for the `actix` actor
+//! framework.
+//! - [`tracing-gelf`] implements a subscriber for exporting traces in Greylog
+//! GELF format.
+//! - [`tracing-coz`] provides integration with the [coz] causal profiler
+//! (Linux-only).
+//! - [`tracing-bunyan-formatter`] provides a layer implementation that reports events and spans
+//! in [bunyan] format, enriched with timing information.
+//! - [`tracing-wasm`] provides a `Subscriber`/`Layer` implementation that reports
+//! events and spans via browser `console.log` and [User Timing API (`window.performance`)].
+//! - [`tide-tracing`] provides a [tide] middleware to trace all incoming requests and responses.
+//! - [`test-env-log`] takes care of initializing `tracing` for tests, based on
+//! environment variables with an `env_logger` compatible syntax.
+//! - [`tracing-unwrap`] provides convenience methods to report failed unwraps
+//! on `Result` or `Option` types to a `Subscriber`.
+//! - [`diesel-tracing`] provides integration with [`diesel`] database connections.
+//! - [`tracing-tracy`] provides a way to collect [Tracy] profiles in instrumented
+//! applications.
+//!
+//! If you're the maintainer of a `tracing` ecosystem crate not listed above,
+//! please let us know! We'd love to add your project to the list!
+//!
+//! [`tracing-opentelemetry`]: https://crates.io/crates/tracing-opentelemetry
+//! [OpenTelemetry]: https://opentelemetry.io/
+//! [`tracing-honeycomb`]: https://crates.io/crates/tracing-honeycomb
+//! [`tracing-distributed`]: https://crates.io/crates/tracing-distributed
+//! [honeycomb.io]: https://www.honeycomb.io/
+//! [`tracing-actix`]: https://crates.io/crates/tracing-actix
+//! [`tracing-gelf`]: https://crates.io/crates/tracing-gelf
+//! [`tracing-coz`]: https://crates.io/crates/tracing-coz
+//! [coz]: https://github.com/plasma-umass/coz
+//! [`tracing-bunyan-formatter`]: https://crates.io/crates/tracing-bunyan-formatter
+//! [bunyan]: https://github.com/trentm/node-bunyan
+//! [`tracing-wasm`]: https://docs.rs/tracing-wasm
+//! [User Timing API (`window.performance`)]: https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API
+//! [`tide-tracing`]: https://crates.io/crates/tide-tracing
+//! [tide]: https://crates.io/crates/tide
+//! [`test-env-log`]: https://crates.io/crates/test-env-log
+//! [`tracing-unwrap`]: https://docs.rs/tracing-unwrap
+//! [`diesel`]: https://crates.io/crates/diesel
+//! [`diesel-tracing`]: https://crates.io/crates/diesel-tracing
+//! [`tracing-tracy`]: https://crates.io/crates/tracing-tracy
+//! [Tracy]: https://github.com/wolfpld/tracy
+//!
+//! <div class="information">
+//! <div class="tooltip ignore" style="">ⓘ<span class="tooltiptext">Note</span></div>
+//! </div>
+//! <div class="example-wrap" style="display:inline-block">
+//! <pre class="ignore" style="white-space:normal;font:inherit;">
+//! <strong>Note</strong>: Some of these ecosystem crates are currently
+//! unreleased and/or in earlier stages of development. They may be less stable
+//! than <code>tracing</code> and <code>tracing-core</code>.
+//! </pre></div>
+//!
+//! ## Crate Feature Flags
+//!
+//! The following crate feature flags are available:
+//!
+//! * A set of features controlling the [static verbosity level].
+//! * `log`: causes trace instrumentation points to emit [`log`] records as well
+//! as trace events, if a default `tracing` subscriber has not been set. This
+//! is intended for use in libraries whose users may be using either `tracing`
+//! or `log`.
+//! * `log-always`: Emit `log` records from all `tracing` spans and events, even
+//! if a `tracing` subscriber has been set. This should be set only by
+//! applications which intend to collect traces and logs separately; if an
+//! adapter is used to convert `log` records into `tracing` events, this will
+//! cause duplicate events to occur.
+//! * `attributes`: Includes support for the `#[instrument]` attribute.
+//! This is on by default, but does bring in the `syn` crate as a dependency,
+//! which may add to the compile time of crates that do not already use it.
+//! * `std`: Depend on the Rust standard library (enabled by default).
+//!
+//! `no_std` users may disable this feature with `default-features = false`:
+//!
+//! ```toml
+//! [dependencies]
+//! tracing = { version = "0.1.21", default-features = false }
+//! ```
+//!
+//! <div class="information">
+//! <div class="tooltip ignore" style="">ⓘ<span class="tooltiptext">Note</span></div>
+//! </div>
+//! <div class="example-wrap" style="display:inline-block">
+//! <pre class="ignore" style="white-space:normal;font:inherit;">
+//! <strong>Note</strong>: <code>tracing</code>'s <code>no_std</code> support
+//! requires <code>liballoc</code>.
+//! </pre></div>
+//!
+//! ## Supported Rust Versions
+//!
+//! Tracing is built against the latest stable release. The minimum supported
+//! version is 1.40. The current Tracing version is not guaranteed to build on
+//! Rust versions earlier than the minimum supported version.
+//!
+//! Tracing follows the same compiler support policies as the rest of the Tokio
+//! project. The current stable Rust compiler and the three most recent minor
+//! versions before it will always be supported. For example, if the current
+//! stable compiler version is 1.45, the minimum supported version will not be
+//! increased past 1.42, three minor versions prior. Increasing the minimum
+//! supported compiler version is not considered a semver breaking change as
+//! long as doing so complies with this policy.
+//!
+//! [`log`]: https://docs.rs/log/0.4.6/log/
+//! [span]: mod@span
+//! [spans]: mod@span
+//! [`Span`]: span::Span
+//! [`in_scope`]: span::Span::in_scope
+//! [event]: Event
+//! [events]: Event
+//! [`Subscriber`]: subscriber::Subscriber
+//! [Subscriber::event]: subscriber::Subscriber::event
+//! [`enter`]: subscriber::Subscriber::enter
+//! [`exit`]: subscriber::Subscriber::exit
+//! [`enabled`]: subscriber::Subscriber::enabled
+//! [metadata]: Metadata
+//! [`field::display`]: field::display
+//! [`field::debug`]: field::debug
+//! [`set_global_default`]: subscriber::set_global_default
+//! [`with_default`]: subscriber::with_default
+//! [`tokio-rs/tracing`]: https://github.com/tokio-rs/tracing
+//! [`tracing-futures`]: https://crates.io/crates/tracing-futures
+//! [`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber
+//! [`tracing-log`]: https://crates.io/crates/tracing-log
+//! [`tracing-timing`]: https://crates.io/crates/tracing-timing
+//! [`tracing-appender`]: https://crates.io/crates/tracing-appender
+//! [`env_logger`]: https://crates.io/crates/env_logger
+//! [`FmtSubscriber`]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Subscriber.html
+//! [static verbosity level]: level_filters/index.html#compile-time-filters
+//! [instrument]: https://docs.rs/tracing-attributes/latest/tracing_attributes/attr.instrument.html
+//! [flags]: #crate-feature-flags
+#![cfg_attr(not(feature = "std"), no_std)]
+#![cfg_attr(docsrs, feature(doc_cfg), deny(broken_intra_doc_links))]
+#![doc(html_root_url = "https://docs.rs/tracing/0.1.21")]
+#![doc(
+ html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
+ issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/"
+)]
+#![warn(
+ missing_debug_implementations,
+ missing_docs,
+ rust_2018_idioms,
+ unreachable_pub,
+ bad_style,
+ const_err,
+ dead_code,
+ improper_ctypes,
+ non_shorthand_field_patterns,
+ no_mangle_generic_items,
+ overflowing_literals,
+ path_statements,
+ patterns_in_fns_without_body,
+ private_in_public,
+ unconditional_recursion,
+ unused,
+ unused_allocation,
+ unused_comparisons,
+ unused_parens,
+ while_true
+)]
+
+#[cfg(not(feature = "std"))]
+extern crate alloc;
+
+#[macro_use]
+extern crate cfg_if;
+
+#[cfg(feature = "log")]
+#[doc(hidden)]
+pub use log;
+
+// Somehow this `use` statement is necessary for us to re-export the `core`
+// macros on Rust 1.26.0. I'm not sure how this makes it work, but it does.
+#[allow(unused_imports)]
+#[doc(hidden)]
+use tracing_core::*;
+
+#[doc(inline)]
+pub use self::instrument::Instrument;
+pub use self::{dispatcher::Dispatch, event::Event, field::Value, subscriber::Subscriber};
+
+#[doc(hidden)]
+pub use self::span::Id;
+
+#[doc(hidden)]
+pub use tracing_core::{
+ callsite::{self, Callsite},
+ metadata,
+};
+pub use tracing_core::{event, Level, Metadata};
+
+#[doc(inline)]
+pub use self::span::Span;
+#[cfg(feature = "attributes")]
+#[cfg_attr(docsrs, doc(cfg(feature = "attributes")))]
+#[doc(inline)]
+pub use tracing_attributes::instrument;
+
+#[macro_use]
+mod macros;
+
+pub mod dispatcher;
+pub mod field;
+/// Attach a span to a `std::future::Future`.
+pub mod instrument;
+pub mod level_filters;
+pub mod span;
+pub(crate) mod stdlib;
+pub mod subscriber;
+
+#[doc(hidden)]
+pub mod __macro_support {
+ pub use crate::callsite::Callsite;
+ use crate::stdlib::sync::atomic::{AtomicUsize, Ordering};
+ use crate::{subscriber::Interest, Metadata};
+ use tracing_core::Once;
+
+ /// Callsite implementation used by macro-generated code.
+ ///
+ /// /!\ WARNING: This is *not* a stable API! /!\
+ /// This type, and all code contained in the `__macro_support` module, is
+ /// a *private* API of `tracing`. It is exposed publicly because it is used
+ /// by the `tracing` macros, but it is not part of the stable versioned API.
+ /// Breaking changes to this module may occur in small-numbered versions
+ /// without warning.
+ #[derive(Debug)]
+ pub struct MacroCallsite {
+ interest: AtomicUsize,
+ meta: &'static Metadata<'static>,
+ registration: Once,
+ }
+
+ impl MacroCallsite {
+ /// Returns a new `MacroCallsite` with the specified `Metadata`.
+ ///
+ /// /!\ WARNING: This is *not* a stable API! /!\
+ /// This method, and all code contained in the `__macro_support` module, is
+ /// a *private* API of `tracing`. It is exposed publicly because it is used
+ /// by the `tracing` macros, but it is not part of the stable versioned API.
+ /// Breaking changes to this module may occur in small-numbered versions
+ /// without warning.
+ pub const fn new(meta: &'static Metadata<'static>) -> Self {
+ Self {
+ interest: AtomicUsize::new(0xDEADFACED),
+ meta,
+ registration: Once::new(),
+ }
+ }
+
+ /// Registers this callsite with the global callsite registry.
+ ///
+ /// If the callsite is already registered, this does nothing.
+ ///
+ /// /!\ WARNING: This is *not* a stable API! /!\
+ /// This method, and all code contained in the `__macro_support` module, is
+ /// a *private* API of `tracing`. It is exposed publicly because it is used
+ /// by the `tracing` macros, but it is not part of the stable versioned API.
+ /// Breaking changes to this module may occur in small-numbered versions
+ /// without warning.
+ #[inline(never)]
+ // This only happens once (or if the cached interest value was corrupted).
+ #[cold]
+ pub fn register(&'static self) -> Interest {
+ self.registration
+ .call_once(|| crate::callsite::register(self));
+ match self.interest.load(Ordering::Relaxed) {
+ 0 => Interest::never(),
+ 2 => Interest::always(),
+ _ => Interest::sometimes(),
+ }
+ }
+
+ /// Returns the callsite's cached Interest, or registers it for the
+ /// first time if it has not yet been registered.
+ ///
+ /// /!\ WARNING: This is *not* a stable API! /!\
+ /// This method, and all code contained in the `__macro_support` module, is
+ /// a *private* API of `tracing`. It is exposed publicly because it is used
+ /// by the `tracing` macros, but it is not part of the stable versioned API.
+ /// Breaking changes to this module may occur in small-numbered versions
+ /// without warning.
+ #[inline]
+ pub fn interest(&'static self) -> Interest {
+ match self.interest.load(Ordering::Relaxed) {
+ 0 => Interest::never(),
+ 1 => Interest::sometimes(),
+ 2 => Interest::always(),
+ _ => self.register(),
+ }
+ }
+
+ pub fn is_enabled(&self, interest: Interest) -> bool {
+ interest.is_always()
+ || crate::dispatcher::get_default(|default| default.enabled(self.meta))
+ }
+
+ #[inline]
+ #[cfg(feature = "log")]
+ pub fn disabled_span(&self) -> crate::Span {
+ crate::Span::new_disabled(self.meta)
+ }
+
+ #[inline]
+ #[cfg(not(feature = "log"))]
+ pub fn disabled_span(&self) -> crate::Span {
+ crate::Span::none()
+ }
+ }
+
+ impl Callsite for MacroCallsite {
+ fn set_interest(&self, interest: Interest) {
+ let interest = match () {
+ _ if interest.is_never() => 0,
+ _ if interest.is_always() => 2,
+ _ => 1,
+ };
+ self.interest.store(interest, Ordering::SeqCst);
+ }
+
+ #[inline(always)]
+ fn metadata(&self) -> &Metadata<'static> {
+ &self.meta
+ }
+ }
+}
+
+mod sealed {
+ pub trait Sealed {}
+}
diff --git a/third_party/rust/tracing/src/macros.rs b/third_party/rust/tracing/src/macros.rs
new file mode 100644
index 0000000000..3222abb741
--- /dev/null
+++ b/third_party/rust/tracing/src/macros.rs
@@ -0,0 +1,2369 @@
+/// Constructs a new span.
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// Creating a new span:
+/// ```
+/// # use tracing::{span, Level};
+/// # fn main() {
+/// let span = span!(Level::TRACE, "my span");
+/// let _enter = span.enter();
+/// // do work inside the span...
+/// # }
+/// ```
+#[macro_export]
+macro_rules! span {
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => {
+ $crate::span!(target: $target, parent: $parent, $lvl, $name,)
+ };
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => {
+ {
+ use $crate::__macro_support::Callsite as _;
+ static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
+ name: $name,
+ kind: $crate::metadata::Kind::SPAN,
+ target: $target,
+ level: $lvl,
+ fields: $($fields)*
+ };
+ let mut interest = $crate::subscriber::Interest::never();
+ if $crate::level_enabled!($lvl)
+ && { interest = CALLSITE.interest(); !interest.is_never() }
+ && CALLSITE.is_enabled(interest)
+ {
+ let meta = CALLSITE.metadata();
+ // span with explicit parent
+ $crate::Span::child_of(
+ $parent,
+ meta,
+ &$crate::valueset!(meta.fields(), $($fields)*),
+ )
+ } else {
+ let span = CALLSITE.disabled_span();
+ $crate::if_log_enabled! {{
+ span.record_all(&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*));
+ }};
+ span
+ }
+ }
+ };
+ (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => {
+ {
+ use $crate::__macro_support::Callsite as _;
+ static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
+ name: $name,
+ kind: $crate::metadata::Kind::SPAN,
+ target: $target,
+ level: $lvl,
+ fields: $($fields)*
+ };
+ let mut interest = $crate::subscriber::Interest::never();
+ if $crate::level_enabled!($lvl)
+ && { interest = CALLSITE.interest(); !interest.is_never() }
+ && CALLSITE.is_enabled(interest)
+ {
+ let meta = CALLSITE.metadata();
+ // span with contextual parent
+ $crate::Span::new(
+ meta,
+ &$crate::valueset!(meta.fields(), $($fields)*),
+ )
+ } else {
+ let span = CALLSITE.disabled_span();
+ $crate::if_log_enabled! {{
+ span.record_all(&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*));
+ }};
+ span
+ }
+ }
+ };
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => {
+ $crate::span!(target: $target, parent: $parent, $lvl, $name,)
+ };
+ (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ $name,
+ $($fields)*
+ )
+ };
+ (parent: $parent:expr, $lvl:expr, $name:expr) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ $name,
+ )
+ };
+ (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => {
+ $crate::span!(
+ target: $target,
+ $lvl,
+ $name,
+ $($fields)*
+ )
+ };
+ (target: $target:expr, $lvl:expr, $name:expr) => {
+ $crate::span!(target: $target, $lvl, $name,)
+ };
+ ($lvl:expr, $name:expr, $($fields:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ $lvl,
+ $name,
+ $($fields)*
+ )
+ };
+ ($lvl:expr, $name:expr) => {
+ $crate::span!(
+ target: module_path!(),
+ $lvl,
+ $name,
+ )
+ };
+}
+
+/// Constructs a span at the trace level.
+///
+/// [Fields] and [attributes] are set using the same syntax as the [`span!`]
+/// macro.
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+/// [attributes]: index.html#configuring-attributes
+/// [Fields]: index.html#recording-fields
+/// [`span!`]: macro.span.html
+///
+/// # Examples
+///
+/// ```rust
+/// # use tracing::{trace_span, span, Level};
+/// # fn main() {
+/// trace_span!("my_span");
+/// // is equivalent to:
+/// span!(Level::TRACE, "my_span");
+/// # }
+/// ```
+///
+/// ```rust
+/// # use tracing::{trace_span, span, Level};
+/// # fn main() {
+/// let span = trace_span!("my span");
+/// span.in_scope(|| {
+/// // do work inside the span...
+/// });
+/// # }
+/// ```
+#[macro_export]
+macro_rules! trace_span {
+ (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ parent: $parent,
+ $crate::Level::TRACE,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, parent: $parent:expr, $name:expr) => {
+ $crate::trace_span!(target: $target, parent: $parent, $name,)
+ };
+ (parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ $name,
+ $($field)*
+ )
+ };
+ (parent: $parent:expr, $name:expr) => {
+ $crate::trace_span!(parent: $parent, $name,)
+ };
+ (target: $target:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ $crate::Level::TRACE,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, $name:expr) => {
+ $crate::trace_span!(target: $target, $name,)
+ };
+ ($name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ $name,
+ $($field)*
+ )
+ };
+ ($name:expr) => { $crate::trace_span!($name,) };
+}
+
+/// Constructs a span at the debug level.
+///
+/// [Fields] and [attributes] are set using the same syntax as the [`span!`]
+/// macro.
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+/// [attributes]: index.html#configuring-attributes
+/// [Fields]: index.html#recording-fields
+/// [`span!`]: macro.span.html
+///
+/// # Examples
+///
+/// ```rust
+/// # use tracing::{debug_span, span, Level};
+/// # fn main() {
+/// debug_span!("my_span");
+/// // is equivalent to:
+/// span!(Level::DEBUG, "my_span");
+/// # }
+/// ```
+///
+/// ```rust
+/// # use tracing::debug_span;
+/// # fn main() {
+/// let span = debug_span!("my span");
+/// span.in_scope(|| {
+/// // do work inside the span...
+/// });
+/// # }
+/// ```
+#[macro_export]
+macro_rules! debug_span {
+ (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ parent: $parent,
+ $crate::Level::DEBUG,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, parent: $parent:expr, $name:expr) => {
+ $crate::debug_span!(target: $target, parent: $parent, $name,)
+ };
+ (parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ $name,
+ $($field)*
+ )
+ };
+ (parent: $parent:expr, $name:expr) => {
+ $crate::debug_span!(parent: $parent, $name,)
+ };
+ (target: $target:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ $crate::Level::DEBUG,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, $name:expr) => {
+ $crate::debug_span!(target: $target, $name,)
+ };
+ ($name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ $name,
+ $($field)*
+ )
+ };
+ ($name:expr) => {$crate::debug_span!($name,)};
+}
+
+/// Constructs a span at the info level.
+///
+/// [Fields] and [attributes] are set using the same syntax as the [`span!`]
+/// macro.
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+/// [attributes]: index.html#configuring-attributes
+/// [Fields]: index.html#recording-fields
+/// [`span!`]: macro.span.html
+///
+/// # Examples
+///
+/// ```rust
+/// # use tracing::{span, info_span, Level};
+/// # fn main() {
+/// info_span!("my_span");
+/// // is equivalent to:
+/// span!(Level::INFO, "my_span");
+/// # }
+/// ```
+///
+/// ```rust
+/// # use tracing::info_span;
+/// # fn main() {
+/// let span = info_span!("my span");
+/// span.in_scope(|| {
+/// // do work inside the span...
+/// });
+/// # }
+/// ```
+#[macro_export]
+macro_rules! info_span {
+ (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ parent: $parent,
+ $crate::Level::INFO,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, parent: $parent:expr, $name:expr) => {
+ $crate::info_span!(target: $target, parent: $parent, $name,)
+ };
+ (parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ $name,
+ $($field)*
+ )
+ };
+ (parent: $parent:expr, $name:expr) => {
+ $crate::info_span!(parent: $parent, $name,)
+ };
+ (target: $target:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ $crate::Level::INFO,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, $name:expr) => {
+ $crate::info_span!(target: $target, $name,)
+ };
+ ($name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ $name,
+ $($field)*
+ )
+ };
+ ($name:expr) => {$crate::info_span!($name,)};
+}
+
+/// Constructs a span at the warn level.
+///
+/// [Fields] and [attributes] are set using the same syntax as the [`span!`]
+/// macro.
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+/// [attributes]: index.html#configuring-attributes
+/// [Fields]: index.html#recording-fields
+/// [`span!`]: macro.span.html
+///
+/// # Examples
+///
+/// ```rust
+/// # use tracing::{warn_span, span, Level};
+/// # fn main() {
+/// warn_span!("my_span");
+/// // is equivalent to:
+/// span!(Level::WARN, "my_span");
+/// # }
+/// ```
+///
+/// ```rust
+/// use tracing::warn_span;
+/// # fn main() {
+/// let span = warn_span!("my span");
+/// span.in_scope(|| {
+/// // do work inside the span...
+/// });
+/// # }
+/// ```
+#[macro_export]
+macro_rules! warn_span {
+ (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ parent: $parent,
+ $crate::Level::WARN,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, parent: $parent:expr, $name:expr) => {
+ $crate::warn_span!(target: $target, parent: $parent, $name,)
+ };
+ (parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ $name,
+ $($field)*
+ )
+ };
+ (parent: $parent:expr, $name:expr) => {
+ $crate::warn_span!(parent: $parent, $name,)
+ };
+ (target: $target:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ $crate::Level::WARN,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, $name:expr) => {
+ $crate::warn_span!(target: $target, $name,)
+ };
+ ($name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ $name,
+ $($field)*
+ )
+ };
+ ($name:expr) => {$crate::warn_span!($name,)};
+}
+/// Constructs a span at the error level.
+///
+/// [Fields] and [attributes] are set using the same syntax as the [`span!`]
+/// macro.
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+/// [attributes]: index.html#configuring-attributes
+/// [Fields]: index.html#recording-fields
+/// [`span!`]: macro.span.html
+///
+/// # Examples
+///
+/// ```rust
+/// # use tracing::{span, error_span, Level};
+/// # fn main() {
+/// error_span!("my_span");
+/// // is equivalent to:
+/// span!(Level::ERROR, "my_span");
+/// # }
+/// ```
+///
+/// ```rust
+/// # use tracing::error_span;
+/// # fn main() {
+/// let span = error_span!("my span");
+/// span.in_scope(|| {
+/// // do work inside the span...
+/// });
+/// # }
+/// ```
+#[macro_export]
+macro_rules! error_span {
+ (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ parent: $parent,
+ $crate::Level::ERROR,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, parent: $parent:expr, $name:expr) => {
+ $crate::error_span!(target: $target, parent: $parent, $name,)
+ };
+ (parent: $parent:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ $name,
+ $($field)*
+ )
+ };
+ (parent: $parent:expr, $name:expr) => {
+ $crate::error_span!(parent: $parent, $name,)
+ };
+ (target: $target:expr, $name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: $target,
+ $crate::Level::ERROR,
+ $name,
+ $($field)*
+ )
+ };
+ (target: $target:expr, $name:expr) => {
+ $crate::error_span!(target: $target, $name,)
+ };
+ ($name:expr, $($field:tt)*) => {
+ $crate::span!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ $name,
+ $($field)*
+ )
+ };
+ ($name:expr) => {$crate::error_span!($name,)};
+}
+
+/// Constructs a new `Event`.
+///
+/// The event macro is invoked with a `Level` and up to 32 key-value fields.
+/// Optionally, a format string and arguments may follow the fields; this will
+/// be used to construct an implicit field named "message".
+///
+/// See [the top-level documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// ```rust
+/// use tracing::{event, Level};
+///
+/// # fn main() {
+/// let data = (42, "forty-two");
+/// let private_data = "private";
+/// let error = "a bad error";
+///
+/// event!(Level::ERROR, %error, "Received error");
+/// event!(
+/// target: "app_events",
+/// Level::WARN,
+/// private_data,
+/// ?data,
+/// "App warning: {}",
+/// error
+/// );
+/// event!(Level::INFO, the_answer = data.0);
+/// # }
+/// ```
+///
+// /// Note that *unlike `span!`*, `event!` requires a value for all fields. As
+// /// events are recorded immediately when the macro is invoked, there is no
+// /// opportunity for fields to be recorded later. A trailing comma on the final
+// /// field is valid.
+// ///
+// /// For example, the following does not compile:
+// /// ```rust,compile_fail
+// /// # #[macro_use]
+// /// # extern crate tracing;
+// /// # use tracing::Level;
+// /// # fn main() {
+// /// event!(Level::INFO, foo = 5, bad_field, bar = "hello")
+// /// #}
+// /// ```
+#[macro_export]
+macro_rules! event {
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
+ $crate::__tracing_log!(
+ target: $target,
+ $lvl,
+ $($fields)*
+ );
+
+ if $crate::level_enabled!($lvl) {
+ use $crate::__macro_support::*;
+ static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
+ name: concat!(
+ "event ",
+ file!(),
+ ":",
+ line!()
+ ),
+ kind: $crate::metadata::Kind::EVENT,
+ target: $target,
+ level: $lvl,
+ fields: $($fields)*
+ };
+ let interest = CALLSITE.interest();
+ if !interest.is_never() && CALLSITE.is_enabled(interest) {
+ let meta = CALLSITE.metadata();
+ // event with explicit parent
+ $crate::Event::child_of(
+ $parent,
+ meta,
+ &$crate::valueset!(meta.fields(), $($fields)*)
+ );
+ }
+ }
+ );
+
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: $target,
+ parent: $parent,
+ $lvl,
+ { message = format_args!($($arg)+), $($fields)* }
+ )
+ );
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
+ $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* })
+ );
+ (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => (
+ $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ })
+ );
+ (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({
+ $crate::__tracing_log!(
+ target: $target,
+ $lvl,
+ $($fields)*
+ );
+ if $crate::level_enabled!($lvl) {
+ use $crate::__macro_support::*;
+ static CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
+ name: concat!(
+ "event ",
+ file!(),
+ ":",
+ line!()
+ ),
+ kind: $crate::metadata::Kind::EVENT,
+ target: $target,
+ level: $lvl,
+ fields: $($fields)*
+ };
+ let interest = CALLSITE.interest();
+ if !interest.is_never() && CALLSITE.is_enabled(interest) {
+ let meta = CALLSITE.metadata();
+ // event with contextual parent
+ $crate::Event::dispatch(
+ meta,
+ &$crate::valueset!(meta.fields(), $($fields)*)
+ );
+ }
+ }
+ });
+ (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: $target,
+ $lvl,
+ { message = format_args!($($arg)+), $($fields)* }
+ )
+ );
+ (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
+ $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* })
+ );
+ (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, $lvl, { $($arg)+ })
+ );
+ (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { message = format_args!($($arg)+), $($fields)* }
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ parent: $parent,
+ { message = format_args!($($arg)+), $($fields)* }
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { $($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $lvl,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ })
+ );
+ ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ { message = format_args!($($arg)+), $($fields)* }
+ )
+ );
+ ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ { message = format_args!($($arg)+), $($fields)* }
+ )
+ );
+ ($lvl:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ { $($k).+ = $($field)*}
+ )
+ );
+ ($lvl:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ { $($k).+, $($field)*}
+ )
+ );
+ ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ ($lvl:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $lvl,
+ { %$($k).+, $($field)*}
+ )
+ );
+ ($lvl:expr, ?$($k:ident).+) => (
+ $crate::event!($lvl, ?$($k).+,)
+ );
+ ($lvl:expr, %$($k:ident).+) => (
+ $crate::event!($lvl, %$($k).+,)
+ );
+ ($lvl:expr, $($k:ident).+) => (
+ $crate::event!($lvl, $($k).+,)
+ );
+ ( $lvl:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: module_path!(), $lvl, { $($arg)+ })
+ );
+}
+
+/// Constructs an event at the trace level.
+///
+/// This functions similarly to the [`event!`] macro. See [the top-level
+/// documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [`event!`]: macro.event.html
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// ```rust
+/// use tracing::trace;
+/// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 }
+/// # impl Position {
+/// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 };
+/// # fn dist(&self, other: Position) -> f32 {
+/// # let x = (other.x - self.x).exp2(); let y = (self.y - other.y).exp2();
+/// # (x + y).sqrt()
+/// # }
+/// # }
+/// # fn main() {
+/// let pos = Position { x: 3.234, y: -1.223 };
+/// let origin_dist = pos.dist(Position::ORIGIN);
+///
+/// trace!(position = ?pos, ?origin_dist);
+/// trace!(
+/// target: "app_events",
+/// position = ?pos,
+/// "x is {} and y is {}",
+/// if pos.x >= 0.0 { "positive" } else { "negative" },
+/// if pos.y >= 0.0 { "positive" } else { "negative" }
+/// );
+/// # }
+/// ```
+#[macro_export]
+macro_rules! trace {
+ (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+)
+ );
+ (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { $($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::TRACE,
+ {},
+ $($arg)+
+ )
+ );
+ (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+)
+ );
+ ({ $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ ($($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { $($k).+ = $($field)*}
+ )
+ );
+ ($($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { $($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (%$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { ?$($k).+ }
+ )
+ );
+ (%$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { %$($k).+ }
+ )
+ );
+ ($($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { $($k).+ }
+ )
+ );
+ ($($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ {},
+ $($arg)+
+ )
+ );
+}
+
+/// Constructs an event at the debug level.
+///
+/// This functions similarly to the [`event!`] macro. See [the top-level
+/// documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [`event!`]: macro.event.html
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// ```rust
+/// use tracing::debug;
+/// # fn main() {
+/// # #[derive(Debug)] struct Position { x: f32, y: f32 }
+///
+/// let pos = Position { x: 3.234, y: -1.223 };
+///
+/// debug!(?pos.x, ?pos.y);
+/// debug!(target: "app_events", position = ?pos, "New position");
+/// # }
+/// ```
+#[macro_export]
+macro_rules! debug {
+ (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+)
+ );
+ (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { $($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::DEBUG,
+ {},
+ $($arg)+
+ )
+ );
+ (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+)
+ );
+ ({ $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ ($($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (%$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ ($($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { $($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (%$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { ?$($k).+ }
+ )
+ );
+ (%$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { %$($k).+ }
+ )
+ );
+ ($($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ { $($k).+ }
+ )
+ );
+ ($($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::DEBUG,
+ {},
+ $($arg)+
+ )
+ );
+}
+
+/// Constructs an event at the info level.
+///
+/// This functions similarly to the [`event!`] macro. See [the top-level
+/// documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [`event!`]: macro.event.html
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// ```rust
+/// use tracing::info;
+/// # // this is so the test will still work in no-std mode
+/// # #[derive(Debug)]
+/// # pub struct Ipv4Addr;
+/// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } }
+/// # fn main() {
+/// # struct Connection { port: u32, speed: f32 }
+/// use tracing::field;
+///
+/// let addr = Ipv4Addr::new(127, 0, 0, 1);
+/// let conn = Connection { port: 40, speed: 3.20 };
+///
+/// info!(conn.port, "connected to {:?}", addr);
+/// info!(
+/// target: "connection_events",
+/// ip = ?addr,
+/// conn.port,
+/// ?conn.speed,
+/// );
+/// # }
+/// ```
+#[macro_export]
+macro_rules! info {
+ (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+)
+ );
+ (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { $($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::INFO,
+ {},
+ $($arg)+
+ )
+ );
+ (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+)
+ );
+ ({ $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ ($($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (%$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ ($($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { $($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (%$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { ?$($k).+ }
+ )
+ );
+ (%$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { %$($k).+ }
+ )
+ );
+ ($($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ { $($k).+ }
+ )
+ );
+ ($($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::INFO,
+ {},
+ $($arg)+
+ )
+ );
+}
+
+/// Constructs an event at the warn level.
+///
+/// This functions similarly to the [`event!`] macro. See [the top-level
+/// documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [`event!`]: macro.event.html
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// ```rust
+/// use tracing::warn;
+/// # fn main() {
+///
+/// let warn_description = "Invalid Input";
+/// let input = &[0x27, 0x45];
+///
+/// warn!(?input, warning = warn_description);
+/// warn!(
+/// target: "input_events",
+/// warning = warn_description,
+/// "Received warning for input: {:?}", input,
+/// );
+/// # }
+/// ```
+#[macro_export]
+macro_rules! warn {
+ (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+)
+ );
+ (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { $($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::WARN,
+ {},
+ $($arg)+
+ )
+ );
+ (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+)
+ );
+ ({ $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ ($($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (%$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ ($($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { $($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (%$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { ?$($k).+ }
+ )
+ );
+ (%$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { %$($k).+ }
+ )
+ );
+ ($($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ { $($k).+ }
+ )
+ );
+ ($($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::WARN,
+ {},
+ $($arg)+
+ )
+ );
+}
+
+/// Constructs an event at the error level.
+///
+/// This functions similarly to the [`event!`] macro. See [the top-level
+/// documentation][lib] for details on the syntax accepted by
+/// this macro.
+///
+/// [`event!`]: macro.event.html
+/// [lib]: index.html#using-the-macros
+///
+/// # Examples
+///
+/// ```rust
+/// use tracing::error;
+/// # fn main() {
+///
+/// let (err_info, port) = ("No connection", 22);
+///
+/// error!(port, error = %err_info);
+/// error!(target: "app_events", "App Error: {}", err_info);
+/// error!({ info = err_info }, "error on port: {}", port);
+/// # }
+/// ```
+#[macro_export]
+macro_rules! error {
+ (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+)
+ );
+ (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { $($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (parent: $parent:expr, $($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ parent: $parent,
+ $crate::Level::ERROR,
+ {},
+ $($arg)+
+ )
+ );
+ (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
+ $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*)
+ );
+ (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ })
+ );
+ (target: $target:expr, $($arg:tt)+ ) => (
+ $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+)
+ );
+ ({ $($field:tt)+ }, $($arg:tt)+ ) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { $($field)+ },
+ $($arg)+
+ )
+ );
+ ($($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { $($k).+ = $($field)*}
+ )
+ );
+ (?$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { ?$($k).+ = $($field)*}
+ )
+ );
+ (%$($k:ident).+ = $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::TRACE,
+ { %$($k).+ = $($field)*}
+ )
+ );
+ ($($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { $($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { ?$($k).+, $($field)*}
+ )
+ );
+ (%$($k:ident).+, $($field:tt)*) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { %$($k).+, $($field)*}
+ )
+ );
+ (?$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { ?$($k).+ }
+ )
+ );
+ (%$($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { %$($k).+ }
+ )
+ );
+ ($($k:ident).+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ { $($k).+ }
+ )
+ );
+ ($($arg:tt)+) => (
+ $crate::event!(
+ target: module_path!(),
+ $crate::Level::ERROR,
+ {},
+ $($arg)+
+ )
+ );
+}
+
+/// Constructs a new static callsite for a span or event.
+#[doc(hidden)]
+#[macro_export]
+macro_rules! callsite {
+ (name: $name:expr, kind: $kind:expr, fields: $($fields:tt)*) => {{
+ $crate::callsite! {
+ name: $name,
+ kind: $kind,
+ target: module_path!(),
+ level: $crate::Level::TRACE,
+ fields: $($fields)*
+ }
+ }};
+ (
+ name: $name:expr,
+ kind: $kind:expr,
+ level: $lvl:expr,
+ fields: $($fields:tt)*
+ ) => {{
+ $crate::callsite! {
+ name: $name,
+ kind: $kind,
+ target: module_path!(),
+ level: $lvl,
+ fields: $($fields)*
+ }
+ }};
+ (
+ name: $name:expr,
+ kind: $kind:expr,
+ target: $target:expr,
+ level: $lvl:expr,
+ fields: $($fields:tt)*
+ ) => {{
+ use $crate::__macro_support::MacroCallsite;
+ static META: $crate::Metadata<'static> = {
+ $crate::metadata! {
+ name: $name,
+ target: $target,
+ level: $lvl,
+ fields: $crate::fieldset!( $($fields)* ),
+ callsite: &CALLSITE,
+ kind: $kind,
+ }
+ };
+ static CALLSITE: MacroCallsite = MacroCallsite::new(&META);
+ CALLSITE.register();
+ &CALLSITE
+ }};
+}
+
+/// Constructs a new static callsite for a span or event.
+#[doc(hidden)]
+#[macro_export]
+macro_rules! callsite2 {
+ (name: $name:expr, kind: $kind:expr, fields: $($fields:tt)*) => {{
+ $crate::callsite2! {
+ name: $name,
+ kind: $kind,
+ target: module_path!(),
+ level: $crate::Level::TRACE,
+ fields: $($fields)*
+ }
+ }};
+ (
+ name: $name:expr,
+ kind: $kind:expr,
+ level: $lvl:expr,
+ fields: $($fields:tt)*
+ ) => {{
+ $crate::callsite2! {
+ name: $name,
+ kind: $kind,
+ target: module_path!(),
+ level: $lvl,
+ fields: $($fields)*
+ }
+ }};
+ (
+ name: $name:expr,
+ kind: $kind:expr,
+ target: $target:expr,
+ level: $lvl:expr,
+ fields: $($fields:tt)*
+ ) => {{
+ use $crate::__macro_support::MacroCallsite;
+ static META: $crate::Metadata<'static> = {
+ $crate::metadata! {
+ name: $name,
+ target: $target,
+ level: $lvl,
+ fields: $crate::fieldset!( $($fields)* ),
+ callsite: &CALLSITE,
+ kind: $kind,
+ }
+ };
+ MacroCallsite::new(&META)
+ }};
+}
+
+#[macro_export]
+// TODO: determine if this ought to be public API?`
+#[doc(hidden)]
+macro_rules! level_enabled {
+ ($lvl:expr) => {
+ $lvl <= $crate::level_filters::STATIC_MAX_LEVEL
+ && $lvl <= $crate::level_filters::LevelFilter::current()
+ };
+}
+
+#[doc(hidden)]
+#[macro_export]
+macro_rules! valueset {
+
+ // === base case ===
+ (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => {
+ &[ $($val),* ]
+ };
+
+ // === recursive case (more tts) ===
+
+ // TODO(#1138): determine a new syntax for uninitialized span fields, and
+ // re-enable this.
+ // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => {
+ // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*)
+ // };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&$val as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&$val as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) },
+ $next,
+ )
+ };
+
+ // Handle literal names
+ (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr, $($rest:tt)*) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&$val as &Value)) },
+ $next,
+ $($rest)*
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) },
+ $next,
+ )
+ };
+ (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr) => {
+ $crate::valueset!(
+ @ { $($out),*, (&$next, Some(&$val as &Value)) },
+ $next,
+ )
+ };
+
+ // Remainder is unparseable, but exists --- must be format args!
+ (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => {
+ $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &Value)), $($out),* }, $next, )
+ };
+
+ // === entry ===
+ ($fields:expr, $($kvs:tt)+) => {
+ {
+ #[allow(unused_imports)]
+ use $crate::field::{debug, display, Value};
+ let mut iter = $fields.iter();
+ $fields.value_set($crate::valueset!(
+ @ { },
+ iter.next().expect("FieldSet corrupted (this is a bug)"),
+ $($kvs)+
+ ))
+ }
+ };
+ ($fields:expr,) => {
+ {
+ $fields.value_set(&[])
+ }
+ };
+}
+
+#[doc(hidden)]
+#[macro_export]
+macro_rules! fieldset {
+ // == base case ==
+ (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => {
+ &[ $($out),* ]
+ };
+
+ // == recursive cases (more tts) ==
+ (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ };
+ // TODO(#1138): determine a new syntax for uninitialized span fields, and
+ // re-enable this.
+ // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => {
+ // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ // };
+ (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*)
+ };
+
+ // Handle literal names
+ (@ { $(,)* $($out:expr),* } $k:literal = ?$val:expr, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $k } $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* } $k:literal = %$val:expr, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $k } $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* } $k:literal = $val:expr, $($rest:tt)*) => {
+ $crate::fieldset!(@ { $($out),*, $k } $($rest)*)
+ };
+
+ // Remainder is unparseable, but exists --- must be format args!
+ (@ { $(,)* $($out:expr),* } $($rest:tt)+) => {
+ $crate::fieldset!(@ { "message", $($out),*, })
+ };
+
+ // == entry ==
+ ($($args:tt)*) => {
+ $crate::fieldset!(@ { } $($args)*,)
+ };
+
+}
+
+#[cfg(feature = "log")]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! level_to_log {
+ ($level:expr) => {
+ match $level {
+ $crate::Level::ERROR => $crate::log::Level::Error,
+ $crate::Level::WARN => $crate::log::Level::Warn,
+ $crate::Level::INFO => $crate::log::Level::Info,
+ $crate::Level::DEBUG => $crate::log::Level::Debug,
+ _ => $crate::log::Level::Trace,
+ }
+ };
+}
+
+#[doc(hidden)]
+#[macro_export]
+macro_rules! __tracing_stringify {
+ ($s:expr) => {
+ stringify!($s)
+ };
+}
+
+#[cfg(not(feature = "log"))]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! __tracing_log {
+ (target: $target:expr, $level:expr, $($field:tt)+ ) => {};
+}
+
+#[cfg(feature = "log")]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! __mk_format_string {
+ // === base case ===
+ (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => {
+ concat!( $($out),*)
+ };
+
+ // === recursive case (more tts), ===
+ // ====== shorthand field syntax ===
+ (@ { $(,)* $($out:expr),* }, ?$($k:ident).+, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, $crate::__tracing_stringify!($($k).+), "={:?} " }, $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* }, %$($k:ident).+, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, $crate::__tracing_stringify!($($k).+), "={} " }, $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* }, $($k:ident).+, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, $crate::__tracing_stringify!($($k).+), "={:?} " }, $($rest)*)
+ };
+ // ====== kv field syntax ===
+ (@ { $(,)* $($out:expr),* }, message = $val:expr, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, "{} " }, $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* }, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, $crate::__tracing_stringify!($($k).+), "={:?} " }, $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* }, $($k:ident).+ = %$val:expr, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, $crate::__tracing_stringify!($($k).+), "={} " }, $($rest)*)
+ };
+ (@ { $(,)* $($out:expr),* }, $($k:ident).+ = $val:expr, $($rest:tt)*) => {
+ $crate::__mk_format_string!(@ { $($out),*, $crate::__tracing_stringify!($($k).+), "={:?} " }, $($rest)*)
+ };
+
+ // === rest is unparseable --- must be fmt args ===
+ (@ { $(,)* $($out:expr),* }, $($rest:tt)+) => {
+ $crate::__mk_format_string!(@ { "{} ", $($out),* }, )
+ };
+
+ // === entry ===
+ ($($kvs:tt)+) => {
+ $crate::__mk_format_string!(@ { }, $($kvs)+,)
+ };
+ () => {
+ ""
+ }
+}
+
+#[cfg(feature = "log")]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! __mk_format_args {
+ // === finished --- called into by base cases ===
+ (@ { $(,)* $($out:expr),* $(,)* }, $fmt:expr, fields: $(,)*) => {
+ format_args!($fmt, $($out),*)
+ };
+
+ // === base case (no more tts) ===
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ = ?$val:expr $(,)*) => {
+ $crate::__mk_format_args!(@ { $($out),*, $val }, $fmt, fields: )
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ = %$val:expr $(,)*) => {
+ $crate::__mk_format_args!(@ { $($out),*, $val }, $fmt, fields: )
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ = $val:expr $(,)*) => {
+ $crate::__mk_format_args!(@ { $($out),*, $val }, $fmt, fields: )
+ };
+ // ====== shorthand field syntax ===
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: ?$($k:ident).+ $(,)*) => {
+ $crate::__mk_format_args!(@ { $($out),*, &$($k).+ }, $fmt, fields:)
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: %$($k:ident).+ $(,)*) => {
+ $crate::__mk_format_args!(@ { $($out),*, &$($k).+ }, $fmt, fields: )
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ $(,)*) => {
+ $crate::__mk_format_args!(@ { $($out),*, &$($k).+ }, $fmt, fields: )
+ };
+
+ // === recursive case (more tts) ===
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ = ?$val:expr, $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { $($out),*, $val }, $fmt, fields: $($rest)+)
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ = %$val:expr, $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { $($out),*, $val }, $fmt, fields: $($rest)+)
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+ = $val:expr, $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { $($out),*, $val }, $fmt, fields: $($rest)+)
+ };
+ // ====== shorthand field syntax ===
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: ?$($k:ident).+, $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { $($out),*, &$($k).+ }, $fmt, fields: $($rest)+)
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: %$($k:ident).+, $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { $($out),*, &$($k).+ }, $fmt, fields: $($rest)+)
+ };
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($k:ident).+, $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { $($out),*, &$($k).+ }, $fmt, fields: $($rest)+)
+ };
+
+ // === rest is unparseable --- must be fmt args ===
+ (@ { $(,)* $($out:expr),* }, $fmt:expr, fields: $($rest:tt)+) => {
+ $crate::__mk_format_args!(@ { format_args!($($rest)+), $($out),* }, $fmt, fields: )
+ };
+
+ // === entry ===
+ ($($kv:tt)*) => {
+ {
+ #[allow(unused_imports)]
+ use $crate::field::{debug, display};
+ // use $crate::__mk_format_string;
+ $crate::__mk_format_args!(@ { }, $crate::__mk_format_string!($($kv)*), fields: $($kv)*)
+ }
+ };
+}
+
+#[cfg(feature = "log")]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! __tracing_log {
+ (target: $target:expr, $level:expr, $($field:tt)+ ) => {
+ $crate::if_log_enabled! {{
+ use $crate::log;
+ let level = $crate::level_to_log!($level);
+ if level <= log::STATIC_MAX_LEVEL && level <= log::max_level() {
+ let log_meta = log::Metadata::builder()
+ .level(level)
+ .target($target)
+ .build();
+ let logger = log::logger();
+ if logger.enabled(&log_meta) {
+ logger.log(&log::Record::builder()
+ .file(Some(file!()))
+ .module_path(Some(module_path!()))
+ .line(Some(line!()))
+ .metadata(log_meta)
+ .args($crate::__mk_format_args!($($field)+))
+ .build());
+ }
+ }
+ }}
+ };
+}
+
+#[cfg(not(feature = "log"))]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! if_log_enabled {
+ ($e:expr;) => {
+ $crate::if_log_enabled! { $e }
+ };
+ ($if_log:block) => {
+ $crate::if_log_enabled! { $if_log else {} }
+ };
+ ($if_log:block else $else_block:block) => {
+ $else_block
+ };
+}
+
+#[cfg(all(feature = "log", not(feature = "log-always")))]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! if_log_enabled {
+ ($e:expr;) => {
+ $crate::if_log_enabled! { $e }
+ };
+ ($if_log:block) => {
+ $crate::if_log_enabled! { $if_log else {} }
+ };
+ ($if_log:block else $else_block:block) => {
+ if !$crate::dispatcher::has_been_set() {
+ $if_log
+ } else {
+ $else_block
+ }
+ };
+}
+
+#[cfg(all(feature = "log", feature = "log-always"))]
+#[doc(hidden)]
+#[macro_export]
+macro_rules! if_log_enabled {
+ ($e:expr;) => {
+ $crate::if_log_enabled! { $e }
+ };
+ ($if_log:block) => {
+ $crate::if_log_enabled! { $if_log else {} }
+ };
+ ($if_log:block else $else_block:block) => {
+ #[allow(unused_braces)]
+ $if_log
+ };
+}
diff --git a/third_party/rust/tracing/src/span.rs b/third_party/rust/tracing/src/span.rs
new file mode 100644
index 0000000000..c1e0ee1a0c
--- /dev/null
+++ b/third_party/rust/tracing/src/span.rs
@@ -0,0 +1,1283 @@
+//! Spans represent periods of time in which a program was executing in a
+//! particular context.
+//!
+//! A span consists of [fields], user-defined key-value pairs of arbitrary data
+//! that describe the context the span represents, and a set of fixed attributes
+//! that describe all `tracing` spans and events. Attributes describing spans
+//! include:
+//!
+//! - An [`Id`] assigned by the subscriber that uniquely identifies it in relation
+//! to other spans.
+//! - The span's [parent] in the trace tree.
+//! - [Metadata] that describes static characteristics of all spans
+//! originating from that callsite, such as its name, source code location,
+//! [verbosity level], and the names of its fields.
+//!
+//! # Creating Spans
+//!
+//! Spans are created using the [`span!`] macro. This macro is invoked with the
+//! following arguments, in order:
+//!
+//! - The [`target`] and/or [`parent`][parent] attributes, if the user wishes to
+//! override their default values.
+//! - The span's [verbosity level]
+//! - A string literal providing the span's name.
+//! - Finally, between zero and 32 arbitrary key/value fields.
+//!
+//! [`target`]: ../struct.Metadata.html#method.target
+//!
+//! For example:
+//! ```rust
+//! use tracing::{span, Level};
+//!
+//! /// Construct a new span at the `INFO` level named "my_span", with a single
+//! /// field named answer , with the value `42`.
+//! let my_span = span!(Level::INFO, "my_span", answer = 42);
+//! ```
+//!
+//! The documentation for the [`span!`] macro provides additional examples of
+//! the various options that exist when creating spans.
+//!
+//! The [`trace_span!`], [`debug_span!`], [`info_span!`], [`warn_span!`], and
+//! [`error_span!`] exist as shorthand for constructing spans at various
+//! verbosity levels.
+//!
+//! ## Recording Span Creation
+//!
+//! The [`Attributes`] type contains data associated with a span, and is
+//! provided to the [`Subscriber`] when a new span is created. It contains
+//! the span's metadata, the ID of [the span's parent][parent] if one was
+//! explicitly set, and any fields whose values were recorded when the span was
+//! constructed. The subscriber, which is responsible for recording `tracing`
+//! data, can then store or record these values.
+//!
+//! # The Span Lifecycle
+//!
+//! ## Entering a Span
+//!
+//! A thread of execution is said to _enter_ a span when it begins executing,
+//! and _exit_ the span when it switches to another context. Spans may be
+//! entered through the [`enter`] and [`in_scope`] methods.
+//!
+//! The `enter` method enters a span, returning a [guard] that exits the span
+//! when dropped
+//! ```
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! let my_var: u64 = 5;
+//! let my_span = span!(Level::TRACE, "my_span", my_var);
+//!
+//! // `my_span` exists but has not been entered.
+//!
+//! // Enter `my_span`...
+//! let _enter = my_span.enter();
+//!
+//! // Perform some work inside of the context of `my_span`...
+//! // Dropping the `_enter` guard will exit the span.
+//!```
+//!
+//! <div class="information">
+//! <div class="tooltip compile_fail" style="">&#x26a0; &#xfe0f;<span class="tooltiptext">Warning</span></div>
+//! </div><div class="example-wrap" style="display:inline-block"><pre class="compile_fail" style="white-space:normal;font:inherit;">
+//! <strong>Warning</strong>: In asynchronous code that uses async/await syntax,
+//! <code>Span::enter</code> may produce incorrect traces if the returned drop
+//! guard is held across an await point. See
+//! <a href="struct.Span.html#in-asynchronous-code">the method documentation</a>
+//! for details.
+//! </pre></div>
+//!
+//! `in_scope` takes a closure or function pointer and executes it inside the
+//! span.
+//! ```
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! let my_var: u64 = 5;
+//! let my_span = span!(Level::TRACE, "my_span", my_var = &my_var);
+//!
+//! my_span.in_scope(|| {
+//! // perform some work in the context of `my_span`...
+//! });
+//!
+//! // Perform some work outside of the context of `my_span`...
+//!
+//! my_span.in_scope(|| {
+//! // Perform some more work in the context of `my_span`.
+//! });
+//! ```
+//!
+//! <div class="information">
+//! <div class="tooltip ignore" style="">ⓘ<span class="tooltiptext">Note</span></div>
+//! </div>
+//! <div class="example-wrap" style="display:inline-block">
+//! <pre class="ignore" style="white-space:normal;font:inherit;">
+//! <strong>Note</strong>: Since entering a span takes <code>&self</code<, and
+//! <code>Span</code>s are <code>Clone</code>, <code>Send</code>, and
+//! <code>Sync</code>, it is entirely valid for multiple threads to enter the
+//! same span concurrently.
+//! </pre></div>
+//!
+//! ## Span Relationships
+//!
+//! Spans form a tree structure — unless it is a root span, all spans have a
+//! _parent_, and may have one or more _children_. When a new span is created,
+//! the current span becomes the new span's parent. The total execution time of
+//! a span consists of the time spent in that span and in the entire subtree
+//! represented by its children. Thus, a parent span always lasts for at least
+//! as long as the longest-executing span in its subtree.
+//!
+//! ```
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! // this span is considered the "root" of a new trace tree:
+//! span!(Level::INFO, "root").in_scope(|| {
+//! // since we are now inside "root", this span is considered a child
+//! // of "root":
+//! span!(Level::DEBUG, "outer_child").in_scope(|| {
+//! // this span is a child of "outer_child", which is in turn a
+//! // child of "root":
+//! span!(Level::TRACE, "inner_child").in_scope(|| {
+//! // and so on...
+//! });
+//! });
+//! // another span created here would also be a child of "root".
+//! });
+//!```
+//!
+//! In addition, the parent of a span may be explicitly specified in
+//! the `span!` macro. For example:
+//!
+//! ```rust
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! // Create, but do not enter, a span called "foo".
+//! let foo = span!(Level::INFO, "foo");
+//!
+//! // Create and enter a span called "bar".
+//! let bar = span!(Level::INFO, "bar");
+//! let _enter = bar.enter();
+//!
+//! // Although we have currently entered "bar", "baz"'s parent span
+//! // will be "foo".
+//! let baz = span!(parent: &foo, Level::INFO, "baz");
+//! ```
+//!
+//! A child span should typically be considered _part_ of its parent. For
+//! example, if a subscriber is recording the length of time spent in various
+//! spans, it should generally include the time spent in a span's children as
+//! part of that span's duration.
+//!
+//! In addition to having zero or one parent, a span may also _follow from_ any
+//! number of other spans. This indicates a causal relationship between the span
+//! and the spans that it follows from, but a follower is *not* typically
+//! considered part of the duration of the span it follows. Unlike the parent, a
+//! span may record that it follows from another span after it is created, using
+//! the [`follows_from`] method.
+//!
+//! As an example, consider a listener task in a server. As the listener accepts
+//! incoming connections, it spawns new tasks that handle those connections. We
+//! might want to have a span representing the listener, and instrument each
+//! spawned handler task with its own span. We would want our instrumentation to
+//! record that the handler tasks were spawned as a result of the listener task.
+//! However, we might not consider the handler tasks to be _part_ of the time
+//! spent in the listener task, so we would not consider those spans children of
+//! the listener span. Instead, we would record that the handler tasks follow
+//! from the listener, recording the causal relationship but treating the spans
+//! as separate durations.
+//!
+//! ## Closing Spans
+//!
+//! Execution may enter and exit a span multiple times before that span is
+//! _closed_. Consider, for example, a future which has an associated
+//! span and enters that span every time it is polled:
+//! ```rust
+//! # extern crate tracing;
+//! # extern crate futures;
+//! # use futures::{Future, Poll, Async};
+//! struct MyFuture {
+//! // data
+//! span: tracing::Span,
+//! }
+//!
+//! impl Future for MyFuture {
+//! type Item = ();
+//! type Error = ();
+//!
+//! fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
+//! let _enter = self.span.enter();
+//! // Do actual future work...
+//! # Ok(Async::Ready(()))
+//! }
+//! }
+//! ```
+//!
+//! If this future was spawned on an executor, it might yield one or more times
+//! before `poll` returns `Ok(Async::Ready)`. If the future were to yield, then
+//! the executor would move on to poll the next future, which may _also_ enter
+//! an associated span or series of spans. Therefore, it is valid for a span to
+//! be entered repeatedly before it completes. Only the time when that span or
+//! one of its children was the current span is considered to be time spent in
+//! that span. A span which is not executing and has not yet been closed is said
+//! to be _idle_.
+//!
+//! Because spans may be entered and exited multiple times before they close,
+//! [`Subscriber`]s have separate trait methods which are called to notify them
+//! of span exits and when span handles are dropped. When execution exits a
+//! span, [`exit`] will always be called with that span's ID to notify the
+//! subscriber that the span has been exited. When span handles are dropped, the
+//! [`drop_span`] method is called with that span's ID. The subscriber may use
+//! this to determine whether or not the span will be entered again.
+//!
+//! If there is only a single handle with the capacity to exit a span, dropping
+//! that handle "closes" the span, since the capacity to enter it no longer
+//! exists. For example:
+//! ```
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! {
+//! span!(Level::TRACE, "my_span").in_scope(|| {
+//! // perform some work in the context of `my_span`...
+//! }); // --> Subscriber::exit(my_span)
+//!
+//! // The handle to `my_span` only lives inside of this block; when it is
+//! // dropped, the subscriber will be informed via `drop_span`.
+//!
+//! } // --> Subscriber::drop_span(my_span)
+//! ```
+//!
+//! However, if multiple handles exist, the span can still be re-entered even if
+//! one or more is dropped. For determining when _all_ handles to a span have
+//! been dropped, `Subscriber`s have a [`clone_span`] method, which is called
+//! every time a span handle is cloned. Combined with `drop_span`, this may be
+//! used to track the number of handles to a given span — if `drop_span` has
+//! been called one more time than the number of calls to `clone_span` for a
+//! given ID, then no more handles to the span with that ID exist. The
+//! subscriber may then treat it as closed.
+//!
+//! # When to use spans
+//!
+//! As a rule of thumb, spans should be used to represent discrete units of work
+//! (e.g., a given request's lifetime in a server) or periods of time spent in a
+//! given context (e.g., time spent interacting with an instance of an external
+//! system, such as a database).
+//!
+//! Which scopes in a program correspond to new spans depend somewhat on user
+//! intent. For example, consider the case of a loop in a program. Should we
+//! construct one span and perform the entire loop inside of that span, like:
+//!
+//! ```rust
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! # let n = 1;
+//! let span = span!(Level::TRACE, "my_loop");
+//! let _enter = span.enter();
+//! for i in 0..n {
+//! # let _ = i;
+//! // ...
+//! }
+//! ```
+//! Or, should we create a new span for each iteration of the loop, as in:
+//! ```rust
+//! # #[macro_use] extern crate tracing;
+//! # use tracing::Level;
+//! # let n = 1u64;
+//! for i in 0..n {
+//! let span = span!(Level::TRACE, "my_loop", iteration = i);
+//! let _enter = span.enter();
+//! // ...
+//! }
+//! ```
+//!
+//! Depending on the circumstances, we might want to do either, or both. For
+//! example, if we want to know how long was spent in the loop overall, we would
+//! create a single span around the entire loop; whereas if we wanted to know how
+//! much time was spent in each individual iteration, we would enter a new span
+//! on every iteration.
+//!
+//! [fields]: ../field/index.html
+//! [Metadata]: ../struct.Metadata.html
+//! [`Id`]: struct.Id.html
+//! [verbosity level]: ../struct.Level.html
+//! [`span!`]: ../macro.span.html
+//! [`trace_span!`]: ../macro.trace_span.html
+//! [`debug_span!`]: ../macro.debug_span.html
+//! [`info_span!`]: ../macro.info_span.html
+//! [`warn_span!`]: ../macro.warn_span.html
+//! [`error_span!`]: ../macro.error_span.html
+//! [`clone_span`]: ../subscriber/trait.Subscriber.html#method.clone_span
+//! [`drop_span`]: ../subscriber/trait.Subscriber.html#method.drop_span
+//! [`exit`]: ../subscriber/trait.Subscriber.html#tymethod.exit
+//! [`Subscriber`]: ../subscriber/trait.Subscriber.html
+//! [`Attributes`]: struct.Attributes.html
+//! [`enter`]: struct.Span.html#method.enter
+//! [`in_scope`]: struct.Span.html#method.in_scope
+//! [`follows_from`]: struct.Span.html#method.follows_from
+//! [guard]: struct.Entered.html
+//! [parent]: #span-relationships
+pub use tracing_core::span::{Attributes, Id, Record};
+
+use crate::stdlib::{
+ cmp, fmt,
+ hash::{Hash, Hasher},
+};
+use crate::{
+ dispatcher::{self, Dispatch},
+ field, Metadata,
+};
+
+/// Trait implemented by types which have a span `Id`.
+pub trait AsId: crate::sealed::Sealed {
+ /// Returns the `Id` of the span that `self` corresponds to, or `None` if
+ /// this corresponds to a disabled span.
+ fn as_id(&self) -> Option<&Id>;
+}
+
+/// A handle representing a span, with the capability to enter the span if it
+/// exists.
+///
+/// If the span was rejected by the current `Subscriber`'s filter, entering the
+/// span will silently do nothing. Thus, the handle can be used in the same
+/// manner regardless of whether or not the trace is currently being collected.
+#[derive(Clone)]
+pub struct Span {
+ /// A handle used to enter the span when it is not executing.
+ ///
+ /// If this is `None`, then the span has either closed or was never enabled.
+ inner: Option<Inner>,
+ /// Metadata describing the span.
+ ///
+ /// This might be `Some` even if `inner` is `None`, in the case that the
+ /// span is disabled but the metadata is needed for `log` support.
+ meta: Option<&'static Metadata<'static>>,
+}
+
+/// A handle representing the capacity to enter a span which is known to exist.
+///
+/// Unlike `Span`, this type is only constructed for spans which _have_ been
+/// enabled by the current filter. This type is primarily used for implementing
+/// span handles; users should typically not need to interact with it directly.
+#[derive(Debug)]
+pub(crate) struct Inner {
+ /// The span's ID, as provided by `subscriber`.
+ id: Id,
+
+ /// The subscriber that will receive events relating to this span.
+ ///
+ /// This should be the same subscriber that provided this span with its
+ /// `id`.
+ subscriber: Dispatch,
+}
+
+/// A guard representing a span which has been entered and is currently
+/// executing.
+///
+/// When the guard is dropped, the span will be exited.
+///
+/// This is returned by the [`Span::enter`] function.
+///
+/// [`Span::enter`]: ../struct.Span.html#method.enter
+#[derive(Debug)]
+#[must_use = "once a span has been entered, it should be exited"]
+pub struct Entered<'a> {
+ span: &'a Span,
+}
+
+/// `log` target for all span lifecycle (creation/enter/exit/close) records.
+#[cfg(feature = "log")]
+const LIFECYCLE_LOG_TARGET: &str = "tracing::span";
+/// `log` target for span activity (enter/exit) records.
+#[cfg(feature = "log")]
+const ACTIVITY_LOG_TARGET: &str = "tracing::span::active";
+
+// ===== impl Span =====
+
+impl Span {
+ /// Constructs a new `Span` with the given [metadata] and set of
+ /// [field values].
+ ///
+ /// The new span will be constructed by the currently-active [`Subscriber`],
+ /// with the current span as its parent (if one exists).
+ ///
+ /// After the span is constructed, [field values] and/or [`follows_from`]
+ /// annotations may be added to it.
+ ///
+ /// [metadata]: ../metadata
+ /// [`Subscriber`]: ../subscriber/trait.Subscriber.html
+ /// [field values]: ../field/struct.ValueSet.html
+ /// [`follows_from`]: ../struct.Span.html#method.follows_from
+ pub fn new(meta: &'static Metadata<'static>, values: &field::ValueSet<'_>) -> Span {
+ dispatcher::get_default(|dispatch| Self::new_with(meta, values, dispatch))
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub fn new_with(
+ meta: &'static Metadata<'static>,
+ values: &field::ValueSet<'_>,
+ dispatch: &Dispatch,
+ ) -> Span {
+ let new_span = Attributes::new(meta, values);
+ Self::make_with(meta, new_span, dispatch)
+ }
+
+ /// Constructs a new `Span` as the root of its own trace tree, with the
+ /// given [metadata] and set of [field values].
+ ///
+ /// After the span is constructed, [field values] and/or [`follows_from`]
+ /// annotations may be added to it.
+ ///
+ /// [metadata]: ../metadata
+ /// [field values]: ../field/struct.ValueSet.html
+ /// [`follows_from`]: ../struct.Span.html#method.follows_from
+ pub fn new_root(meta: &'static Metadata<'static>, values: &field::ValueSet<'_>) -> Span {
+ dispatcher::get_default(|dispatch| Self::new_root_with(meta, values, dispatch))
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub fn new_root_with(
+ meta: &'static Metadata<'static>,
+ values: &field::ValueSet<'_>,
+ dispatch: &Dispatch,
+ ) -> Span {
+ let new_span = Attributes::new_root(meta, values);
+ Self::make_with(meta, new_span, dispatch)
+ }
+
+ /// Constructs a new `Span` as child of the given parent span, with the
+ /// given [metadata] and set of [field values].
+ ///
+ /// After the span is constructed, [field values] and/or [`follows_from`]
+ /// annotations may be added to it.
+ ///
+ /// [metadata]: ../metadata
+ /// [field values]: ../field/struct.ValueSet.html
+ /// [`follows_from`]: ../struct.Span.html#method.follows_from
+ pub fn child_of(
+ parent: impl Into<Option<Id>>,
+ meta: &'static Metadata<'static>,
+ values: &field::ValueSet<'_>,
+ ) -> Span {
+ let mut parent = parent.into();
+ dispatcher::get_default(move |dispatch| {
+ Self::child_of_with(Option::take(&mut parent), meta, values, dispatch)
+ })
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub fn child_of_with(
+ parent: impl Into<Option<Id>>,
+ meta: &'static Metadata<'static>,
+ values: &field::ValueSet<'_>,
+ dispatch: &Dispatch,
+ ) -> Span {
+ let new_span = match parent.into() {
+ Some(parent) => Attributes::child_of(parent, meta, values),
+ None => Attributes::new_root(meta, values),
+ };
+ Self::make_with(meta, new_span, dispatch)
+ }
+
+ /// Constructs a new disabled span with the given `Metadata`.
+ ///
+ /// This should be used when a span is constructed from a known callsite,
+ /// but the subscriber indicates that it is disabled.
+ ///
+ /// Entering, exiting, and recording values on this span will not notify the
+ /// `Subscriber` but _may_ record log messages if the `log` feature flag is
+ /// enabled.
+ #[inline(always)]
+ pub fn new_disabled(meta: &'static Metadata<'static>) -> Span {
+ Self {
+ inner: None,
+ meta: Some(meta),
+ }
+ }
+
+ /// Constructs a new span that is *completely disabled*.
+ ///
+ /// This can be used rather than `Option<Span>` to represent cases where a
+ /// span is not present.
+ ///
+ /// Entering, exiting, and recording values on this span will do nothing.
+ #[inline(always)]
+ pub const fn none() -> Span {
+ Self {
+ inner: None,
+ meta: None,
+ }
+ }
+
+ /// Returns a handle to the span [considered by the `Subscriber`] to be the
+ /// current span.
+ ///
+ /// If the subscriber indicates that it does not track the current span, or
+ /// that the thread from which this function is called is not currently
+ /// inside a span, the returned span will be disabled.
+ ///
+ /// [considered by the `Subscriber`]: ../subscriber/trait.Subscriber.html#method.current
+ pub fn current() -> Span {
+ dispatcher::get_default(|dispatch| {
+ if let Some((id, meta)) = dispatch.current_span().into_inner() {
+ let id = dispatch.clone_span(&id);
+ Self {
+ inner: Some(Inner::new(id, dispatch)),
+ meta: Some(meta),
+ }
+ } else {
+ Self::none()
+ }
+ })
+ }
+
+ fn make_with(
+ meta: &'static Metadata<'static>,
+ new_span: Attributes<'_>,
+ dispatch: &Dispatch,
+ ) -> Span {
+ let attrs = &new_span;
+ let id = dispatch.new_span(attrs);
+ let inner = Some(Inner::new(id, dispatch));
+
+ let span = Self {
+ inner,
+ meta: Some(meta),
+ };
+
+ if_log_enabled! {{
+ let target = if attrs.is_empty() {
+ LIFECYCLE_LOG_TARGET
+ } else {
+ meta.target()
+ };
+ span.log(target, level_to_log!(*meta.level()), format_args!("++ {}{}", meta.name(), FmtAttrs(attrs)));
+ }}
+
+ span
+ }
+ /// Enters this span, returning a guard that will exit the span when dropped.
+ ///
+ /// If this span is enabled by the current subscriber, then this function will
+ /// call [`Subscriber::enter`] with the span's [`Id`], and dropping the guard
+ /// will call [`Subscriber::exit`]. If the span is disabled, this does
+ /// nothing.
+ ///
+ /// # In Asynchronous Code
+ ///
+ /// **Warning**: in asynchronous code that uses [async/await syntax][syntax],
+ /// `Span::enter` should be used very carefully or avoided entirely. Holding
+ /// the drop guard returned by `Span::enter` across `.await` points will
+ /// result in incorrect traces.
+ ///
+ /// For example,
+ ///
+ /// ```
+ /// # use tracing::info_span;
+ /// # async fn some_other_async_function() {}
+ /// async fn my_async_function() {
+ /// let span = info_span!("my_async_function");
+ ///
+ /// // THIS WILL RESULT IN INCORRECT TRACES
+ /// let _enter = span.enter();
+ /// some_other_async_function().await;
+ ///
+ /// // ...
+ /// }
+ /// ```
+ ///
+ /// The drop guard returned by `Span::enter` exits the span when it is
+ /// dropped. When an async function or async block yields at an `.await`
+ /// point, the current scope is _exited_, but values in that scope are
+ /// **not** dropped (because the async block will eventually resume
+ /// execution from that await point). This means that _another_ task will
+ /// begin executing while _remaining_ in the entered span. This results in
+ /// an incorrect trace.
+ ///
+ /// Instead of using `Span::enter` in asynchronous code, prefer the
+ /// following:
+ ///
+ /// * To enter a span for a synchronous section of code within an async
+ /// block or function, prefer [`Span::in_scope`]. Since `in_scope` takes a
+ /// synchronous closure and exits the span when the closure returns, the
+ /// span will always be exited before the next await point. For example:
+ /// ```
+ /// # use tracing::info_span;
+ /// # async fn some_other_async_function(_: ()) {}
+ /// async fn my_async_function() {
+ /// let span = info_span!("my_async_function");
+ ///
+ /// let some_value = span.in_scope(|| {
+ /// // run some synchronous code inside the span...
+ /// });
+ ///
+ /// // This is okay! The span has already been exited before we reach
+ /// // the await point.
+ /// some_other_async_function(some_value).await;
+ ///
+ /// // ...
+ /// }
+ /// ```
+ /// * For instrumenting asynchronous code, `tracing` provides the
+ /// [`Future::instrument` combinator][instrument] for
+ /// attaching a span to a future (async function or block). This will
+ /// enter the span _every_ time the future is polled, and exit it whenever
+ /// the future yields.
+ ///
+ /// `Instrument` can be used with an async block inside an async function:
+ /// ```ignore
+ /// # use tracing::info_span;
+ /// use tracing::Instrument;
+ ///
+ /// # async fn some_other_async_function() {}
+ /// async fn my_async_function() {
+ /// let span = info_span!("my_async_function");
+ /// async move {
+ /// // This is correct! If we yield here, the span will be exited,
+ /// // and re-entered when we resume.
+ /// some_other_async_function().await;
+ ///
+ /// //more asynchronous code inside the span...
+ ///
+ /// }
+ /// // instrument the async block with the span...
+ /// .instrument(span)
+ /// // ...and await it.
+ /// .await
+ /// }
+ /// ```
+ ///
+ /// It can also be used to instrument calls to async functions at the
+ /// callsite:
+ /// ```ignore
+ /// # use tracing::debug_span;
+ /// use tracing::Instrument;
+ ///
+ /// # async fn some_other_async_function() {}
+ /// async fn my_async_function() {
+ /// let some_value = some_other_async_function()
+ /// .instrument(debug_span!("some_other_async_function"))
+ /// .await;
+ ///
+ /// // ...
+ /// }
+ /// ```
+ ///
+ /// * The [`#[instrument]` attribute macro][attr] can automatically generate
+ /// correct code when used on an async function:
+ ///
+ /// ```ignore
+ /// # async fn some_other_async_function() {}
+ /// #[tracing::instrument(level = "info")]
+ /// async fn my_async_function() {
+ ///
+ /// // This is correct! If we yield here, the span will be exited,
+ /// // and re-entered when we resume.
+ /// some_other_async_function().await;
+ ///
+ /// // ...
+ ///
+ /// }
+ /// ```
+ ///
+ /// [syntax]: https://rust-lang.github.io/async-book/01_getting_started/04_async_await_primer.html
+ /// [`Span::in_scope`]: #method.in_scope
+ /// [instrument]: https://docs.rs/tracing/latest/tracing/trait.Instrument.html
+ /// [attr]: ../../attr.instrument.html
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #[macro_use] extern crate tracing;
+ /// # use tracing::Level;
+ /// let span = span!(Level::INFO, "my_span");
+ /// let guard = span.enter();
+ ///
+ /// // code here is within the span
+ ///
+ /// drop(guard);
+ ///
+ /// // code here is no longer within the span
+ ///
+ /// ```
+ ///
+ /// Guards need not be explicitly dropped:
+ ///
+ /// ```
+ /// #[macro_use] extern crate tracing;
+ /// fn my_function() -> String {
+ /// // enter a span for the duration of this function.
+ /// let span = trace_span!("my_function");
+ /// let _enter = span.enter();
+ ///
+ /// // anything happening in functions we call is still inside the span...
+ /// my_other_function();
+ ///
+ /// // returning from the function drops the guard, exiting the span.
+ /// return "Hello world".to_owned();
+ /// }
+ ///
+ /// fn my_other_function() {
+ /// // ...
+ /// }
+ /// ```
+ ///
+ /// Sub-scopes may be created to limit the duration for which the span is
+ /// entered:
+ ///
+ /// ```
+ /// #[macro_use] extern crate tracing;
+ /// let span = info_span!("my_great_span");
+ ///
+ /// {
+ /// let _enter = span.enter();
+ ///
+ /// // this event occurs inside the span.
+ /// info!("i'm in the span!");
+ ///
+ /// // exiting the scope drops the guard, exiting the span.
+ /// }
+ ///
+ /// // this event is not inside the span.
+ /// info!("i'm outside the span!")
+ /// ```
+ ///
+ /// [`Subscriber::enter`]: ../subscriber/trait.Subscriber.html#method.enter
+ /// [`Subscriber::exit`]: ../subscriber/trait.Subscriber.html#method.exit
+ /// [`Id`]: ../struct.Id.html
+ pub fn enter(&self) -> Entered<'_> {
+ if let Some(ref inner) = self.inner.as_ref() {
+ inner.subscriber.enter(&inner.id);
+ }
+
+ if_log_enabled! {{
+ if let Some(ref meta) = self.meta {
+ self.log(ACTIVITY_LOG_TARGET, log::Level::Trace, format_args!("-> {}", meta.name()));
+ }
+ }}
+
+ Entered { span: self }
+ }
+
+ /// Executes the given function in the context of this span.
+ ///
+ /// If this span is enabled, then this function enters the span, invokes `f`
+ /// and then exits the span. If the span is disabled, `f` will still be
+ /// invoked, but in the context of the currently-executing span (if there is
+ /// one).
+ ///
+ /// Returns the result of evaluating `f`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// # #[macro_use] extern crate tracing;
+ /// # use tracing::Level;
+ /// let my_span = span!(Level::TRACE, "my_span");
+ ///
+ /// my_span.in_scope(|| {
+ /// // this event occurs within the span.
+ /// trace!("i'm in the span!");
+ /// });
+ ///
+ /// // this event occurs outside the span.
+ /// trace!("i'm not in the span!");
+ /// ```
+ ///
+ /// Calling a function and returning the result:
+ /// ```
+ /// # use tracing::{info_span, Level};
+ /// fn hello_world() -> String {
+ /// "Hello world!".to_owned()
+ /// }
+ ///
+ /// let span = info_span!("hello_world");
+ /// // the span will be entered for the duration of the call to
+ /// // `hello_world`.
+ /// let a_string = span.in_scope(hello_world);
+ ///
+ pub fn in_scope<F: FnOnce() -> T, T>(&self, f: F) -> T {
+ let _enter = self.enter();
+ f()
+ }
+
+ /// Returns a [`Field`](../field/struct.Field.html) for the field with the
+ /// given `name`, if one exists,
+ pub fn field<Q: ?Sized>(&self, field: &Q) -> Option<field::Field>
+ where
+ Q: field::AsField,
+ {
+ self.metadata().and_then(|meta| field.as_field(meta))
+ }
+
+ /// Returns true if this `Span` has a field for the given
+ /// [`Field`](../field/struct.Field.html) or field name.
+ #[inline]
+ pub fn has_field<Q: ?Sized>(&self, field: &Q) -> bool
+ where
+ Q: field::AsField,
+ {
+ self.field(field).is_some()
+ }
+
+ /// Records that the field described by `field` has the value `value`.
+ ///
+ /// This may be used with [`field::Empty`] to declare fields whose values
+ /// are not known when the span is created, and record them later:
+ /// ```
+ /// use tracing::{trace_span, field};
+ ///
+ /// // Create a span with two fields: `greeting`, with the value "hello world", and
+ /// // `parting`, without a value.
+ /// let span = trace_span!("my_span", greeting = "hello world", parting = field::Empty);
+ ///
+ /// // ...
+ ///
+ /// // Now, record a value for parting as well.
+ /// // (note that the field name is passed as a string slice)
+ /// span.record("parting", &"goodbye world!");
+ /// ```
+ /// However, it may also be used to record a _new_ value for a field whose
+ /// value was already recorded:
+ /// ```
+ /// use tracing::info_span;
+ /// # fn do_something() -> Result<(), ()> { Err(()) }
+ ///
+ /// // Initially, let's assume that our attempt to do something is going okay...
+ /// let span = info_span!("doing_something", is_okay = true);
+ /// let _e = span.enter();
+ ///
+ /// match do_something() {
+ /// Ok(something) => {
+ /// // ...
+ /// }
+ /// Err(_) => {
+ /// // Things are no longer okay!
+ /// span.record("is_okay", &false);
+ /// }
+ /// }
+ /// ```
+ ///
+ /// <div class="information">
+ /// <div class="tooltip ignore" style="">ⓘ<span class="tooltiptext">Note</span></div>
+ /// </div>
+ /// <div class="example-wrap" style="display:inline-block">
+ /// <pre class="ignore" style="white-space:normal;font:inherit;">
+ /// <strong>Note</strong>: The fields associated with a span are part of its
+ /// <a href="../struct.Metadata.html"><code>Metadata</code></a>.
+ /// The <a href="../struct.Metadata.html"><code>Metadata</code></a>. describing a particular
+ /// span is constructed statically when the span is created and cannot be extended later to
+ /// add new fields. Therefore, you cannot record a value for a field that was not specified
+ /// when the span was created:</pre></div>
+ ///
+ /// ```
+ /// use tracing::{trace_span, field};
+ ///
+ /// // Create a span with two fields: `greeting`, with the value "hello world", and
+ /// // `parting`, without a value.
+ /// let span = trace_span!("my_span", greeting = "hello world", parting = field::Empty);
+ ///
+ /// // ...
+ ///
+ /// // Now, you try to record a value for a new field, `new_field`, which was not
+ /// // declared as `Empty` or populated when you created `span`.
+ /// // You won't get any error, but the assignment will have no effect!
+ /// span.record("new_field", &"interesting_value_you_really_need");
+ ///
+ /// // Instead, all fields that may be recorded after span creation should be declared up front,
+ /// // using field::Empty when a value is not known, as we did for `parting`.
+ /// // This `record` call will indeed replace field::Empty with "you will be remembered".
+ /// span.record("parting", &"you will be remembered");
+ /// ```
+ ///
+ /// [`field::Empty`]: ../field/struct.Empty.html
+ /// [`Metadata`]: ../struct.Metadata.html
+ pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
+ where
+ Q: field::AsField,
+ V: field::Value,
+ {
+ if let Some(ref meta) = self.meta {
+ if let Some(field) = field.as_field(meta) {
+ self.record_all(
+ &meta
+ .fields()
+ .value_set(&[(&field, Some(value as &dyn field::Value))]),
+ );
+ }
+ }
+
+ self
+ }
+
+ /// Records all the fields in the provided `ValueSet`.
+ pub fn record_all(&self, values: &field::ValueSet<'_>) -> &Self {
+ let record = Record::new(values);
+ if let Some(ref inner) = self.inner {
+ inner.record(&record);
+ }
+
+ if_log_enabled! {{
+ if let Some(ref meta) = self.meta {
+ let target = if record.is_empty() {
+ LIFECYCLE_LOG_TARGET
+ } else {
+ meta.target()
+ };
+ self.log(target, level_to_log!(*meta.level()), format_args!("{}{}", meta.name(), FmtValues(&record)));
+ }
+ }}
+
+ self
+ }
+
+ /// Returns `true` if this span was disabled by the subscriber and does not
+ /// exist.
+ ///
+ /// See also [`is_none`].
+ ///
+ /// [`is_none`]: #method.is_none
+ #[inline]
+ pub fn is_disabled(&self) -> bool {
+ self.inner.is_none()
+ }
+
+ /// Returns `true` if this span was constructed by [`Span::none`] and is
+ /// empty.
+ ///
+ /// If `is_none` returns `true` for a given span, then [`is_disabled`] will
+ /// also return `true`. However, when a span is disabled by the subscriber
+ /// rather than constructed by `Span::none`, this method will return
+ /// `false`, while `is_disabled` will return `true`.
+ ///
+ /// [`Span::none`]: #method.none
+ /// [`is_disabled`]: #method.is_disabled
+ #[inline]
+ pub fn is_none(&self) -> bool {
+ self.is_disabled() && self.meta.is_none()
+ }
+
+ /// Indicates that the span with the given ID has an indirect causal
+ /// relationship with this span.
+ ///
+ /// This relationship differs somewhat from the parent-child relationship: a
+ /// span may have any number of prior spans, rather than a single one; and
+ /// spans are not considered to be executing _inside_ of the spans they
+ /// follow from. This means that a span may close even if subsequent spans
+ /// that follow from it are still open, and time spent inside of a
+ /// subsequent span should not be included in the time its precedents were
+ /// executing. This is used to model causal relationships such as when a
+ /// single future spawns several related background tasks, et cetera.
+ ///
+ /// If this span is disabled, or the resulting follows-from relationship
+ /// would be invalid, this function will do nothing.
+ ///
+ /// # Examples
+ ///
+ /// Setting a `follows_from` relationship with a `Span`:
+ /// ```
+ /// # use tracing::{span, Id, Level, Span};
+ /// let span1 = span!(Level::INFO, "span_1");
+ /// let span2 = span!(Level::DEBUG, "span_2");
+ /// span2.follows_from(span1);
+ /// ```
+ ///
+ /// Setting a `follows_from` relationship with the current span:
+ /// ```
+ /// # use tracing::{span, Id, Level, Span};
+ /// let span = span!(Level::INFO, "hello!");
+ /// span.follows_from(Span::current());
+ /// ```
+ ///
+ /// Setting a `follows_from` relationship with a `Span` reference:
+ /// ```
+ /// # use tracing::{span, Id, Level, Span};
+ /// let span = span!(Level::INFO, "hello!");
+ /// let curr = Span::current();
+ /// span.follows_from(&curr);
+ /// ```
+ ///
+ /// Setting a `follows_from` relationship with an `Id`:
+ /// ```
+ /// # use tracing::{span, Id, Level, Span};
+ /// let span = span!(Level::INFO, "hello!");
+ /// let id = span.id();
+ /// span.follows_from(id);
+ /// ```
+ pub fn follows_from(&self, from: impl Into<Option<Id>>) -> &Self {
+ if let Some(ref inner) = self.inner {
+ if let Some(from) = from.into() {
+ inner.follows_from(&from);
+ }
+ }
+ self
+ }
+
+ /// Returns this span's `Id`, if it is enabled.
+ pub fn id(&self) -> Option<Id> {
+ self.inner.as_ref().map(Inner::id)
+ }
+
+ /// Returns this span's `Metadata`, if it is enabled.
+ pub fn metadata(&self) -> Option<&'static Metadata<'static>> {
+ self.meta
+ }
+
+ #[cfg(feature = "log")]
+ #[inline]
+ fn log(&self, target: &str, level: log::Level, message: fmt::Arguments<'_>) {
+ if let Some(ref meta) = self.meta {
+ if level_to_log!(*meta.level()) <= log::max_level() {
+ let logger = log::logger();
+ let log_meta = log::Metadata::builder().level(level).target(target).build();
+ if logger.enabled(&log_meta) {
+ if let Some(ref inner) = self.inner {
+ logger.log(
+ &log::Record::builder()
+ .metadata(log_meta)
+ .module_path(meta.module_path())
+ .file(meta.file())
+ .line(meta.line())
+ .args(format_args!("{}; span={}", message, inner.id.into_u64()))
+ .build(),
+ );
+ } else {
+ logger.log(
+ &log::Record::builder()
+ .metadata(log_meta)
+ .module_path(meta.module_path())
+ .file(meta.file())
+ .line(meta.line())
+ .args(message)
+ .build(),
+ );
+ }
+ }
+ }
+ }
+ }
+
+ /// Invokes a function with a reference to this span's ID and subscriber.
+ ///
+ /// if this span is enabled, the provided function is called, and the result is returned.
+ /// If the span is disabled, the function is not called, and this method returns `None`
+ /// instead.
+ pub fn with_subscriber<T>(&self, f: impl FnOnce((&Id, &Dispatch)) -> T) -> Option<T> {
+ self.inner
+ .as_ref()
+ .map(|inner| f((&inner.id, &inner.subscriber)))
+ }
+}
+
+impl cmp::PartialEq for Span {
+ fn eq(&self, other: &Self) -> bool {
+ match (&self.meta, &other.meta) {
+ (Some(this), Some(that)) => {
+ this.callsite() == that.callsite() && self.inner == other.inner
+ }
+ _ => false,
+ }
+ }
+}
+
+impl Hash for Span {
+ fn hash<H: Hasher>(&self, hasher: &mut H) {
+ self.inner.hash(hasher);
+ }
+}
+
+impl fmt::Debug for Span {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut span = f.debug_struct("Span");
+ if let Some(ref meta) = self.meta {
+ span.field("name", &meta.name())
+ .field("level", &meta.level())
+ .field("target", &meta.target());
+
+ if let Some(ref inner) = self.inner {
+ span.field("id", &inner.id());
+ } else {
+ span.field("disabled", &true);
+ }
+
+ if let Some(ref path) = meta.module_path() {
+ span.field("module_path", &path);
+ }
+
+ if let Some(ref line) = meta.line() {
+ span.field("line", &line);
+ }
+
+ if let Some(ref file) = meta.file() {
+ span.field("file", &file);
+ }
+ } else {
+ span.field("none", &true);
+ }
+
+ span.finish()
+ }
+}
+
+impl<'a> Into<Option<&'a Id>> for &'a Span {
+ fn into(self) -> Option<&'a Id> {
+ self.inner.as_ref().map(|inner| &inner.id)
+ }
+}
+
+impl<'a> Into<Option<Id>> for &'a Span {
+ fn into(self) -> Option<Id> {
+ self.inner.as_ref().map(Inner::id)
+ }
+}
+
+impl Into<Option<Id>> for Span {
+ fn into(self) -> Option<Id> {
+ self.inner.as_ref().map(Inner::id)
+ }
+}
+
+impl Drop for Span {
+ fn drop(&mut self) {
+ if let Some(Inner {
+ ref id,
+ ref subscriber,
+ }) = self.inner
+ {
+ subscriber.try_close(id.clone());
+ }
+
+ if_log_enabled!({
+ if let Some(ref meta) = self.meta {
+ self.log(
+ LIFECYCLE_LOG_TARGET,
+ log::Level::Trace,
+ format_args!("-- {}", meta.name()),
+ );
+ }
+ })
+ }
+}
+
+// ===== impl Inner =====
+
+impl Inner {
+ /// Indicates that the span with the given ID has an indirect causal
+ /// relationship with this span.
+ ///
+ /// This relationship differs somewhat from the parent-child relationship: a
+ /// span may have any number of prior spans, rather than a single one; and
+ /// spans are not considered to be executing _inside_ of the spans they
+ /// follow from. This means that a span may close even if subsequent spans
+ /// that follow from it are still open, and time spent inside of a
+ /// subsequent span should not be included in the time its precedents were
+ /// executing. This is used to model causal relationships such as when a
+ /// single future spawns several related background tasks, et cetera.
+ ///
+ /// If this span is disabled, this function will do nothing. Otherwise, it
+ /// returns `Ok(())` if the other span was added as a precedent of this
+ /// span, or an error if this was not possible.
+ fn follows_from(&self, from: &Id) {
+ self.subscriber.record_follows_from(&self.id, &from)
+ }
+
+ /// Returns the span's ID.
+ fn id(&self) -> Id {
+ self.id.clone()
+ }
+
+ fn record(&self, values: &Record<'_>) {
+ self.subscriber.record(&self.id, values)
+ }
+
+ fn new(id: Id, subscriber: &Dispatch) -> Self {
+ Inner {
+ id,
+ subscriber: subscriber.clone(),
+ }
+ }
+}
+
+impl cmp::PartialEq for Inner {
+ fn eq(&self, other: &Self) -> bool {
+ self.id == other.id
+ }
+}
+
+impl Hash for Inner {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.id.hash(state);
+ }
+}
+
+impl Clone for Inner {
+ fn clone(&self) -> Self {
+ Inner {
+ id: self.subscriber.clone_span(&self.id),
+ subscriber: self.subscriber.clone(),
+ }
+ }
+}
+
+// ===== impl Entered =====
+
+impl<'a> Drop for Entered<'a> {
+ #[inline]
+ fn drop(&mut self) {
+ // Dropping the guard exits the span.
+ //
+ // Running this behaviour on drop rather than with an explicit function
+ // call means that spans may still be exited when unwinding.
+ if let Some(inner) = self.span.inner.as_ref() {
+ inner.subscriber.exit(&inner.id);
+ }
+
+ if_log_enabled! {{
+ if let Some(ref meta) = self.span.meta {
+ self.span.log(ACTIVITY_LOG_TARGET, log::Level::Trace, format_args!("<- {}", meta.name()));
+ }
+ }}
+ }
+}
+
+#[cfg(feature = "log")]
+struct FmtValues<'a>(&'a Record<'a>);
+
+#[cfg(feature = "log")]
+impl<'a> fmt::Display for FmtValues<'a> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut res = Ok(());
+ let mut is_first = true;
+ self.0.record(&mut |k: &field::Field, v: &dyn fmt::Debug| {
+ res = write!(f, "{} {}={:?}", if is_first { ";" } else { "" }, k, v);
+ is_first = false;
+ });
+ res
+ }
+}
+
+#[cfg(feature = "log")]
+struct FmtAttrs<'a>(&'a Attributes<'a>);
+
+#[cfg(feature = "log")]
+impl<'a> fmt::Display for FmtAttrs<'a> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut res = Ok(());
+ let mut is_first = true;
+ self.0.record(&mut |k: &field::Field, v: &dyn fmt::Debug| {
+ res = write!(f, "{} {}={:?}", if is_first { ";" } else { "" }, k, v);
+ is_first = false;
+ });
+ res
+ }
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ trait AssertSend: Send {}
+ impl AssertSend for Span {}
+
+ trait AssertSync: Sync {}
+ impl AssertSync for Span {}
+}
diff --git a/third_party/rust/tracing/src/stdlib.rs b/third_party/rust/tracing/src/stdlib.rs
new file mode 100644
index 0000000000..12b54084d4
--- /dev/null
+++ b/third_party/rust/tracing/src/stdlib.rs
@@ -0,0 +1,55 @@
+//! Re-exports either the Rust `std` library or `core` and `alloc` when `std` is
+//! disabled.
+//!
+//! `crate::stdlib::...` should be used rather than `std::` when adding code that
+//! will be available with the standard library disabled.
+//!
+//! Note that this module is called `stdlib` rather than `std`, as Rust 1.34.0
+//! does not permit redefining the name `stdlib` (although this works on the
+//! latest stable Rust).
+#[cfg(feature = "std")]
+pub(crate) use std::*;
+
+#[cfg(not(feature = "std"))]
+pub(crate) use self::no_std::*;
+
+#[cfg(not(feature = "std"))]
+mod no_std {
+ // We pre-emptively export everything from libcore/liballoc, (even modules
+ // we aren't using currently) to make adding new code easier. Therefore,
+ // some of these imports will be unused.
+ #![allow(unused_imports)]
+
+ pub(crate) use core::{
+ any, array, ascii, cell, char, clone, cmp, convert, default, f32, f64, ffi, future, hash,
+ hint, i128, i16, i8, isize, iter, marker, mem, num, ops, option, pin, ptr, result, task,
+ time, u128, u16, u32, u8, usize,
+ };
+
+ pub(crate) use alloc::{boxed, collections, rc, string, vec};
+
+ pub(crate) mod borrow {
+ pub(crate) use alloc::borrow::*;
+ pub(crate) use core::borrow::*;
+ }
+
+ pub(crate) mod fmt {
+ pub(crate) use alloc::fmt::*;
+ pub(crate) use core::fmt::*;
+ }
+
+ pub(crate) mod slice {
+ pub(crate) use alloc::slice::*;
+ pub(crate) use core::slice::*;
+ }
+
+ pub(crate) mod str {
+ pub(crate) use alloc::str::*;
+ pub(crate) use core::str::*;
+ }
+
+ pub(crate) mod sync {
+ pub(crate) use alloc::sync::*;
+ pub(crate) use core::sync::*;
+ }
+}
diff --git a/third_party/rust/tracing/src/subscriber.rs b/third_party/rust/tracing/src/subscriber.rs
new file mode 100644
index 0000000000..8f35d84e09
--- /dev/null
+++ b/third_party/rust/tracing/src/subscriber.rs
@@ -0,0 +1,68 @@
+//! Collects and records trace data.
+pub use tracing_core::subscriber::*;
+
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+pub use tracing_core::dispatcher::DefaultGuard;
+
+/// Sets this subscriber as the default for the duration of a closure.
+///
+/// The default subscriber is used when creating a new [`Span`] or
+/// [`Event`], _if no span is currently executing_. If a span is currently
+/// executing, new spans or events are dispatched to the subscriber that
+/// tagged that span, instead.
+///
+/// [`Span`]: ../span/struct.Span.html
+/// [`Subscriber`]: ../subscriber/trait.Subscriber.html
+/// [`Event`]: :../event/struct.Event.html
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+pub fn with_default<T, S>(subscriber: S, f: impl FnOnce() -> T) -> T
+where
+ S: Subscriber + Send + Sync + 'static,
+{
+ crate::dispatcher::with_default(&crate::Dispatch::new(subscriber), f)
+}
+
+/// Sets this subscriber as the global default for the duration of the entire program.
+/// Will be used as a fallback if no thread-local subscriber has been set in a thread (using `with_default`.)
+///
+/// Can only be set once; subsequent attempts to set the global default will fail.
+/// Returns whether the initialization was successful.
+///
+/// Note: Libraries should *NOT* call `set_global_default()`! That will cause conflicts when
+/// executables try to set them later.
+///
+/// [span]: ../span/index.html
+/// [`Subscriber`]: ../subscriber/trait.Subscriber.html
+/// [`Event`]: ../event/struct.Event.html
+pub fn set_global_default<S>(subscriber: S) -> Result<(), SetGlobalDefaultError>
+where
+ S: Subscriber + Send + Sync + 'static,
+{
+ crate::dispatcher::set_global_default(crate::Dispatch::new(subscriber))
+}
+
+/// Sets the subscriber as the default for the duration of the lifetime of the
+/// returned [`DefaultGuard`]
+///
+/// The default subscriber is used when creating a new [`Span`] or
+/// [`Event`], _if no span is currently executing_. If a span is currently
+/// executing, new spans or events are dispatched to the subscriber that
+/// tagged that span, instead.
+///
+/// [`Span`]: ../span/struct.Span.html
+/// [`Subscriber`]: ../subscriber/trait.Subscriber.html
+/// [`Event`]: :../event/struct.Event.html
+/// [`DefaultGuard`]: ../dispatcher/struct.DefaultGuard.html
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
+#[must_use = "Dropping the guard unregisters the subscriber."]
+pub fn set_default<S>(subscriber: S) -> DefaultGuard
+where
+ S: Subscriber + Send + Sync + 'static,
+{
+ crate::dispatcher::set_default(&crate::Dispatch::new(subscriber))
+}
+
+pub use tracing_core::dispatcher::SetGlobalDefaultError;