RPM build fix (reverted CI changes which will need to be un-reverted or made conditional) and vendor Rust dependencies to make builds much faster in any CI system.
This commit is contained in:
149
zeroidc/vendor/tracing/src/dispatcher.rs
vendored
Normal file
149
zeroidc/vendor/tracing/src/dispatcher.rs
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
//! 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
|
||||
//! ```
|
||||
//!
|
||||
//! <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>
|
||||
//!
|
||||
//! ## 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`]: crate::Subscriber
|
||||
//! [`with_default`]: with_default
|
||||
//! [`set_global_default`]: set_global_default
|
||||
//! [`get_default`]: get_default
|
||||
//! [`Dispatch`]: Dispatch
|
||||
#[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;
|
||||
170
zeroidc/vendor/tracing/src/field.rs
vendored
Normal file
170
zeroidc/vendor/tracing/src/field.rs
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
//! `Span` and `Event` key-value data.
|
||||
//!
|
||||
//! Spans and events may be annotated with key-value data, referred to as known
|
||||
//! as _fields_. These fields consist of a mapping from a key (corresponding to
|
||||
//! a `&str` but represented internally as an array index) to a [`Value`].
|
||||
//!
|
||||
//! # `Value`s and `Subscriber`s
|
||||
//!
|
||||
//! `Subscriber`s consume `Value`s as fields attached to [span]s or [`Event`]s.
|
||||
//! The set of field keys on a given span or is defined on its [`Metadata`].
|
||||
//! When a span is created, it provides [`Attributes`] to the `Subscriber`'s
|
||||
//! [`new_span`] method, containing any fields whose values were provided when
|
||||
//! the span was created; and may call the `Subscriber`'s [`record`] method
|
||||
//! with additional [`Record`]s if values are added for more of its fields.
|
||||
//! Similarly, the [`Event`] type passed to the subscriber's [`event`] method
|
||||
//! will contain any fields attached to each event.
|
||||
//!
|
||||
//! `tracing` represents values as either one of a set of Rust primitives
|
||||
//! (`i64`, `u64`, `f64`, `bool`, and `&str`) or using a `fmt::Display` or
|
||||
//! `fmt::Debug` implementation. `Subscriber`s are provided these primitive
|
||||
//! value types as `dyn Value` trait objects.
|
||||
//!
|
||||
//! These trait objects can be formatted using `fmt::Debug`, but may also be
|
||||
//! recorded as typed data by calling the [`Value::record`] method on these
|
||||
//! trait objects with a _visitor_ implementing the [`Visit`] trait. This trait
|
||||
//! represents the behavior used to record values of various types. For example,
|
||||
//! an implementation of `Visit` might record integers by incrementing counters
|
||||
//! for their field names rather than printing them.
|
||||
//!
|
||||
//!
|
||||
//! # Using `valuable`
|
||||
//!
|
||||
//! `tracing`'s [`Value`] trait is intentionally minimalist: it supports only a small
|
||||
//! number of Rust primitives as typed values, and only permits recording
|
||||
//! user-defined types with their [`fmt::Debug`] or [`fmt::Display`]
|
||||
//! implementations. However, there are some cases where it may be useful to record
|
||||
//! nested values (such as arrays, `Vec`s, or `HashMap`s containing values), or
|
||||
//! user-defined `struct` and `enum` types without having to format them as
|
||||
//! unstructured text.
|
||||
//!
|
||||
//! To address `Value`'s limitations, `tracing` offers experimental support for
|
||||
//! the [`valuable`] crate, which provides object-safe inspection of structured
|
||||
//! values. User-defined types can implement the [`valuable::Valuable`] trait,
|
||||
//! and be recorded as a `tracing` field by calling their [`as_value`] method.
|
||||
//! If the [`Subscriber`] also supports the `valuable` crate, it can
|
||||
//! then visit those types fields as structured values using `valuable`.
|
||||
//!
|
||||
//! <pre class="ignore" style="white-space:normal;font:inherit;">
|
||||
//! <strong>Note</strong>: <code>valuable</code> support is an
|
||||
//! <a href = "../index.html#unstable-features">unstable feature</a>. See
|
||||
//! the documentation on unstable features for details on how to enable it.
|
||||
//! </pre>
|
||||
//!
|
||||
//! For example:
|
||||
//! ```ignore
|
||||
//! // Derive `Valuable` for our types:
|
||||
//! use valuable::Valuable;
|
||||
//!
|
||||
//! #[derive(Clone, Debug, Valuable)]
|
||||
//! struct User {
|
||||
//! name: String,
|
||||
//! age: u32,
|
||||
//! address: Address,
|
||||
//! }
|
||||
//!
|
||||
//! #[derive(Clone, Debug, Valuable)]
|
||||
//! struct Address {
|
||||
//! country: String,
|
||||
//! city: String,
|
||||
//! street: String,
|
||||
//! }
|
||||
//!
|
||||
//! let user = User {
|
||||
//! name: "Arwen Undomiel".to_string(),
|
||||
//! age: 3000,
|
||||
//! address: Address {
|
||||
//! country: "Middle Earth".to_string(),
|
||||
//! city: "Rivendell".to_string(),
|
||||
//! street: "leafy lane".to_string(),
|
||||
//! },
|
||||
//! };
|
||||
//!
|
||||
//! // Recording `user` as a `valuable::Value` will allow the `tracing` subscriber
|
||||
//! // to traverse its fields as a nested, typed structure:
|
||||
//! tracing::info!(current_user = user.as_value());
|
||||
//! ```
|
||||
//!
|
||||
//! Alternatively, the [`valuable()`] function may be used to convert a type
|
||||
//! implementing [`Valuable`] into a `tracing` field value.
|
||||
//!
|
||||
//! When the `valuable` feature is enabled, the [`Visit`] trait will include an
|
||||
//! optional [`record_value`] method. `Visit` implementations that wish to
|
||||
//! record `valuable` values can implement this method with custom behavior.
|
||||
//! If a visitor does not implement `record_value`, the [`valuable::Value`] will
|
||||
//! be forwarded to the visitor's [`record_debug`] method.
|
||||
//!
|
||||
//! [`fmt::Debug`]: std::fmt::Debug
|
||||
//! [`fmt::Display`]: std::fmt::Debug
|
||||
//! [`valuable`]: https://crates.io/crates/valuable
|
||||
//! [`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
|
||||
//! [`as_value`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html#tymethod.as_value
|
||||
//! [`valuable::Value`]: https://docs.rs/valuable/latest/valuable/enum.Value.html
|
||||
//! [`Subscriber`]: crate::Subscriber
|
||||
//! [`record_value`]: Visit::record_value
|
||||
//! [`record_debug`]: Visit::record_debug
|
||||
//! [span]: mod@crate::span
|
||||
//! [`Event`]: crate::event::Event
|
||||
//! [`Metadata`]: crate::Metadata
|
||||
//! [`Attributes`]: crate::span::Attributes
|
||||
//! [`Record`]: crate::span::Record
|
||||
//! [`new_span`]: crate::Subscriber::new_span
|
||||
//! [`record`]: crate::Subscriber::record
|
||||
//! [`event`]: crate::Subscriber::event
|
||||
pub use tracing_core::field::*;
|
||||
|
||||
use crate::Metadata;
|
||||
|
||||
/// Trait implemented to allow a type to be used as a field key.
|
||||
///
|
||||
/// <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 {}
|
||||
370
zeroidc/vendor/tracing/src/instrument.rs
vendored
Normal file
370
zeroidc/vendor/tracing/src/instrument.rs
vendored
Normal file
@@ -0,0 +1,370 @@
|
||||
use crate::stdlib::pin::Pin;
|
||||
use crate::stdlib::task::{Context, Poll};
|
||||
use crate::stdlib::{future::Future, marker::Sized};
|
||||
use crate::{
|
||||
dispatcher::{self, Dispatch},
|
||||
span::Span,
|
||||
};
|
||||
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]: super::Span
|
||||
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
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// The [`Span::or_current`] combinator can be used in combination with
|
||||
/// `instrument` to ensure that the [current span] is attached to the
|
||||
/// future if the span passed to `instrument` is [disabled]:
|
||||
///
|
||||
/// ```
|
||||
/// use tracing::Instrument;
|
||||
/// # mod tokio {
|
||||
/// # pub(super) fn spawn(_: impl std::future::Future) {}
|
||||
/// # }
|
||||
///
|
||||
/// let my_future = async {
|
||||
/// // ...
|
||||
/// };
|
||||
///
|
||||
/// let outer_span = tracing::info_span!("outer").entered();
|
||||
///
|
||||
/// // If the "my_future" span is enabled, then the spawned task will
|
||||
/// // be within both "my_future" *and* "outer", since "outer" is
|
||||
/// // "my_future"'s parent. However, if "my_future" is disabled,
|
||||
/// // the spawned task will *not* be in any span.
|
||||
/// tokio::spawn(
|
||||
/// my_future
|
||||
/// .instrument(tracing::debug_span!("my_future"))
|
||||
/// );
|
||||
///
|
||||
/// // Using `Span::or_current` ensures the spawned task is instrumented
|
||||
/// // with the current span, if the new span passed to `instrument` is
|
||||
/// // not enabled. This means that if the "my_future" span is disabled,
|
||||
/// // the spawned task will still be instrumented with the "outer" span:
|
||||
/// # let my_future = async {};
|
||||
/// tokio::spawn(
|
||||
/// my_future
|
||||
/// .instrument(tracing::debug_span!("my_future").or_current())
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// [entered]: super::Span::enter()
|
||||
/// [`Span::or_current`]: super::Span::or_current()
|
||||
/// [current span]: super::Span::current()
|
||||
/// [disabled]: super::Span::is_disabled()
|
||||
/// [`Future`]: std::future::Future
|
||||
fn instrument(self, span: Span) -> Instrumented<Self> {
|
||||
Instrumented { inner: self, span }
|
||||
}
|
||||
|
||||
/// Instruments this type with the [current] [`Span`], returning an
|
||||
/// `Instrumented` wrapper.
|
||||
///
|
||||
/// The attached [`Span`] will be [entered] every time the instrumented
|
||||
/// [`Future`] is polled.
|
||||
///
|
||||
/// This can be used to propagate the current span when spawning a new future.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use tracing::Instrument;
|
||||
///
|
||||
/// # mod tokio {
|
||||
/// # pub(super) fn spawn(_: impl std::future::Future) {}
|
||||
/// # }
|
||||
/// # 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]: super::Span::current()
|
||||
/// [entered]: super::Span::enter()
|
||||
/// [`Span`]: crate::Span
|
||||
/// [`Future`]: std::future::Future
|
||||
#[inline]
|
||||
fn in_current_span(self) -> Instrumented<Self> {
|
||||
self.instrument(Span::current())
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait allowing futures to be instrumented with
|
||||
/// a `tracing` [`Subscriber`](crate::Subscriber).
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
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.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use tracing::subscriber::NoSubscriber as MySubscriber;
|
||||
/// # use tracing::subscriber::NoSubscriber as MyOtherSubscriber;
|
||||
/// # async fn docs() {
|
||||
/// use tracing::instrument::WithSubscriber;
|
||||
///
|
||||
/// // Set the default `Subscriber`
|
||||
/// let _default = tracing::subscriber::set_default(MySubscriber::default());
|
||||
///
|
||||
/// tracing::info!("this event will be recorded by the default `Subscriber`");
|
||||
///
|
||||
/// // Create a different `Subscriber` and attach it to a future.
|
||||
/// let other_subscriber = MyOtherSubscriber::default();
|
||||
/// let future = async {
|
||||
/// tracing::info!("this event will be recorded by the other `Subscriber`");
|
||||
/// // ...
|
||||
/// };
|
||||
///
|
||||
/// future
|
||||
/// // Attach the other `Subscriber` to the future before awaiting it
|
||||
/// .with_subscriber(other_subscriber)
|
||||
/// .await;
|
||||
///
|
||||
/// // Once the future has completed, we return to the default `Subscriber`.
|
||||
/// tracing::info!("this event will be recorded by the default `Subscriber`");
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// [`Subscriber`]: super::Subscriber
|
||||
/// [default]: crate::dispatcher#setting-the-default-subscriber
|
||||
/// [`Future`]: std::future::Future
|
||||
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
|
||||
where
|
||||
S: Into<Dispatch>,
|
||||
{
|
||||
WithDispatch {
|
||||
inner: self,
|
||||
dispatcher: subscriber.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Attaches the current [default] [`Subscriber`] to this type, returning a
|
||||
/// [`WithDispatch`] wrapper.
|
||||
///
|
||||
/// The attached `Subscriber` will be set as the [default] when the returned
|
||||
/// [`Future`] is polled.
|
||||
///
|
||||
/// This can be used to propagate the current dispatcher context when
|
||||
/// spawning a new future that may run on a different thread.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # mod tokio {
|
||||
/// # pub(super) fn spawn(_: impl std::future::Future) {}
|
||||
/// # }
|
||||
/// # use tracing::subscriber::NoSubscriber as MySubscriber;
|
||||
/// # async fn docs() {
|
||||
/// use tracing::instrument::WithSubscriber;
|
||||
///
|
||||
/// // Using `set_default` (rather than `set_global_default`) sets the
|
||||
/// // default `Subscriber` for *this* thread only.
|
||||
/// let _default = tracing::subscriber::set_default(MySubscriber::default());
|
||||
///
|
||||
/// let future = async {
|
||||
/// // ...
|
||||
/// };
|
||||
///
|
||||
/// // If a multi-threaded async runtime is in use, this spawned task may
|
||||
/// // run on a different thread, in a different default `Subscriber`'s context.
|
||||
/// tokio::spawn(future);
|
||||
///
|
||||
/// // However, calling `with_current_subscriber` on the future before
|
||||
/// // spawning it, ensures that the current thread's default `Subscriber` is
|
||||
/// // propagated to the spawned task, regardless of where it executes:
|
||||
/// # let future = async { };
|
||||
/// tokio::spawn(future.with_current_subscriber());
|
||||
/// # }
|
||||
/// ```
|
||||
/// [`Subscriber`]: super::Subscriber
|
||||
/// [default]: crate::dispatcher#setting-the-default-subscriber
|
||||
/// [`Future`]: std::future::Future
|
||||
#[inline]
|
||||
fn with_current_subscriber(self) -> WithDispatch<Self> {
|
||||
WithDispatch {
|
||||
inner: self,
|
||||
dispatcher: crate::dispatcher::get_default(|default| default.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
/// A [`Future`] that has been instrumented with a `tracing` [`Subscriber`].
|
||||
///
|
||||
/// This type is returned by the [`WithSubscriber`] extension trait. See that
|
||||
/// trait's documentation for details.
|
||||
///
|
||||
/// [`Future`]: std::future::Future
|
||||
/// [`Subscriber`]: crate::Subscriber
|
||||
#[derive(Clone, Debug)]
|
||||
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
pub struct WithDispatch<T> {
|
||||
#[pin]
|
||||
inner: T,
|
||||
dispatcher: Dispatch,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
/// A [`Future`] that has been instrumented with a `tracing` [`Span`].
|
||||
///
|
||||
/// This type is returned by the [`Instrument`] extension trait. See that
|
||||
/// trait's documentation for details.
|
||||
///
|
||||
/// [`Future`]: std::future::Future
|
||||
/// [`Span`]: crate::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 Instrumented ===
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// === impl WithDispatch ===
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<T: Future> Future for WithDispatch<T> {
|
||||
type Output = T::Output;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.project();
|
||||
let dispatcher = this.dispatcher;
|
||||
let future = this.inner;
|
||||
let _default = dispatcher::set_default(dispatcher);
|
||||
future.poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<T: Sized> WithSubscriber for T {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<T> WithDispatch<T> {
|
||||
/// Borrows the [`Dispatch`] that is entered when this type is polled.
|
||||
pub fn dispatcher(&self) -> &Dispatch {
|
||||
&self.dispatcher
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
94
zeroidc/vendor/tracing/src/level_filters.rs
vendored
Normal file
94
zeroidc/vendor/tracing/src/level_filters.rs
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
//! 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"] }
|
||||
//! ```
|
||||
//! ## Notes
|
||||
//!
|
||||
//! Please note that `tracing`'s static max level features do *not* control the
|
||||
//! [`log`] records that may be emitted when [`tracing`'s "log" feature flag][f] is
|
||||
//! enabled. This is to allow `tracing` to be disabled entirely at compile time
|
||||
//! while still emitting `log` records --- such as when a library using
|
||||
//! `tracing` is used by an application using `log` that doesn't want to
|
||||
//! generate any `tracing`-related code, but does want to collect `log` records.
|
||||
//!
|
||||
//! This means that if the "log" feature is in use, some code may be generated
|
||||
//! for `log` records emitted by disabled `tracing` events. If this is not
|
||||
//! desirable, `log` records may be disabled separately using [`log`'s static
|
||||
//! max level features][`log` crate].
|
||||
//!
|
||||
//! [`log`]: https://docs.rs/log/
|
||||
//! [`log` crate]: https://docs.rs/log/latest/log/#compile-time-filters
|
||||
//! [f]: https://docs.rs/tracing/latest/tracing/#emitting-log-records
|
||||
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]: super#compile-time-filters
|
||||
pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL;
|
||||
|
||||
cfg_if::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;
|
||||
}
|
||||
}
|
||||
1183
zeroidc/vendor/tracing/src/lib.rs
vendored
Normal file
1183
zeroidc/vendor/tracing/src/lib.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2500
zeroidc/vendor/tracing/src/macros.rs
vendored
Normal file
2500
zeroidc/vendor/tracing/src/macros.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1617
zeroidc/vendor/tracing/src/span.rs
vendored
Normal file
1617
zeroidc/vendor/tracing/src/span.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
55
zeroidc/vendor/tracing/src/stdlib.rs
vendored
Normal file
55
zeroidc/vendor/tracing/src/stdlib.rs
vendored
Normal file
@@ -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::*;
|
||||
}
|
||||
}
|
||||
68
zeroidc/vendor/tracing/src/subscriber.rs
vendored
Normal file
68
zeroidc/vendor/tracing/src/subscriber.rs
vendored
Normal file
@@ -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`]: super::span::Span
|
||||
/// [`Subscriber`]: super::subscriber::Subscriber
|
||||
/// [`Event`]: super::event::Event
|
||||
#[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]: super::span
|
||||
/// [`Subscriber`]: super::subscriber::Subscriber
|
||||
/// [`Event`]: super::event::Event
|
||||
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`]: super::span::Span
|
||||
/// [`Subscriber`]: super::subscriber::Subscriber
|
||||
/// [`Event`]: super::event::Event
|
||||
/// [`DefaultGuard`]: super::dispatcher::DefaultGuard
|
||||
#[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;
|
||||
Reference in New Issue
Block a user