1 //! Core primitives for `tracing`.
3 //! [`tracing`] is a framework for instrumenting Rust programs to collect
4 //! structured, event-based diagnostic information. This crate defines the core
5 //! primitives of `tracing`.
7 //! This crate provides:
9 //! * [`span::Id`] identifies a span within the execution of a program.
11 //! * [`Event`] represents a single event within a trace.
13 //! * [`Subscriber`], the trait implemented to collect trace data.
15 //! * [`Metadata`] and [`Callsite`] provide information describing spans and
18 //! * [`Field`], [`FieldSet`], [`Value`], and [`ValueSet`] represent the
19 //! structured data attached to a span.
21 //! * [`Dispatch`] allows spans and events to be dispatched to `Subscriber`s.
23 //! In addition, it defines the global callsite registry and per-thread current
24 //! dispatcher which other components of the tracing system rely on.
26 //! *Compiler support: [requires `rustc` 1.40+][msrv]*
28 //! [msrv]: #supported-rust-versions
32 //! Application authors will typically not use this crate directly. Instead,
33 //! they will use the [`tracing`] crate, which provides a much more
34 //! fully-featured API. However, this crate's API will change very infrequently,
35 //! so it may be used when dependencies must be very stable.
37 //! `Subscriber` implementations may depend on `tracing-core` rather than
38 //! `tracing`, as the additional APIs provided by `tracing` are primarily useful
39 //! for instrumenting libraries and applications, and are generally not
40 //! necessary for `Subscriber` implementations.
42 //! The [`tokio-rs/tracing`] repository contains less stable crates designed to
43 //! be used with the `tracing` ecosystem. It includes a collection of
44 //! `Subscriber` implementations, as well as utility and adapter crates.
46 //! ### Crate Feature Flags
48 //! The following crate feature flags are available:
50 //! * `std`: Depend on the Rust standard library (enabled by default).
52 //! `no_std` users may disable this feature with `default-features = false`:
56 //! tracing-core = { version = "0.1.16", default-features = false }
59 //! **Note**:`tracing-core`'s `no_std` support requires `liballoc`.
61 //! ## Supported Rust Versions
63 //! Tracing is built against the latest stable release. The minimum supported
64 //! version is 1.40. The current Tracing version is not guaranteed to build on
65 //! Rust versions earlier than the minimum supported version.
67 //! Tracing follows the same compiler support policies as the rest of the Tokio
68 //! project. The current stable Rust compiler and the three most recent minor
69 //! versions before it will always be supported. For example, if the current
70 //! stable compiler version is 1.45, the minimum supported version will not be
71 //! increased past 1.42, three minor versions prior. Increasing the minimum
72 //! supported compiler version is not considered a semver breaking change as
73 //! long as doing so complies with this policy.
76 //! [`span::Id`]: span/struct.Id.html
77 //! [`Event`]: event/struct.Event.html
78 //! [`Subscriber`]: subscriber/trait.Subscriber.html
79 //! [`Metadata`]: metadata/struct.Metadata.html
80 //! [`Callsite`]: callsite/trait.Callsite.html
81 //! [`Field`]: field/struct.Field.html
82 //! [`FieldSet`]: field/struct.FieldSet.html
83 //! [`Value`]: field/trait.Value.html
84 //! [`ValueSet`]: field/struct.ValueSet.html
85 //! [`Dispatch`]: dispatcher/struct.Dispatch.html
86 //! [`tokio-rs/tracing`]: https://github.com/tokio-rs/tracing
87 //! [`tracing`]: https://crates.io/crates/tracing
88 #![doc(html_root_url = "https://docs.rs/tracing-core/0.1.16")]
90 html_logo_url
= "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
91 issue_tracker_base_url
= "https://github.com/tokio-rs/tracing/issues/"
93 #![cfg_attr(not(feature = "std"), no_std)]
94 #![cfg_attr(docsrs, feature(doc_cfg))]
96 missing_debug_implementations
,
104 non_shorthand_field_patterns
,
105 no_mangle_generic_items
,
106 overflowing_literals
,
108 patterns_in_fns_without_body
,
110 unconditional_recursion
,
117 #[cfg(not(feature = "std"))]
120 /// Statically constructs an [`Identifier`] for the provided [`Callsite`].
122 /// This may be used in contexts, such as static initializers, where the
123 /// [`Callsite::id`] function is not currently usable.
128 /// # extern crate tracing_core;
129 /// use tracing_core::callsite;
130 /// # use tracing_core::{Metadata, subscriber::Interest};
132 /// pub struct MyCallsite {
135 /// impl callsite::Callsite for MyCallsite {
136 /// # fn set_interest(&self, _: Interest) { unimplemented!() }
137 /// # fn metadata(&self) -> &Metadata { unimplemented!() }
141 /// static CALLSITE: MyCallsite = MyCallsite {
145 /// static CALLSITE_ID: callsite::Identifier = identify_callsite!(&CALLSITE);
149 /// [`Identifier`]: callsite/struct.Identifier.html
150 /// [`Callsite`]: callsite/trait.Callsite.html
151 /// [`Callsite::id`]: callsite/trait.Callsite.html#method.id
153 macro_rules
! identify_callsite
{
154 ($callsite
:expr
) => {
155 $
crate::callsite
::Identifier($callsite
)
159 /// Statically constructs new span [metadata].
164 /// # extern crate tracing_core;
165 /// # use tracing_core::{callsite::Callsite, subscriber::Interest};
166 /// use tracing_core::metadata::{Kind, Level, Metadata};
168 /// # pub struct MyCallsite { }
169 /// # impl Callsite for MyCallsite {
170 /// # fn set_interest(&self, _: Interest) { unimplemented!() }
171 /// # fn metadata(&self) -> &Metadata { unimplemented!() }
174 /// static FOO_CALLSITE: MyCallsite = MyCallsite {
178 /// static FOO_METADATA: Metadata = metadata!{
180 /// target: module_path!(),
181 /// level: Level::DEBUG,
182 /// fields: &["bar", "baz"],
183 /// callsite: &FOO_CALLSITE,
184 /// kind: Kind::SPAN,
189 /// [metadata]: metadata/struct.Metadata.html
190 /// [`Metadata::new`]: metadata/struct.Metadata.html#method.new
192 macro_rules
! metadata
{
195 target
: $target
:expr
,
197 fields
: $fields
:expr
,
198 callsite
: $callsite
:expr
,
212 target
: $target
:expr
,
214 fields
: $fields
:expr
,
215 callsite
: $callsite
:expr
,
218 $
crate::metadata
::Metadata
::new(
224 Some(module_path
!()),
225 $
crate::field
::FieldSet
::new($fields
, $
crate::identify_callsite
!($callsite
)),
231 // std uses lazy_static from crates.io
232 #[cfg(feature = "std")]
234 extern crate lazy_static
;
236 // no_std uses vendored version of lazy_static 1.4.0 (4216696) with spin
237 // This can conflict when included in a project already using std lazy_static
238 // Remove this module when cargo enables specifying dependencies for no_std
239 #[cfg(not(feature = "std"))]
243 // Trimmed-down vendored version of spin 0.5.2 (0387621)
244 // Dependency of no_std lazy_static, not required in a std build
245 #[cfg(not(feature = "std"))]
248 #[cfg(not(feature = "std"))]
250 pub type Once
= self::spin
::Once
<()>;
252 #[cfg(feature = "std")]
253 pub use stdlib
::sync
::Once
;
262 pub(crate) mod stdlib
;
268 dispatcher
::Dispatch
,
271 metadata
::{Level, LevelFilter, Metadata}
,
272 subscriber
::Subscriber
,
275 pub use self::{metadata::Kind, subscriber::Interest}
;