зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1785002 - Update tracing to 0.1.36. r=emilio,supply-chain-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D154757
This commit is contained in:
Родитель
89755616b7
Коммит
9e481b1841
|
@ -5429,9 +5429,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
|
|||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.35"
|
||||
version = "0.1.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
|
||||
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"log",
|
||||
|
@ -5442,9 +5442,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.21"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c"
|
||||
checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -5453,9 +5453,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.27"
|
||||
version = "0.1.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921"
|
||||
checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
|
|
@ -660,6 +660,21 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
|
|||
criteria = "safe-to-run"
|
||||
delta = "0.3.1 -> 0.3.2"
|
||||
|
||||
[[audits.tracing]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-run"
|
||||
delta = "0.1.35 -> 0.1.36"
|
||||
|
||||
[[audits.tracing-attributes]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-run"
|
||||
delta = "0.1.21 -> 0.1.22"
|
||||
|
||||
[[audits.tracing-core]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-run"
|
||||
delta = "0.1.27 -> 0.1.29"
|
||||
|
||||
[[audits.tracy-rs]]
|
||||
who = "Glenn Watson <git@intuitionlibrary.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"CHANGELOG.md":"a41cefad0d01fc385c212e5160b4b11bc7a87e3be3f211af17396bb4a7865abb","Cargo.toml":"253511713d185e130c9c15f037445c17776427c3588621d7972abb0c2db5b866","LICENSE":"898b1ae9821e98daf8964c8d6c7f61641f5f5aa78ad500020771c0939ee0dea1","README.md":"a0e6d8ad2f6071cd53539bfe6d6f011c1dd07a31872be014f43b7a36860b3c7e","src/attr.rs":"4d26dad70c765fff3d4677ebe8e71b63599d67ceba5c48dbcb204d247b5394ce","src/expand.rs":"0e30aec264f96e2388787aa346b94f004cb7cfa6d7187e256b335ce9a449606b","src/lib.rs":"8f6382c2c4622cd2f5478943ca228ad2cf335dcb35f16a900cb8960b8bffa78c","tests/async_fn.rs":"74126e6027bc9cb6e5e3d5d0e3b2debd5c808c737d25b90303b8e3ca878a3667","tests/destructuring.rs":"26b9800678bad09e06512a113a54556e2fac3ecb15a18dcccefe105fb8911c26","tests/err.rs":"bed4968c19f833f67464e2270bd9b05bf21fffefa1056770c634f161cb5fa5f1","tests/fields.rs":"e18f157a80bd3cee68d9dd96106b060652d4d94dabdd99e721c54851745b23f9","tests/follows_from.rs":"5bc856923e87b34e0558959149118238fe668ac621f1748cc444c21c90a86647","tests/instrument.rs":"9118eb6971d19a6b8d301bb4512b0fda909404a21e14edbef6b01db094cd8aaf","tests/levels.rs":"80ffb684163a4d28c69c40e31a82609ac02daf922086bab8247bca125aec3c69","tests/names.rs":"5afd6c4d526588bcea3141c130a45a21872956495b6868a01b44ddff57749827","tests/parents.rs":"673d3f81eed6ba433f685ec53fd007c5dd957b97d32499d7ea1537e1f289cb2e","tests/ret.rs":"bfd71022dbd9f9149152d13d99278e8adb0be8ae2fe8208611576d3a76359e08","tests/targets.rs":"95ce1ce1e2d29794062c5b3429d91c1bfaba5813251d5d8440c12cb2db6e11bf"},"package":"cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c"}
|
||||
{"files":{"CHANGELOG.md":"daa6621db253ddaaa095d297d0de2be41b03831a3992f2f9a5107749a689983e","Cargo.toml":"70c8c7dba6890f42c7830651ec9847c0e22b4c0987024d076d4abb3801f26bc8","LICENSE":"898b1ae9821e98daf8964c8d6c7f61641f5f5aa78ad500020771c0939ee0dea1","README.md":"7484033338a94e5ce23f1b281e1bdef1bae590c2329bd9b4d192ce66702e3a31","src/attr.rs":"4d26dad70c765fff3d4677ebe8e71b63599d67ceba5c48dbcb204d247b5394ce","src/expand.rs":"e6b81defa4ed98d71466ede6eb5a8f613cd0d33750b2e1274265467b85756362","src/lib.rs":"4400f3c00b7b4daf9cd61bec3e1f5d794c3d4b131667252a43c95a40041b6711","tests/async_fn.rs":"74126e6027bc9cb6e5e3d5d0e3b2debd5c808c737d25b90303b8e3ca878a3667","tests/destructuring.rs":"26b9800678bad09e06512a113a54556e2fac3ecb15a18dcccefe105fb8911c26","tests/err.rs":"3beb5f065e57a578825c383a56b9d64fb89794a508018bf36e16f113557909b8","tests/fields.rs":"3882bd4e744d6b492f59beac7475e8bf4ff4ca8ad85c6951c305a22c78e75fae","tests/follows_from.rs":"5bc856923e87b34e0558959149118238fe668ac621f1748cc444c21c90a86647","tests/instrument.rs":"9118eb6971d19a6b8d301bb4512b0fda909404a21e14edbef6b01db094cd8aaf","tests/levels.rs":"80ffb684163a4d28c69c40e31a82609ac02daf922086bab8247bca125aec3c69","tests/names.rs":"5afd6c4d526588bcea3141c130a45a21872956495b6868a01b44ddff57749827","tests/parents.rs":"673d3f81eed6ba433f685ec53fd007c5dd957b97d32499d7ea1537e1f289cb2e","tests/ret.rs":"083b4ca456d766c469b2fff7608b59524b422941e5c5e84f07c1ce0d7b345c7a","tests/targets.rs":"95ce1ce1e2d29794062c5b3429d91c1bfaba5813251d5d8440c12cb2db6e11bf"},"package":"11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"}
|
|
@ -1,3 +1,26 @@
|
|||
# 0.1.22 (July 1, 2022)
|
||||
|
||||
This release fixes an issue where using the `err` or `ret` arguments to
|
||||
`#[instrument]` along with an overridden target, such as
|
||||
|
||||
```rust
|
||||
#[instrument(target = "...", err, ret)]
|
||||
```
|
||||
|
||||
would not propagate the overridden target to the events generated for
|
||||
errors/return values.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Error and return value events generated by `#[instrument(err)]` or
|
||||
`#[instrument(ret)]` not inheriting an overridden target ([#2184])
|
||||
- Incorrect default level in documentation ([#2119])
|
||||
|
||||
Thanks to new contributor @tbraun96 for contributing to this release!
|
||||
|
||||
[#2184]: https://github.com/tokio-rs/tracing/pull/2184
|
||||
[#2119]: https://github.com/tokio-rs/tracing/pull/2119
|
||||
|
||||
# 0.1.21 (April 26, 2022)
|
||||
|
||||
This release adds support for setting explicit parent and follows-from spans
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
edition = "2018"
|
||||
rust-version = "1.49.0"
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.21"
|
||||
version = "0.1.22"
|
||||
authors = [
|
||||
"Tokio Contributors <team@tokio.rs>",
|
||||
"Eliza Weisman <eliza@buoyant.io>",
|
||||
|
@ -66,7 +66,7 @@ default-features = false
|
|||
version = "0.1.44"
|
||||
|
||||
[dev-dependencies.tokio-test]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dev-dependencies.tracing]
|
||||
version = "0.1"
|
||||
|
@ -74,6 +74,10 @@ version = "0.1"
|
|||
[dev-dependencies.tracing-core]
|
||||
version = "0.1"
|
||||
|
||||
[dev-dependencies.tracing-subscriber]
|
||||
version = "0.3"
|
||||
features = ["env-filter"]
|
||||
|
||||
[features]
|
||||
async-await = []
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ Macro attributes for application-level tracing.
|
|||
[crates-badge]: https://img.shields.io/crates/v/tracing-attributes.svg
|
||||
[crates-url]: https://crates.io/crates/tracing-attributes
|
||||
[docs-badge]: https://docs.rs/tracing-attributes/badge.svg
|
||||
[docs-url]: https://docs.rs/tracing-attributes/0.1.21
|
||||
[docs-url]: https://docs.rs/tracing-attributes/0.1.22
|
||||
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue
|
||||
[docs-master-url]: https://tracing-rs.netlify.com/tracing_attributes
|
||||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
|
||||
|
@ -47,7 +47,7 @@ First, add this to your `Cargo.toml`:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
tracing-attributes = "0.1.21"
|
||||
tracing-attributes = "0.1.22"
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -200,19 +200,23 @@ fn gen_block<B: ToTokens>(
|
|||
))
|
||||
})();
|
||||
|
||||
let target = args.target();
|
||||
|
||||
let err_event = match args.err_mode {
|
||||
Some(FormatMode::Default) | Some(FormatMode::Display) => {
|
||||
Some(quote!(tracing::error!(error = %e)))
|
||||
Some(quote!(tracing::error!(target: #target, error = %e)))
|
||||
}
|
||||
Some(FormatMode::Debug) => Some(quote!(tracing::error!(error = ?e))),
|
||||
Some(FormatMode::Debug) => Some(quote!(tracing::error!(target: #target, error = ?e))),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let ret_event = match args.ret_mode {
|
||||
Some(FormatMode::Display) => Some(quote!(tracing::event!(#level, return = %x))),
|
||||
Some(FormatMode::Default) | Some(FormatMode::Debug) => {
|
||||
Some(quote!(tracing::event!(#level, return = ?x)))
|
||||
}
|
||||
Some(FormatMode::Display) => Some(quote!(
|
||||
tracing::event!(target: #target, #level, return = %x)
|
||||
)),
|
||||
Some(FormatMode::Default) | Some(FormatMode::Debug) => Some(quote!(
|
||||
tracing::event!(target: #target, #level, return = ?x)
|
||||
)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//!
|
||||
//! ```toml
|
||||
//! [dependencies]
|
||||
//! tracing-attributes = "0.1.21"
|
||||
//! tracing-attributes = "0.1.22"
|
||||
//! ```
|
||||
//!
|
||||
//! The [`#[instrument]`][instrument] attribute can now be added to a function
|
||||
|
@ -52,7 +52,7 @@
|
|||
//! supported compiler version is not considered a semver breaking change as
|
||||
//! long as doing so complies with this policy.
|
||||
//!
|
||||
#![doc(html_root_url = "https://docs.rs/tracing-attributes/0.1.21")]
|
||||
#![doc(html_root_url = "https://docs.rs/tracing-attributes/0.1.22")]
|
||||
#![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/"
|
||||
|
@ -93,7 +93,7 @@ mod expand;
|
|||
/// Instruments a function to create and enter a `tracing` [span] every time
|
||||
/// the function is called.
|
||||
///
|
||||
/// Unless overriden, a span with `info` level will be generated.
|
||||
/// Unless overriden, a span with the [`INFO`] [level] will be generated.
|
||||
/// The generated span's name will be the name of the function.
|
||||
/// By default, all arguments to the function are included as fields on the
|
||||
/// span. Arguments that are `tracing` [primitive types] implementing the
|
||||
|
@ -420,7 +420,7 @@ mod expand;
|
|||
/// }
|
||||
/// ```
|
||||
/// The return value event will have the same level as the span generated by `#[instrument]`.
|
||||
/// By default, this will be `TRACE`, but if the level is overridden, the event will be at the same
|
||||
/// By default, this will be [`INFO`], but if the level is overridden, the event will be at the same
|
||||
/// level.
|
||||
///
|
||||
/// **Note**: if the function returns a `Result<T, E>`, `ret` will record returned values if and
|
||||
|
@ -461,6 +461,9 @@ mod expand;
|
|||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// If a `target` is specified, both the `ret` and `err` arguments will emit outputs to
|
||||
/// the declared target (or the default channel if `target` is not specified).
|
||||
///
|
||||
/// The `ret` and `err` arguments can be combined in order to record an event if a
|
||||
/// function returns [`Result::Ok`] or [`Result::Err`]:
|
||||
///
|
||||
|
|
|
@ -2,6 +2,8 @@ use tracing::subscriber::with_default;
|
|||
use tracing::Level;
|
||||
use tracing_attributes::instrument;
|
||||
use tracing_mock::*;
|
||||
use tracing_subscriber::filter::EnvFilter;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::num::TryFromIntError;
|
||||
|
@ -198,3 +200,34 @@ fn test_err_display_default() {
|
|||
with_default(subscriber, || err().ok());
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_err_custom_target() {
|
||||
let filter: EnvFilter = "my_target=error".parse().expect("filter should parse");
|
||||
let span = span::mock().named("error_span").with_target("my_target");
|
||||
|
||||
let (subscriber, handle) = subscriber::mock()
|
||||
.new_span(span.clone())
|
||||
.enter(span.clone())
|
||||
.event(
|
||||
event::mock()
|
||||
.at_level(Level::ERROR)
|
||||
.with_target("my_target"),
|
||||
)
|
||||
.exit(span.clone())
|
||||
.drop_span(span)
|
||||
.done()
|
||||
.run_with_handle();
|
||||
|
||||
let subscriber = subscriber.with(filter);
|
||||
|
||||
with_default(subscriber, || {
|
||||
let error_span = tracing::error_span!(target: "my_target", "error_span");
|
||||
|
||||
{
|
||||
let _enter = error_span.enter();
|
||||
tracing::error!(target: "my_target", "This should display")
|
||||
}
|
||||
});
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@ fn fn_clashy_expr_field2(s: &str) {
|
|||
let _ = s;
|
||||
}
|
||||
|
||||
#[instrument(fields(s = &s))]
|
||||
fn fn_string(s: String) {
|
||||
let _ = s;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct HasField {
|
||||
my_field: &'static str,
|
||||
|
@ -134,6 +139,14 @@ fn empty_field() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_field() {
|
||||
let span = span::mock().with_field(mock("s").with_value(&"hello world").only());
|
||||
run_test(span, || {
|
||||
fn_string(String::from("hello world"));
|
||||
});
|
||||
}
|
||||
|
||||
fn run_test<F: FnOnce() -> T, T>(span: NewSpan, fun: F) {
|
||||
let (subscriber, handle) = subscriber::mock()
|
||||
.new_span(span)
|
||||
|
|
|
@ -4,12 +4,19 @@ use tracing_mock::*;
|
|||
|
||||
use tracing::{subscriber::with_default, Level};
|
||||
use tracing_attributes::instrument;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[instrument(ret)]
|
||||
fn ret() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
#[instrument(target = "my_target", ret)]
|
||||
fn ret_with_target() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
let span = span::mock().named("ret");
|
||||
|
@ -30,6 +37,33 @@ fn test() {
|
|||
handle.assert_finished();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_custom_target() {
|
||||
let filter: EnvFilter = "my_target=info".parse().expect("filter should parse");
|
||||
let span = span::mock()
|
||||
.named("ret_with_target")
|
||||
.with_target("my_target");
|
||||
|
||||
let (subscriber, handle) = subscriber::mock()
|
||||
.new_span(span.clone())
|
||||
.enter(span.clone())
|
||||
.event(
|
||||
event::mock()
|
||||
.with_fields(field::mock("return").with_value(&tracing::field::debug(42)))
|
||||
.at_level(Level::INFO)
|
||||
.with_target("my_target"),
|
||||
)
|
||||
.exit(span.clone())
|
||||
.drop_span(span)
|
||||
.done()
|
||||
.run_with_handle();
|
||||
|
||||
let subscriber = subscriber.with(filter);
|
||||
|
||||
with_default(subscriber, ret_with_target);
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
||||
#[instrument(level = "warn", ret)]
|
||||
fn ret_warn() -> i32 {
|
||||
42
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"CHANGELOG.md":"37c4bc613ee2bee4831f6422130468392ab0ba9a96a6f692f030eff1568d684b","Cargo.toml":"d0ec1fa23dfb63071b6a0e203a22dba4b55fdda01b644f172ebe5ec1d509efc5","LICENSE":"898b1ae9821e98daf8964c8d6c7f61641f5f5aa78ad500020771c0939ee0dea1","README.md":"c79162b3b8c9e5ab0035a62a98f77a1143ac4dd7309b55e691fa72fc51a7446d","src/callsite.rs":"38bcdde0e37c5c7c3657ab1197c1a569d96c885a7aa0374b409cba53c3a9921a","src/dispatcher.rs":"d346bad5456a79dbe7cd621feef4adb35d319115fc9ce9a2561083847916c684","src/event.rs":"f2673bf5d266972e567e521c9cd92fb33f28b0c7e010937e3bc2bf9eb483087f","src/field.rs":"bfd2a4e9982f0c9ce5db7635ac066917a01ca4a1dcfad5e96441b83a777c4b5a","src/lazy_static/LICENSE":"1e2391052f82d7b0111f512680dcbecf01b06842f5295833e7bd435be2b09a9b","src/lazy_static/core_lazy.rs":"b4c1aaec440177f0de3148fd7b5b60f052890267035966069e9d6a167a72af6a","src/lazy_static/mod.rs":"31abed65708c02b36ec4c72d0788b3fc18c684274ba943dc80fc9f2347f5fb2f","src/lib.rs":"f56fa036e9e0b6c4170ab8421bf06f933b5db5f2ddc4631872c17c44028dc141","src/metadata.rs":"1019ffecd3d8a3636708c6654f34074c041af88b6221c4950037c6bbf09af835","src/parent.rs":"5d5ad733343280a64a1feb6a008e186c39305ec554f14279012b8d7915821471","src/span.rs":"dcf2135e4ca158c1be45007f0be25426c375a4081f8f3c5a4d7f7382d8a950a4","src/spin/LICENSE":"58545fed1565e42d687aecec6897d35c6d37ccb71479a137c0deb2203e125c79","src/spin/mod.rs":"c458ce5e875acb7fbfb279f23254f4924d7c6d6fee419b740800d2e8087d1524","src/spin/mutex.rs":"4d30ff2b59b18fd7909f016e1abdf9aa0c04aa11d047a46e98cffe1319e32dad","src/spin/once.rs":"3781fd4eae0db04d80c03a039906c99b1e01d1583b29ac0144e6fbbd5a0fef0b","src/stdlib.rs":"491c9e37321798c86124c0690f7c5f29054bc444cc51406c36b6fdb106392303","src/subscriber.rs":"4e54bc5164e0b3fa17997b59c640c03192fda84f84b4f3e827899c955b8c343f","tests/common/mod.rs":"0bbb217baa17df0f96cc1ff57dfa74ccc5a959e7f66b15bb7d25d5f43358a278","tests/dispatch.rs":"d3f000fab43734a854c82a7783142910c5e79f806cbd3f8ec5eded598c59ddb1","tests/global_dispatch.rs":"cdc05d77e448ee8b50bfb930abafa3f19b4c6f922b7bebc7797fa1dbdaa1d398","tests/macros.rs":"b1603d888b349c8d103794deceec3b1ae4538b8d3eba805f3f561899e8ad0dd2"},"package":"7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921"}
|
||||
{"files":{"CHANGELOG.md":"10eae751c81a268b6118e2dea49d0d501ea4d2a69ece6350232f3800407ab2d3","Cargo.toml":"d29fae6d4ae043c79697e4305224fb8f65279515e1db6ad1211ccd27d073287f","LICENSE":"898b1ae9821e98daf8964c8d6c7f61641f5f5aa78ad500020771c0939ee0dea1","README.md":"f40e479c4d837f4fec140b0f4adad7aae062d55b53708f2255b93217f19d22a9","src/callsite.rs":"f5e9cdaed7fdc75dad5da6486af0ea6e9be896ab5fc1b44c49a90b8b88b33d53","src/dispatcher.rs":"1d129a0c3af976669787733101c2ce7d2f9eca794deeb2ae5a662085e966e0cf","src/event.rs":"f2673bf5d266972e567e521c9cd92fb33f28b0c7e010937e3bc2bf9eb483087f","src/field.rs":"4ec913012ffcf05d3feba2a5ea2ba99c35e2072dabfa2db75614c0e122961b7e","src/lazy.rs":"318e3558e4446abf26294287167c0788e343044a28072f9217bd985929809087","src/lib.rs":"088b29ecce4bdb5b68df9cbe3984f4b22d7124988866d5aace0e7029ea033d58","src/metadata.rs":"1a79326aee210b9e20eb08d5baa22133390f2b1e868cf4dc72a3e9bc9a37d17f","src/parent.rs":"5d5ad733343280a64a1feb6a008e186c39305ec554f14279012b8d7915821471","src/span.rs":"dcf2135e4ca158c1be45007f0be25426c375a4081f8f3c5a4d7f7382d8a950a4","src/spin/LICENSE":"58545fed1565e42d687aecec6897d35c6d37ccb71479a137c0deb2203e125c79","src/spin/mod.rs":"c458ce5e875acb7fbfb279f23254f4924d7c6d6fee419b740800d2e8087d1524","src/spin/mutex.rs":"4d30ff2b59b18fd7909f016e1abdf9aa0c04aa11d047a46e98cffe1319e32dad","src/spin/once.rs":"3781fd4eae0db04d80c03a039906c99b1e01d1583b29ac0144e6fbbd5a0fef0b","src/stdlib.rs":"698693062b8109cace3ffea02e9c2372b7d5b5d43c0b11cb4800b0e7b1a69971","src/subscriber.rs":"916d315ca324a752f70fc3cc557089418a63779ceda54955f55f0ab3c1f3fc7b","tests/common/mod.rs":"0bbb217baa17df0f96cc1ff57dfa74ccc5a959e7f66b15bb7d25d5f43358a278","tests/dispatch.rs":"d3f000fab43734a854c82a7783142910c5e79f806cbd3f8ec5eded598c59ddb1","tests/global_dispatch.rs":"cdc05d77e448ee8b50bfb930abafa3f19b4c6f922b7bebc7797fa1dbdaa1d398","tests/macros.rs":"b1603d888b349c8d103794deceec3b1ae4538b8d3eba805f3f561899e8ad0dd2"},"package":"5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7"}
|
|
@ -1,3 +1,52 @@
|
|||
# 0.1.29 (July 29, 2022)
|
||||
|
||||
This release of `tracing-core` adds `PartialEq` and `Eq` implementations for
|
||||
metadata types, and improves error messages when setting the global default
|
||||
subscriber fails.
|
||||
|
||||
### Added
|
||||
|
||||
- `PartialEq` and `Eq` implementations for `Metadata` ([#2229])
|
||||
- `PartialEq` and `Eq` implementations for `FieldSet` ([#2229])
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed unhelpful `fmt::Debug` output for `dispatcher::SetGlobalDefaultError`
|
||||
([#2250])
|
||||
- Fixed compilation with `-Z minimal-versions` ([#2246])
|
||||
|
||||
Thanks to @jswrenn and @CAD97 for contributing to this release!
|
||||
|
||||
[#2229]: https://github.com/tokio-rs/tracing/pull/2229
|
||||
[#2246]: https://github.com/tokio-rs/tracing/pull/2246
|
||||
[#2250]: https://github.com/tokio-rs/tracing/pull/2250
|
||||
|
||||
# 0.1.28 (June 23, 2022)
|
||||
|
||||
This release of `tracing-core` adds new `Value` implementations, including one
|
||||
for `String`, to allow recording `&String` as a value without having to call
|
||||
`as_str()` or similar, and for 128-bit integers (`i128` and `u128`). In
|
||||
addition, it adds new methods and trait implementations for `Subscriber`s.
|
||||
|
||||
### Added
|
||||
|
||||
- `Value` implementation for `String` ([#2164])
|
||||
- `Value` implementation for `u128` and `i28` ([#2166])
|
||||
- `downcast_ref` and `is` methods for `dyn Subscriber + Sync`,
|
||||
`dyn Subscriber + Send`, and `dyn Subscriber + Send + Sync` ([#2160])
|
||||
- `Subscriber::event_enabled` method to enable filtering based on `Event` field
|
||||
values ([#2008])
|
||||
- `Subscriber` implementation for `Box<S: Subscriber + ?Sized>` and
|
||||
`Arc<S: Subscriber + ?Sized>` ([#2161])
|
||||
|
||||
Thanks to @jswrenn and @CAD97 for contributing to this release!
|
||||
|
||||
[#2164]: https://github.com/tokio-rs/tracing/pull/2164
|
||||
[#2166]: https://github.com/tokio-rs/tracing/pull/2166
|
||||
[#2160]: https://github.com/tokio-rs/tracing/pull/2160
|
||||
[#2008]: https://github.com/tokio-rs/tracing/pull/2008
|
||||
[#2161]: https://github.com/tokio-rs/tracing/pull/2161
|
||||
|
||||
# 0.1.27 (June 7, 2022)
|
||||
|
||||
This release of `tracing-core` introduces a new `DefaultCallsite` type, which
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
edition = "2018"
|
||||
rust-version = "1.49.0"
|
||||
name = "tracing-core"
|
||||
version = "0.1.27"
|
||||
version = "0.1.29"
|
||||
authors = ["Tokio Contributors <team@tokio.rs>"]
|
||||
description = """
|
||||
Core primitives for application-level tracing.
|
||||
|
@ -47,7 +47,7 @@ rustc-args = [
|
|||
]
|
||||
|
||||
[dependencies.once_cell]
|
||||
version = "1.12"
|
||||
version = "1.13.0"
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
|
@ -60,7 +60,7 @@ std = ["once_cell"]
|
|||
[target."cfg(tracing_unstable)".dependencies.valuable]
|
||||
version = "0.1.0"
|
||||
optional = true
|
||||
default_features = false
|
||||
default-features = false
|
||||
|
||||
[badges.maintenance]
|
||||
status = "actively-developed"
|
||||
|
|
|
@ -16,9 +16,9 @@ Core primitives for application-level tracing.
|
|||
[Documentation][docs-url] | [Chat][discord-url]
|
||||
|
||||
[crates-badge]: https://img.shields.io/crates/v/tracing-core.svg
|
||||
[crates-url]: https://crates.io/crates/tracing-core/0.1.27
|
||||
[crates-url]: https://crates.io/crates/tracing-core/0.1.29
|
||||
[docs-badge]: https://docs.rs/tracing-core/badge.svg
|
||||
[docs-url]: https://docs.rs/tracing-core/0.1.27
|
||||
[docs-url]: https://docs.rs/tracing-core/0.1.29
|
||||
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue
|
||||
[docs-master-url]: https://tracing-rs.netlify.com/tracing_core
|
||||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
|
||||
|
@ -79,22 +79,22 @@ The following crate feature flags are available:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
tracing-core = { version = "0.1.27", default-features = false }
|
||||
tracing-core = { version = "0.1.29", default-features = false }
|
||||
```
|
||||
|
||||
**Note**:`tracing-core`'s `no_std` support requires `liballoc`.
|
||||
|
||||
[`tracing`]: ../tracing
|
||||
[`span::Id`]: https://docs.rs/tracing-core/0.1.27/tracing_core/span/struct.Id.html
|
||||
[`Event`]: https://docs.rs/tracing-core/0.1.27/tracing_core/event/struct.Event.html
|
||||
[`Subscriber`]: https://docs.rs/tracing-core/0.1.27/tracing_core/subscriber/trait.Subscriber.html
|
||||
[`Metadata`]: https://docs.rs/tracing-core/0.1.27/tracing_core/metadata/struct.Metadata.html
|
||||
[`Callsite`]: https://docs.rs/tracing-core/0.1.27/tracing_core/callsite/trait.Callsite.html
|
||||
[`Field`]: https://docs.rs/tracing-core/0.1.27/tracing_core/field/struct.Field.html
|
||||
[`FieldSet`]: https://docs.rs/tracing-core/0.1.27/tracing_core/field/struct.FieldSet.html
|
||||
[`Value`]: https://docs.rs/tracing-core/0.1.27/tracing_core/field/trait.Value.html
|
||||
[`ValueSet`]: https://docs.rs/tracing-core/0.1.27/tracing_core/field/struct.ValueSet.html
|
||||
[`Dispatch`]: https://docs.rs/tracing-core/0.1.27/tracing_core/dispatcher/struct.Dispatch.html
|
||||
[`span::Id`]: https://docs.rs/tracing-core/0.1.29/tracing_core/span/struct.Id.html
|
||||
[`Event`]: https://docs.rs/tracing-core/0.1.29/tracing_core/event/struct.Event.html
|
||||
[`Subscriber`]: https://docs.rs/tracing-core/0.1.29/tracing_core/subscriber/trait.Subscriber.html
|
||||
[`Metadata`]: https://docs.rs/tracing-core/0.1.29/tracing_core/metadata/struct.Metadata.html
|
||||
[`Callsite`]: https://docs.rs/tracing-core/0.1.29/tracing_core/callsite/trait.Callsite.html
|
||||
[`Field`]: https://docs.rs/tracing-core/0.1.29/tracing_core/field/struct.Field.html
|
||||
[`FieldSet`]: https://docs.rs/tracing-core/0.1.29/tracing_core/field/struct.FieldSet.html
|
||||
[`Value`]: https://docs.rs/tracing-core/0.1.29/tracing_core/field/trait.Value.html
|
||||
[`ValueSet`]: https://docs.rs/tracing-core/0.1.29/tracing_core/field/struct.ValueSet.html
|
||||
[`Dispatch`]: https://docs.rs/tracing-core/0.1.29/tracing_core/dispatcher/struct.Dispatch.html
|
||||
|
||||
## Supported Rust Versions
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ use crate::stdlib::{
|
|||
};
|
||||
use crate::{
|
||||
dispatcher::Dispatch,
|
||||
lazy::Lazy,
|
||||
metadata::{LevelFilter, Metadata},
|
||||
subscriber::Interest,
|
||||
};
|
||||
|
@ -136,6 +137,15 @@ pub trait Callsite: Sync {
|
|||
|
||||
/// Returns the [metadata] associated with the callsite.
|
||||
///
|
||||
/// <div class="example-wrap" style="display:inline-block">
|
||||
/// <pre class="ignore" style="white-space:normal;font:inherit;">
|
||||
///
|
||||
/// **Note:** Implementations of this method should not produce [`Metadata`]
|
||||
/// that share the same callsite [`Identifier`] but otherwise differ in any
|
||||
/// way (e.g., have different `name`s).
|
||||
///
|
||||
/// </pre></div>
|
||||
///
|
||||
/// [metadata]: super::metadata::Metadata
|
||||
fn metadata(&self) -> &Metadata<'_>;
|
||||
|
||||
|
@ -253,14 +263,7 @@ static CALLSITES: Callsites = Callsites {
|
|||
|
||||
static DISPATCHERS: Dispatchers = Dispatchers::new();
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
static LOCKED_CALLSITES: once_cell::sync::Lazy<Mutex<Vec<&'static dyn Callsite>>> =
|
||||
once_cell::sync::Lazy::new(Default::default);
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
crate::lazy_static! {
|
||||
static ref LOCKED_CALLSITES: Mutex<Vec<&'static dyn Callsite>> = Mutex::new(Vec::new());
|
||||
}
|
||||
static LOCKED_CALLSITES: Lazy<Mutex<Vec<&'static dyn Callsite>>> = Lazy::new(Default::default);
|
||||
|
||||
struct Callsites {
|
||||
list_head: AtomicPtr<DefaultCallsite>,
|
||||
|
@ -514,8 +517,7 @@ mod private {
|
|||
|
||||
#[cfg(feature = "std")]
|
||||
mod dispatchers {
|
||||
use crate::dispatcher;
|
||||
use once_cell::sync::Lazy;
|
||||
use crate::{dispatcher, lazy::Lazy};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
RwLock, RwLockReadGuard, RwLockWriteGuard,
|
||||
|
|
|
@ -293,14 +293,21 @@ pub fn has_been_set() -> bool {
|
|||
}
|
||||
|
||||
/// Returned if setting the global dispatcher fails.
|
||||
#[derive(Debug)]
|
||||
pub struct SetGlobalDefaultError {
|
||||
_no_construct: (),
|
||||
}
|
||||
|
||||
impl fmt::Debug for SetGlobalDefaultError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_tuple("SetGlobalDefaultError")
|
||||
.field(&Self::MESSAGE)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SetGlobalDefaultError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.pad("a global default trace dispatcher has already been set")
|
||||
f.pad(Self::MESSAGE)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,6 +315,10 @@ impl fmt::Display for SetGlobalDefaultError {
|
|||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl error::Error for SetGlobalDefaultError {}
|
||||
|
||||
impl SetGlobalDefaultError {
|
||||
const MESSAGE: &'static str = "a global default trace dispatcher has already been set";
|
||||
}
|
||||
|
||||
/// Executes a closure with a reference to this thread's current [dispatcher].
|
||||
///
|
||||
/// Note that calls to `get_default` should not be nested; if this function is
|
||||
|
@ -511,7 +522,9 @@ impl Dispatch {
|
|||
/// [`event`]: super::subscriber::Subscriber::event
|
||||
#[inline]
|
||||
pub fn event(&self, event: &Event<'_>) {
|
||||
self.subscriber.event(event)
|
||||
if self.subscriber.event_enabled(event) {
|
||||
self.subscriber.event(event);
|
||||
}
|
||||
}
|
||||
|
||||
/// Records that a span has been can_enter.
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
//! 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.
|
||||
//! (`i64`, `u64`, `f64`, `i128`, `u128`, `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
|
||||
|
@ -116,6 +116,7 @@ use crate::stdlib::{
|
|||
hash::{Hash, Hasher},
|
||||
num,
|
||||
ops::Range,
|
||||
string::String,
|
||||
};
|
||||
|
||||
use self::private::ValidLen;
|
||||
|
@ -144,6 +145,16 @@ pub struct Field {
|
|||
pub struct Empty;
|
||||
|
||||
/// Describes the fields present on a span.
|
||||
///
|
||||
/// ## Equality
|
||||
///
|
||||
/// In well-behaved applications, two `FieldSet`s [initialized] with equal
|
||||
/// [callsite identifiers] will have identical fields. Consequently, in release
|
||||
/// builds, [`FieldSet::eq`] *only* checks that its arguments have equal
|
||||
/// callsites. However, the equality of field names is checked in debug builds.
|
||||
///
|
||||
/// [initialized]: Self::new
|
||||
/// [callsite identifiers]: callsite::Identifier
|
||||
pub struct FieldSet {
|
||||
/// The names of each field on the described span.
|
||||
names: &'static [&'static str],
|
||||
|
@ -277,6 +288,16 @@ pub trait Visit {
|
|||
self.record_debug(field, &value)
|
||||
}
|
||||
|
||||
/// Visit a signed 128-bit integer value.
|
||||
fn record_i128(&mut self, field: &Field, value: i128) {
|
||||
self.record_debug(field, &value)
|
||||
}
|
||||
|
||||
/// Visit an unsigned 128-bit integer value.
|
||||
fn record_u128(&mut self, field: &Field, value: u128) {
|
||||
self.record_debug(field, &value)
|
||||
}
|
||||
|
||||
/// Visit a boolean value.
|
||||
fn record_bool(&mut self, field: &Field, value: bool) {
|
||||
self.record_debug(field, &value)
|
||||
|
@ -489,6 +510,8 @@ impl_values! {
|
|||
record_u64(usize, u32, u16, u8 as u64),
|
||||
record_i64(i64),
|
||||
record_i64(isize, i32, i16, i8 as i64),
|
||||
record_u128(u128),
|
||||
record_i128(i128),
|
||||
record_bool(bool),
|
||||
record_f64(f64, f32 as f64)
|
||||
}
|
||||
|
@ -596,6 +619,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl crate::sealed::Sealed for String {}
|
||||
impl Value for String {
|
||||
fn record(&self, key: &Field, visitor: &mut dyn Visit) {
|
||||
visitor.record_str(key, self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for dyn Value {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// We are only going to be recording the field value, so we don't
|
||||
|
@ -891,6 +921,40 @@ impl fmt::Display for FieldSet {
|
|||
}
|
||||
}
|
||||
|
||||
impl Eq for FieldSet {}
|
||||
|
||||
impl PartialEq for FieldSet {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if core::ptr::eq(&self, &other) {
|
||||
true
|
||||
} else if cfg!(not(debug_assertions)) {
|
||||
// In a well-behaving application, two `FieldSet`s can be assumed to
|
||||
// be totally equal so long as they share the same callsite.
|
||||
self.callsite == other.callsite
|
||||
} else {
|
||||
// However, when debug-assertions are enabled, do NOT assume that
|
||||
// the application is well-behaving; check every the field names of
|
||||
// each `FieldSet` for equality.
|
||||
|
||||
// `FieldSet` is destructured here to ensure a compile-error if the
|
||||
// fields of `FieldSet` change.
|
||||
let Self {
|
||||
names: lhs_names,
|
||||
callsite: lhs_callsite,
|
||||
} = self;
|
||||
|
||||
let Self {
|
||||
names: rhs_names,
|
||||
callsite: rhs_callsite,
|
||||
} = &other;
|
||||
|
||||
// Check callsite equality first, as it is probably cheaper to do
|
||||
// than str equality.
|
||||
lhs_callsite == rhs_callsite && lhs_names == rhs_names
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl Iter =====
|
||||
|
||||
impl Iterator for Iter {
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
#[cfg(feature = "std")]
|
||||
pub(crate) use once_cell::sync::Lazy;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub(crate) use self::spin::Lazy;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod spin {
|
||||
//! This is the `once_cell::sync::Lazy` type, but modified to use our
|
||||
//! `spin::Once` type rather than `OnceCell`. This is used to replace
|
||||
//! `once_cell::sync::Lazy` on `no-std` builds.
|
||||
use crate::spin::Once;
|
||||
use core::{cell::Cell, fmt, ops::Deref};
|
||||
|
||||
/// Re-implementation of `once_cell::sync::Lazy` on top of `spin::Once`
|
||||
/// rather than `OnceCell`.
|
||||
///
|
||||
/// This is used when the standard library is disabled.
|
||||
pub(crate) struct Lazy<T, F = fn() -> T> {
|
||||
cell: Once<T>,
|
||||
init: Cell<Option<F>>,
|
||||
}
|
||||
|
||||
impl<T: fmt::Debug, F> fmt::Debug for Lazy<T, F> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Lazy")
|
||||
.field("cell", &self.cell)
|
||||
.field("init", &"..")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
// We never create a `&F` from a `&Lazy<T, F>` so it is fine to not impl
|
||||
// `Sync` for `F`. We do create a `&mut Option<F>` in `force`, but this is
|
||||
// properly synchronized, so it only happens once so it also does not
|
||||
// contribute to this impl.
|
||||
unsafe impl<T, F: Send> Sync for Lazy<T, F> where Once<T>: Sync {}
|
||||
// auto-derived `Send` impl is OK.
|
||||
|
||||
impl<T, F> Lazy<T, F> {
|
||||
/// Creates a new lazy value with the given initializing function.
|
||||
pub(crate) const fn new(init: F) -> Lazy<T, F> {
|
||||
Lazy {
|
||||
cell: Once::new(),
|
||||
init: Cell::new(Some(init)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F: FnOnce() -> T> Lazy<T, F> {
|
||||
/// Forces the evaluation of this lazy value and returns a reference to
|
||||
/// the result.
|
||||
///
|
||||
/// This is equivalent to the `Deref` impl, but is explicit.
|
||||
pub(crate) fn force(this: &Lazy<T, F>) -> &T {
|
||||
this.cell.call_once(|| match this.init.take() {
|
||||
Some(f) => f(),
|
||||
None => panic!("Lazy instance has previously been poisoned"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
Lazy::force(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default> Default for Lazy<T> {
|
||||
/// Creates a new lazy value using `Default` as the initializing function.
|
||||
fn default() -> Lazy<T> {
|
||||
Lazy::new(T::default)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
Copyright (c) 2010 The Rust Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright 2016 lazy-static.rs Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use crate::spin::Once;
|
||||
|
||||
pub(crate) struct Lazy<T: Sync>(Once<T>);
|
||||
|
||||
impl<T: Sync> Lazy<T> {
|
||||
pub(crate) const INIT: Self = Lazy(Once::INIT);
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn get<F>(&'static self, builder: F) -> &T
|
||||
where
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
self.0.call_once(builder)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __lazy_static_create {
|
||||
($NAME:ident, $T:ty) => {
|
||||
static $NAME: $crate::lazy_static::lazy::Lazy<$T> = $crate::lazy_static::lazy::Lazy::INIT;
|
||||
};
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright 2016 lazy-static.rs Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
/*!
|
||||
A macro for declaring lazily evaluated statics.
|
||||
Using this macro, it is possible to have `static`s that require code to be
|
||||
executed at runtime in order to be initialized.
|
||||
This includes anything requiring heap allocations, like vectors or hash maps,
|
||||
as well as anything that requires function calls to be computed.
|
||||
*/
|
||||
|
||||
#[path = "core_lazy.rs"]
|
||||
pub(crate) mod lazy;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub(crate) use core::ops::Deref as __Deref;
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __lazy_static_internal {
|
||||
// optional visibility restrictions are wrapped in `()` to allow for
|
||||
// explicitly passing otherwise implicit information about private items
|
||||
($(#[$attr:meta])* ($($vis:tt)*) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
$crate::__lazy_static_internal!(@MAKE TY, $(#[$attr])*, ($($vis)*), $N);
|
||||
$crate::__lazy_static_internal!(@TAIL, $N : $T = $e);
|
||||
$crate::lazy_static!($($t)*);
|
||||
};
|
||||
(@TAIL, $N:ident : $T:ty = $e:expr) => {
|
||||
impl $crate::lazy_static::__Deref for $N {
|
||||
type Target = $T;
|
||||
fn deref(&self) -> &$T {
|
||||
#[inline(always)]
|
||||
fn __static_ref_initialize() -> $T { $e }
|
||||
|
||||
#[inline(always)]
|
||||
fn __stability() -> &'static $T {
|
||||
$crate::__lazy_static_create!(LAZY, $T);
|
||||
LAZY.get(__static_ref_initialize)
|
||||
}
|
||||
__stability()
|
||||
}
|
||||
}
|
||||
impl $crate::lazy_static::LazyStatic for $N {
|
||||
fn initialize(lazy: &Self) {
|
||||
let _ = &**lazy;
|
||||
}
|
||||
}
|
||||
};
|
||||
// `vis` is wrapped in `()` to prevent parsing ambiguity
|
||||
(@MAKE TY, $(#[$attr:meta])*, ($($vis:tt)*), $N:ident) => {
|
||||
#[allow(missing_copy_implementations)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(dead_code)]
|
||||
$(#[$attr])*
|
||||
$($vis)* struct $N {__private_field: ()}
|
||||
#[doc(hidden)]
|
||||
$($vis)* static $N: $N = $N {__private_field: ()};
|
||||
};
|
||||
() => ()
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! lazy_static {
|
||||
($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
// use `()` to explicitly forward the information about private items
|
||||
$crate::__lazy_static_internal!($(#[$attr])* () static ref $N : $T = $e; $($t)*);
|
||||
};
|
||||
($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
$crate::__lazy_static_internal!($(#[$attr])* (pub) static ref $N : $T = $e; $($t)*);
|
||||
};
|
||||
($(#[$attr:meta])* pub ($($vis:tt)+) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
|
||||
$crate::__lazy_static_internal!($(#[$attr])* (pub ($($vis)+)) static ref $N : $T = $e; $($t)*);
|
||||
};
|
||||
() => ()
|
||||
}
|
||||
|
||||
/// Support trait for enabling a few common operation on lazy static values.
|
||||
///
|
||||
/// This is implemented by each defined lazy static, and
|
||||
/// used by the free functions in this crate.
|
||||
pub(crate) trait LazyStatic {
|
||||
#[doc(hidden)]
|
||||
fn initialize(lazy: &Self);
|
||||
}
|
|
@ -254,10 +254,7 @@ macro_rules! metadata {
|
|||
};
|
||||
}
|
||||
|
||||
// Facade module: `no_std` uses spinlocks, `std` uses the mutexes in the standard library
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[macro_use]
|
||||
mod lazy_static;
|
||||
pub(crate) mod lazy;
|
||||
|
||||
// Trimmed-down vendored version of spin 0.5.2 (0387621)
|
||||
// Dependency of no_std lazy_static, not required in a std build
|
||||
|
|
|
@ -35,28 +35,25 @@ use crate::stdlib::{
|
|||
/// _significantly_ lower than that of creating the actual span. Therefore,
|
||||
/// filtering is based on metadata, rather than on the constructed span.
|
||||
///
|
||||
/// <pre class="ignore" style="white-space:normal;font:inherit;">
|
||||
/// <strong>Note</strong>: Although instances of <code>Metadata</code>
|
||||
/// cannot be compared directly, they provide a method
|
||||
/// <a href="struct.Metadata.html#method.id"><code>id</code></a>, returning
|
||||
/// an opaque <a href="../callsite/struct.Identifier.html">callsite
|
||||
/// identifier</a>which uniquely identifies the callsite where the metadata
|
||||
/// originated. This can be used to determine if two <code>Metadata</code>
|
||||
/// correspond to the same callsite.
|
||||
/// </pre>
|
||||
/// ## Equality
|
||||
///
|
||||
/// In well-behaved applications, two `Metadata` with equal
|
||||
/// [callsite identifiers] will be equal in all other ways (i.e., have the same
|
||||
/// `name`, `target`, etc.). Consequently, in release builds, [`Metadata::eq`]
|
||||
/// *only* checks that its arguments have equal callsites. However, the equality
|
||||
/// of `Metadata`'s other fields is checked in debug builds.
|
||||
///
|
||||
/// [span]: super::span
|
||||
/// [event]: super::event
|
||||
/// [name]: Metadata::name()
|
||||
/// [target]: Metadata::target()
|
||||
/// [fields]: Metadata::fields()
|
||||
/// [verbosity level]: Metadata::level()
|
||||
/// [file name]: Metadata::file()
|
||||
/// [line number]: Metadata::line()
|
||||
/// [module path]: Metadata::module_path()
|
||||
/// [name]: Self::name
|
||||
/// [target]: Self::target
|
||||
/// [fields]: Self::fields
|
||||
/// [verbosity level]: Self::level
|
||||
/// [file name]: Self::file
|
||||
/// [line number]: Self::line
|
||||
/// [module path]: Self::module_path
|
||||
/// [`Subscriber`]: super::subscriber::Subscriber
|
||||
/// [`id`]: Metadata::id
|
||||
/// [callsite identifier]: super::callsite::Identifier
|
||||
/// [callsite identifiers]: Self::callsite
|
||||
pub struct Metadata<'a> {
|
||||
/// The name of the span described by this metadata.
|
||||
name: &'static str,
|
||||
|
@ -443,6 +440,62 @@ impl fmt::Debug for Kind {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Eq for Metadata<'a> {}
|
||||
|
||||
impl<'a> PartialEq for Metadata<'a> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if core::ptr::eq(&self, &other) {
|
||||
true
|
||||
} else if cfg!(not(debug_assertions)) {
|
||||
// In a well-behaving application, two `Metadata` can be assumed to
|
||||
// be totally equal so long as they share the same callsite.
|
||||
self.callsite() == other.callsite()
|
||||
} else {
|
||||
// However, when debug-assertions are enabled, do not assume that
|
||||
// the application is well-behaving; check every field of `Metadata`
|
||||
// for equality.
|
||||
|
||||
// `Metadata` is destructured here to ensure a compile-error if the
|
||||
// fields of `Metadata` change.
|
||||
let Metadata {
|
||||
name: lhs_name,
|
||||
target: lhs_target,
|
||||
level: lhs_level,
|
||||
module_path: lhs_module_path,
|
||||
file: lhs_file,
|
||||
line: lhs_line,
|
||||
fields: lhs_fields,
|
||||
kind: lhs_kind,
|
||||
} = self;
|
||||
|
||||
let Metadata {
|
||||
name: rhs_name,
|
||||
target: rhs_target,
|
||||
level: rhs_level,
|
||||
module_path: rhs_module_path,
|
||||
file: rhs_file,
|
||||
line: rhs_line,
|
||||
fields: rhs_fields,
|
||||
kind: rhs_kind,
|
||||
} = &other;
|
||||
|
||||
// The initial comparison of callsites is purely an optimization;
|
||||
// it can be removed without affecting the overall semantics of the
|
||||
// expression.
|
||||
self.callsite() == other.callsite()
|
||||
&& lhs_name == rhs_name
|
||||
&& lhs_target == rhs_target
|
||||
&& lhs_level == rhs_level
|
||||
&& lhs_module_path == rhs_module_path
|
||||
&& lhs_file == rhs_file
|
||||
&& lhs_line == rhs_line
|
||||
&& lhs_fields == rhs_fields
|
||||
&& lhs_kind == rhs_kind
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl Level =====
|
||||
|
||||
impl Level {
|
||||
|
|
|
@ -64,11 +64,11 @@ mod no_std {
|
|||
}
|
||||
|
||||
impl<T> Mutex<T> {
|
||||
pub(crate) fn new(data: T) -> Self {
|
||||
Self {
|
||||
inner: crate::spin::Mutex::new(data),
|
||||
}
|
||||
}
|
||||
// pub(crate) fn new(data: T) -> Self {
|
||||
// Self {
|
||||
// inner: crate::spin::Mutex::new(data),
|
||||
// }
|
||||
// }
|
||||
|
||||
pub(crate) fn lock(&self) -> Result<MutexGuard<'_, T>, ()> {
|
||||
Ok(self.inner.lock())
|
||||
|
|
|
@ -60,6 +60,9 @@ use crate::stdlib::{
|
|||
/// See also the [documentation on the callsite registry][cs-reg] for details
|
||||
/// on [`register_callsite`].
|
||||
///
|
||||
/// - [`event_enabled`] is called once before every call to the [`event`]
|
||||
/// method. This can be used to implement filtering on events once their field
|
||||
/// values are known, but before any processing is done in the `event` method.
|
||||
/// - [`clone_span`] is called every time a span ID is cloned, and [`try_close`]
|
||||
/// is called when a span ID is dropped. By default, these functions do
|
||||
/// nothing. However, they can be used to implement reference counting for
|
||||
|
@ -75,6 +78,8 @@ use crate::stdlib::{
|
|||
/// [`clone_span`]: Subscriber::clone_span
|
||||
/// [`try_close`]: Subscriber::try_close
|
||||
/// [cs-reg]: crate::callsite#registering-callsites
|
||||
/// [`event`]: Subscriber::event
|
||||
/// [`event_enabled`]: Subscriber::event_enabled
|
||||
pub trait Subscriber: 'static {
|
||||
// === Span registry methods ==============================================
|
||||
|
||||
|
@ -291,6 +296,17 @@ pub trait Subscriber: 'static {
|
|||
/// follow from _b_), it may silently do nothing.
|
||||
fn record_follows_from(&self, span: &span::Id, follows: &span::Id);
|
||||
|
||||
/// Determine if an [`Event`] should be recorded.
|
||||
///
|
||||
/// By default, this returns `true` and `Subscriber`s can filter events in
|
||||
/// [`event`][Self::event] without any penalty. However, when `event` is
|
||||
/// more complicated, this can be used to determine if `event` should be
|
||||
/// called at all, separating out the decision from the processing.
|
||||
fn event_enabled(&self, event: &Event<'_>) -> bool {
|
||||
let _ = event;
|
||||
true
|
||||
}
|
||||
|
||||
/// Records that an [`Event`] has occurred.
|
||||
///
|
||||
/// This method will be invoked when an Event is constructed by
|
||||
|
@ -484,6 +500,66 @@ impl dyn Subscriber {
|
|||
}
|
||||
}
|
||||
|
||||
impl dyn Subscriber + Send {
|
||||
/// Returns `true` if this [`Subscriber`] is the same type as `T`.
|
||||
pub fn is<T: Any>(&self) -> bool {
|
||||
self.downcast_ref::<T>().is_some()
|
||||
}
|
||||
|
||||
/// Returns some reference to this [`Subscriber`] value if it is of type `T`,
|
||||
/// or `None` if it isn't.
|
||||
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
|
||||
unsafe {
|
||||
let raw = self.downcast_raw(TypeId::of::<T>())?;
|
||||
if raw.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(&*(raw as *const _))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl dyn Subscriber + Sync {
|
||||
/// Returns `true` if this [`Subscriber`] is the same type as `T`.
|
||||
pub fn is<T: Any>(&self) -> bool {
|
||||
self.downcast_ref::<T>().is_some()
|
||||
}
|
||||
|
||||
/// Returns some reference to this `[`Subscriber`] value if it is of type `T`,
|
||||
/// or `None` if it isn't.
|
||||
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
|
||||
unsafe {
|
||||
let raw = self.downcast_raw(TypeId::of::<T>())?;
|
||||
if raw.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(&*(raw as *const _))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl dyn Subscriber + Send + Sync {
|
||||
/// Returns `true` if this [`Subscriber`] is the same type as `T`.
|
||||
pub fn is<T: Any>(&self) -> bool {
|
||||
self.downcast_ref::<T>().is_some()
|
||||
}
|
||||
|
||||
/// Returns some reference to this [`Subscriber`] value if it is of type `T`,
|
||||
/// or `None` if it isn't.
|
||||
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
|
||||
unsafe {
|
||||
let raw = self.downcast_raw(TypeId::of::<T>())?;
|
||||
if raw.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(&*(raw as *const _))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Indicates a [`Subscriber`]'s interest in a particular callsite.
|
||||
///
|
||||
/// `Subscriber`s return an `Interest` from their [`register_callsite`] methods
|
||||
|
@ -602,7 +678,10 @@ impl Subscriber for NoSubscriber {
|
|||
fn exit(&self, _span: &span::Id) {}
|
||||
}
|
||||
|
||||
impl Subscriber for Box<dyn Subscriber + Send + Sync + 'static> {
|
||||
impl<S> Subscriber for Box<S>
|
||||
where
|
||||
S: Subscriber + ?Sized,
|
||||
{
|
||||
#[inline]
|
||||
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
|
||||
self.as_ref().register_callsite(metadata)
|
||||
|
@ -633,6 +712,11 @@ impl Subscriber for Box<dyn Subscriber + Send + Sync + 'static> {
|
|||
self.as_ref().record_follows_from(span, follows)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn event_enabled(&self, event: &Event<'_>) -> bool {
|
||||
self.as_ref().event_enabled(event)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
self.as_ref().event(event)
|
||||
|
@ -679,7 +763,10 @@ impl Subscriber for Box<dyn Subscriber + Send + Sync + 'static> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Subscriber for Arc<dyn Subscriber + Send + Sync + 'static> {
|
||||
impl<S> Subscriber for Arc<S>
|
||||
where
|
||||
S: Subscriber + ?Sized,
|
||||
{
|
||||
#[inline]
|
||||
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
|
||||
self.as_ref().register_callsite(metadata)
|
||||
|
@ -710,6 +797,11 @@ impl Subscriber for Arc<dyn Subscriber + Send + Sync + 'static> {
|
|||
self.as_ref().record_follows_from(span, follows)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn event_enabled(&self, event: &Event<'_>) -> bool {
|
||||
self.as_ref().event_enabled(event)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
self.as_ref().event(event)
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"CHANGELOG.md":"7d5517e1ac705d5d8574915b59a37bbd0ba5aa6e663fc272b75e5792eca572a9","Cargo.toml":"f6290faffd0bf079845dbd6c3c1ddb6c728bcf7225e3b56a4ba5a9478dc72a8b","LICENSE":"898b1ae9821e98daf8964c8d6c7f61641f5f5aa78ad500020771c0939ee0dea1","README.md":"a83e1a8287e3eca752383ae849872707dddfbd07b918806cc7c027a0824872c6","benches/global_subscriber.rs":"271213baed0e02054e506c1ec9c47b58696c78aaa46f0969a147f4c369f80e3d","benches/no_subscriber.rs":"495c9a91fb972ec61ced31ef8e19d2cca02ec8ffae4e98e3316e55f6a0074578","benches/subscriber.rs":"c609be119ed6e4d3fb79df77f15aa14effbd3e2f77c627a49229a50091d3ee6a","src/dispatcher.rs":"a8158e1901c50dc83d2f15b1773e6b9e31985d9af65e460be52dbf8be6874cd2","src/field.rs":"55c7a2798b9ad0269e7c738c3f15a5d0281bf34ac3a6196a3f0b15801e5278bd","src/instrument.rs":"1fe4de5c13b5ba048e9872d78d1fa4e85655f9f2ed10f79b72b5da881c9b8b45","src/level_filters.rs":"baae8e797897bae9cdd9ec64b8e9a3d71156e9c03261be17b5b18acba034e154","src/lib.rs":"a8ab6b578f93b5fb833942fc59642e67caca8d343670d64fb52d47d5507a67e4","src/macros.rs":"f1a83930cea322f1f2000548d91800c22a9e28d2daf3f178c7c7c3ac8da5a02d","src/span.rs":"96b6c86be09c97b15b2ab5c607013abc5b388c2870eb648bee2cfc07837fa6e9","src/stdlib.rs":"248514a9bae6106e436358aee44c92abf8e7f79022895c4a25136ddef211d198","src/subscriber.rs":"ae879c373be7ee4935f7b02a345f92ccbeb7879d61c5d37e3cc1277b3d51ddb2","tests/enabled.rs":"1333339aace87ea9d701f2f76a1985820cc513a75013a7ed89669f7a2c635479","tests/event.rs":"c4ec3ac338475e9e61675551eb99df1d8a7cbefb05a0d60203994f5c1df7c784","tests/filter_caching_is_lexically_scoped.rs":"5487a37db5fbdf3d57020ab1f01185d928c45d967d99d723ffc434540459d8dc","tests/filters_are_not_reevaluated_for_the_same_span.rs":"251abbc000dddd298448958a1f0e5be71da527ac6c1a368d57837c83a5467329","tests/filters_are_reevaluated_for_different_call_sites.rs":"e0fdd8e930c043674702831b4d96f331e63aba824576bbac50b3f53bb0241cc7","tests/filters_dont_leak.rs":"d594266818a3461886da33bfcc76937d89a433ed6980226fc428706b216c093c","tests/future_send.rs":"3e9c9193219d12e342c18bbedb2f6ec940334202feb3cffba91601d6001b8575","tests/macro_imports.rs":"d5de857162185d4a2384f3cb644bfcf76c7f5c1a3b5f72bfa0d2620ac6e3873c","tests/macros.rs":"fa83397181d73d2cae09c16d9647a63d1e3bad0f2dbc5b3280f69f3d0180c488","tests/macros_incompatible_concat.rs":"5f3bcbb65e4ae39db1cfc2def62fc913c20bab0fb769c8f731504e2615585ee5","tests/macros_redefined_core.rs":"a6eac60522f71fe6c9a040b8b869d596f7eb9e907f5b49f4be4413a40c387676","tests/max_level_hint.rs":"9b366591d947ca0202fa0bdf797e1bb14534d3c896cf8b9674660cd2807c32ef","tests/multiple_max_level_hints.rs":"4d9ef0de9cccc787da8f5e3f6c233ac9db42a2a99cfe5e39997e1f4aa9df0c00","tests/no_subscriber.rs":"2f8f2ada5089d8e2e503394dfe8206598a11895907c53bf940b892f1e6afdd2f","tests/register_callsite_deadlock.rs":"c0b3142543e7a10065c7583a8ee0b6bc978ea4f3979599651101c5a28966e7c8","tests/scoped_clobbers_default.rs":"806480a74c15e4d68bb7576050662b1e53ee765fd583d003f8b349f17ea63a4b","tests/span.rs":"f84ead5b1dad9b91e5cec9d8378ab932a942936374ba928fb381e67fab52cda0","tests/subscriber.rs":"1617c098f4fa6abed174fe062111444c7b67fa0f377d2b342176998e572480e3"},"package":"a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"}
|
||||
{"files":{"CHANGELOG.md":"dc3017cca8de9a33d8e0c3cba87b3977b1c84e1fe16ff87bc36614572ddd5832","Cargo.toml":"e4ffa43825ed68447646e39babd364b737b1353f95a7a6baa995879ad282952d","LICENSE":"898b1ae9821e98daf8964c8d6c7f61641f5f5aa78ad500020771c0939ee0dea1","README.md":"2a2ff5fa337287734c28e856a185afbced4cd656791a1aaeef0b982784e601d7","benches/baseline.rs":"43a3e31b6c33dba2e6328052301b707b212487b83f0dcffc843061a9c48a2319","benches/dispatch_get_clone.rs":"866239abeb74a82440741c948a4e7e0a44e92e8cc87319ec57e3b057c9e8f5dd","benches/dispatch_get_ref.rs":"dd2803259a6784c256304e676bbce05de233e4c8451ac85863787213343e9be7","benches/empty_span.rs":"9f51cf376414ea751b2f50c357f2435a545d606118286f5b8b89f185e28aad8c","benches/enter_span.rs":"4410ec73d277e7b54e9f306c00ff3b79a150d1832966b7fc29984c8e3ad8d57c","benches/event.rs":"98de3c82ed18abe0a3cbe6eda9a4f9deec2b69bca42c3aac11dea4b608b85a67","benches/shared.rs":"2623311af7d153685064e664a5903d03e7dc3179754c324f3a76f29f060515e6","benches/span_fields.rs":"9166cd43ef2783e5419dd61ea57a02e48e8cc38aa1b357e9b79fa581929b60d8","benches/span_no_fields.rs":"79cc4befacf27d7ce728246087c4f06a6066f913e831d9043caeb7941f0193f6","benches/span_repeated.rs":"e4b3c99a7a9fc15d9042b8db399a56cf647b4eebd26f29d95325bb057b68330b","src/dispatcher.rs":"a8158e1901c50dc83d2f15b1773e6b9e31985d9af65e460be52dbf8be6874cd2","src/field.rs":"55c7a2798b9ad0269e7c738c3f15a5d0281bf34ac3a6196a3f0b15801e5278bd","src/instrument.rs":"1fe4de5c13b5ba048e9872d78d1fa4e85655f9f2ed10f79b72b5da881c9b8b45","src/level_filters.rs":"baae8e797897bae9cdd9ec64b8e9a3d71156e9c03261be17b5b18acba034e154","src/lib.rs":"c7edb1602b2e9d164bc90f9d0dff48abb2fad840c07c6283481255fbe5d321e6","src/macros.rs":"f1a83930cea322f1f2000548d91800c22a9e28d2daf3f178c7c7c3ac8da5a02d","src/span.rs":"372695b3eda8354a892316826d2598f821fcb835fb18e1e0271767bce730b7ad","src/stdlib.rs":"248514a9bae6106e436358aee44c92abf8e7f79022895c4a25136ddef211d198","src/subscriber.rs":"8933d8766439f929c0a98a0863d20aff37b221314b3825edd9058be511149968","tests/enabled.rs":"1333339aace87ea9d701f2f76a1985820cc513a75013a7ed89669f7a2c635479","tests/event.rs":"7678d1cc8a29ae8b716fbddb7cc4836422732ba3dce109ff511c8bb6100da606","tests/filter_caching_is_lexically_scoped.rs":"5487a37db5fbdf3d57020ab1f01185d928c45d967d99d723ffc434540459d8dc","tests/filters_are_not_reevaluated_for_the_same_span.rs":"251abbc000dddd298448958a1f0e5be71da527ac6c1a368d57837c83a5467329","tests/filters_are_reevaluated_for_different_call_sites.rs":"e0fdd8e930c043674702831b4d96f331e63aba824576bbac50b3f53bb0241cc7","tests/filters_dont_leak.rs":"d594266818a3461886da33bfcc76937d89a433ed6980226fc428706b216c093c","tests/future_send.rs":"3e9c9193219d12e342c18bbedb2f6ec940334202feb3cffba91601d6001b8575","tests/macro_imports.rs":"d5de857162185d4a2384f3cb644bfcf76c7f5c1a3b5f72bfa0d2620ac6e3873c","tests/macros.rs":"fa83397181d73d2cae09c16d9647a63d1e3bad0f2dbc5b3280f69f3d0180c488","tests/macros_incompatible_concat.rs":"5f3bcbb65e4ae39db1cfc2def62fc913c20bab0fb769c8f731504e2615585ee5","tests/macros_redefined_core.rs":"a6eac60522f71fe6c9a040b8b869d596f7eb9e907f5b49f4be4413a40c387676","tests/max_level_hint.rs":"9b366591d947ca0202fa0bdf797e1bb14534d3c896cf8b9674660cd2807c32ef","tests/multiple_max_level_hints.rs":"4d9ef0de9cccc787da8f5e3f6c233ac9db42a2a99cfe5e39997e1f4aa9df0c00","tests/no_subscriber.rs":"2f8f2ada5089d8e2e503394dfe8206598a11895907c53bf940b892f1e6afdd2f","tests/register_callsite_deadlock.rs":"c0b3142543e7a10065c7583a8ee0b6bc978ea4f3979599651101c5a28966e7c8","tests/scoped_clobbers_default.rs":"806480a74c15e4d68bb7576050662b1e53ee765fd583d003f8b349f17ea63a4b","tests/span.rs":"f84ead5b1dad9b91e5cec9d8378ab932a942936374ba928fb381e67fab52cda0","tests/subscriber.rs":"1617c098f4fa6abed174fe062111444c7b67fa0f377d2b342176998e572480e3"},"package":"2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"}
|
|
@ -1,3 +1,33 @@
|
|||
# 0.1.36 (July 29, 2022)
|
||||
|
||||
This release adds support for owned values and fat pointers as arguments to the
|
||||
`Span::record` method, as well as updating the minimum `tracing-core` version
|
||||
and several documentation improvements.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Incorrect docs in `dispatcher::set_default` ([#2220])
|
||||
- Compilation with `-Z minimal-versions` ([#2246])
|
||||
|
||||
### Added
|
||||
|
||||
- Support for owned values and fat pointers in `Span::record` ([#2212])
|
||||
- Documentation improvements ([#2208], [#2163])
|
||||
|
||||
### Changed
|
||||
|
||||
- `tracing-core`: updated to [0.1.29][core-0.1.29]
|
||||
|
||||
Thanks to @fredr, @cgbur, @jyn514, @matklad, and @CAD97 for contributing to this
|
||||
release!
|
||||
|
||||
[core-0.1.29]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.29
|
||||
[#2220]: https://github.com/tokio-rs/tracing/pull/2220
|
||||
[#2246]: https://github.com/tokio-rs/tracing/pull/2246
|
||||
[#2212]: https://github.com/tokio-rs/tracing/pull/2212
|
||||
[#2208]: https://github.com/tokio-rs/tracing/pull/2208
|
||||
[#2163]: https://github.com/tokio-rs/tracing/pull/2163
|
||||
|
||||
# 0.1.35 (June 8, 2022)
|
||||
|
||||
This release reduces the overhead of callsite registration by using new
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
edition = "2018"
|
||||
rust-version = "1.49.0"
|
||||
name = "tracing"
|
||||
version = "0.1.35"
|
||||
version = "0.1.36"
|
||||
authors = [
|
||||
"Eliza Weisman <eliza@buoyant.io>",
|
||||
"Tokio Contributors <team@tokio.rs>",
|
||||
|
@ -52,37 +52,65 @@ rustc-args = [
|
|||
]
|
||||
|
||||
[[bench]]
|
||||
name = "subscriber"
|
||||
name = "baseline"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "no_subscriber"
|
||||
name = "dispatch_get_clone"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "dispatch_get_ref"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "empty_span"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "enter_span"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "event"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "span_fields"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "span_no_fields"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "span_repeated"
|
||||
harness = false
|
||||
|
||||
[dependencies.cfg-if]
|
||||
version = "1.0.0"
|
||||
|
||||
[dependencies.log]
|
||||
version = "0.4"
|
||||
version = "0.4.17"
|
||||
optional = true
|
||||
|
||||
[dependencies.pin-project-lite]
|
||||
version = "0.2"
|
||||
version = "0.2.9"
|
||||
|
||||
[dependencies.tracing-attributes]
|
||||
version = "0.1.20"
|
||||
version = "0.1.22"
|
||||
optional = true
|
||||
|
||||
[dependencies.tracing-core]
|
||||
version = "0.1.27"
|
||||
version = "0.1.29"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.criterion]
|
||||
version = "0.3"
|
||||
default_features = false
|
||||
version = "0.3.6"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.log]
|
||||
version = "0.4"
|
||||
version = "0.4.17"
|
||||
|
||||
[features]
|
||||
async-await = []
|
||||
|
|
|
@ -16,9 +16,9 @@ Application-level tracing for Rust.
|
|||
[Documentation][docs-url] | [Chat][discord-url]
|
||||
|
||||
[crates-badge]: https://img.shields.io/crates/v/tracing.svg
|
||||
[crates-url]: https://crates.io/crates/tracing/0.1.35
|
||||
[crates-url]: https://crates.io/crates/tracing
|
||||
[docs-badge]: https://docs.rs/tracing/badge.svg
|
||||
[docs-url]: https://docs.rs/tracing/0.1.35
|
||||
[docs-url]: https://docs.rs/tracing
|
||||
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue
|
||||
[docs-master-url]: https://tracing-rs.netlify.com/tracing
|
||||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
|
||||
|
@ -250,7 +250,7 @@ my_future
|
|||
is as long as the future's.
|
||||
|
||||
The second, and preferred, option is through the
|
||||
[`#[instrument]`](https://docs.rs/tracing/0.1.35/tracing/attr.instrument.html)
|
||||
[`#[instrument]`](https://docs.rs/tracing/0.1.36/tracing/attr.instrument.html)
|
||||
attribute:
|
||||
|
||||
```rust
|
||||
|
@ -297,7 +297,7 @@ span.in_scope(|| {
|
|||
// Dropping the span will close it, indicating that it has ended.
|
||||
```
|
||||
|
||||
The [`#[instrument]`](https://docs.rs/tracing/0.1.35/tracing/attr.instrument.html) attribute macro
|
||||
The [`#[instrument]`](https://docs.rs/tracing/0.1.36/tracing/attr.instrument.html) attribute macro
|
||||
can reduce some of this boilerplate:
|
||||
|
||||
```rust
|
||||
|
@ -395,6 +395,7 @@ maintained by the `tokio` project. These include:
|
|||
framework for validating the behavior of `tracing` spans.
|
||||
- [`sentry-tracing`] provides a layer for reporting events and traces to [Sentry].
|
||||
- [`tracing-loki`] provides a layer for shipping logs to [Grafana Loki].
|
||||
- [`tracing-logfmt`] provides a layer that formats events and spans into the logfmt format.
|
||||
|
||||
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!
|
||||
|
@ -424,6 +425,7 @@ please let us know! We'd love to add your project to the list!
|
|||
[Sentry]: https://sentry.io/welcome/
|
||||
[`tracing-loki`]: https://crates.io/crates/tracing-loki
|
||||
[Grafana Loki]: https://grafana.com/oss/loki/
|
||||
[`tracing-logfmt`]: https://crates.io/crates/tracing-logfmt
|
||||
|
||||
**Note:** that some of the ecosystem crates are currently unreleased and
|
||||
undergoing active development. They may be less stable than `tracing` and
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let mut group = c.benchmark_group("comparison");
|
||||
group.bench_function("relaxed_load", |b| {
|
||||
let foo = AtomicUsize::new(1);
|
||||
b.iter(|| black_box(foo.load(Ordering::Relaxed)));
|
||||
});
|
||||
group.bench_function("acquire_load", |b| {
|
||||
let foo = AtomicUsize::new(1);
|
||||
b.iter(|| black_box(foo.load(Ordering::Acquire)))
|
||||
});
|
||||
group.bench_function("log", |b| {
|
||||
b.iter(|| {
|
||||
log::log!(log::Level::Info, "log");
|
||||
})
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,15 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_dispatches(&mut c.benchmark_group("Dispatch::get_clone"), |b| {
|
||||
b.iter(|| {
|
||||
let current = tracing::dispatcher::get_default(|current| current.clone());
|
||||
black_box(current);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,16 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_dispatches(&mut c.benchmark_group("Dispatch::get_ref"), |b| {
|
||||
b.iter(|| {
|
||||
tracing::dispatcher::get_default(|current| {
|
||||
black_box(¤t);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,43 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("empty_span");
|
||||
shared::for_all_dispatches(&mut group, |b| {
|
||||
b.iter(|| {
|
||||
let span = tracing::span::Span::none();
|
||||
black_box(&span);
|
||||
})
|
||||
});
|
||||
group.bench_function("baseline_struct", |b| {
|
||||
b.iter(|| {
|
||||
let span = FakeEmptySpan::new();
|
||||
black_box(&span);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
struct FakeEmptySpan {
|
||||
inner: Option<(usize, std::sync::Arc<()>)>,
|
||||
meta: Option<&'static ()>,
|
||||
}
|
||||
|
||||
impl FakeEmptySpan {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
inner: None,
|
||||
meta: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FakeEmptySpan {
|
||||
fn drop(&mut self) {
|
||||
black_box(&self.inner);
|
||||
black_box(&self.meta);
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,16 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use tracing::{span, Level};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_dispatches(&mut c.benchmark_group("enter_span"), |b| {
|
||||
let span = span!(Level::TRACE, "span");
|
||||
b.iter(|| {
|
||||
let _span = span.enter();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,12 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_recording(&mut c.benchmark_group("event"), |b| {
|
||||
b.iter(|| tracing::info!("hello world!"))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -1,136 +0,0 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use tracing::Level;
|
||||
|
||||
use tracing::{span, Event, Id, Metadata};
|
||||
|
||||
/// A subscriber that is enabled but otherwise does nothing.
|
||||
struct EnabledSubscriber;
|
||||
|
||||
impl tracing::Subscriber for EnabledSubscriber {
|
||||
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
|
||||
let _ = span;
|
||||
Id::from_u64(0xDEAD_FACE)
|
||||
}
|
||||
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
let _ = event;
|
||||
}
|
||||
|
||||
fn record(&self, span: &Id, values: &span::Record<'_>) {
|
||||
let _ = (span, values);
|
||||
}
|
||||
|
||||
fn record_follows_from(&self, span: &Id, follows: &Id) {
|
||||
let _ = (span, follows);
|
||||
}
|
||||
|
||||
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||
let _ = metadata;
|
||||
true
|
||||
}
|
||||
|
||||
fn enter(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
|
||||
fn exit(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
}
|
||||
|
||||
const NOP_LOGGER: NopLogger = NopLogger;
|
||||
|
||||
struct NopLogger;
|
||||
|
||||
impl log::Log for NopLogger {
|
||||
fn enabled(&self, _metadata: &log::Metadata) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
let mut this = self;
|
||||
let _ = write!(this, "{}", record.args());
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
impl Write for &NopLogger {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
black_box(s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
const N_SPANS: usize = 100;
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut c = c.benchmark_group("global/subscriber");
|
||||
let _ = tracing::subscriber::set_global_default(EnabledSubscriber);
|
||||
let _ = log::set_logger(&NOP_LOGGER);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
c.bench_function("span_no_fields", |b| b.iter(|| span!(Level::TRACE, "span")));
|
||||
|
||||
c.bench_function("event", |b| {
|
||||
b.iter(|| {
|
||||
tracing::event!(Level::TRACE, "hello");
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("enter_span", |b| {
|
||||
let span = span!(Level::TRACE, "span");
|
||||
#[allow(clippy::unit_arg)]
|
||||
b.iter(|| black_box(span.in_scope(|| {})))
|
||||
});
|
||||
|
||||
c.bench_function("span_repeatedly", |b| {
|
||||
#[inline]
|
||||
fn mk_span(i: u64) -> tracing::Span {
|
||||
span!(Level::TRACE, "span", i = i)
|
||||
}
|
||||
|
||||
let n = black_box(N_SPANS);
|
||||
b.iter(|| (0..n).fold(mk_span(0), |_, i| mk_span(i as u64)))
|
||||
});
|
||||
|
||||
c.bench_function("span_with_fields", |b| {
|
||||
b.iter(|| {
|
||||
span!(
|
||||
Level::TRACE,
|
||||
"span",
|
||||
foo = "foo",
|
||||
bar = "bar",
|
||||
baz = 3,
|
||||
quuux = tracing::field::debug(0.99)
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_dispatch(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("global/dispatch");
|
||||
let _ = tracing::subscriber::set_global_default(EnabledSubscriber);
|
||||
let _ = log::set_logger(&NOP_LOGGER);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
group.bench_function("get_ref", |b| {
|
||||
b.iter(|| {
|
||||
tracing::dispatcher::get_default(|current| {
|
||||
black_box(¤t);
|
||||
})
|
||||
})
|
||||
});
|
||||
group.bench_function("get_clone", |b| {
|
||||
b.iter(|| {
|
||||
let current = tracing::dispatcher::get_default(|current| current.clone());
|
||||
black_box(current);
|
||||
})
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark, bench_dispatch);
|
||||
criterion_main!(benches);
|
|
@ -1,101 +0,0 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use tracing::Level;
|
||||
|
||||
struct FakeEmptySpan {
|
||||
inner: Option<(usize, std::sync::Arc<()>)>,
|
||||
meta: Option<&'static ()>,
|
||||
}
|
||||
|
||||
impl FakeEmptySpan {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
inner: None,
|
||||
meta: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FakeEmptySpan {
|
||||
fn drop(&mut self) {
|
||||
black_box(&self.inner);
|
||||
black_box(&self.meta);
|
||||
}
|
||||
}
|
||||
|
||||
fn bench_no_subscriber(c: &mut Criterion) {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let mut group = c.benchmark_group("no_subscriber");
|
||||
|
||||
group.bench_function("span", |b| {
|
||||
b.iter(|| {
|
||||
let span = tracing::span!(Level::TRACE, "span");
|
||||
black_box(&span);
|
||||
})
|
||||
});
|
||||
group.bench_function("span_enter", |b| {
|
||||
b.iter(|| {
|
||||
let span = tracing::span!(Level::TRACE, "span");
|
||||
let _e = span.enter();
|
||||
})
|
||||
});
|
||||
group.bench_function("empty_span", |b| {
|
||||
b.iter(|| {
|
||||
let span = tracing::span::Span::none();
|
||||
black_box(&span);
|
||||
});
|
||||
});
|
||||
group.bench_function("empty_struct", |b| {
|
||||
b.iter(|| {
|
||||
let span = FakeEmptySpan::new();
|
||||
black_box(&span);
|
||||
})
|
||||
});
|
||||
group.bench_function("event", |b| {
|
||||
b.iter(|| {
|
||||
tracing::event!(Level::TRACE, "hello");
|
||||
})
|
||||
});
|
||||
group.bench_function("relaxed_load", |b| {
|
||||
let foo = AtomicUsize::new(1);
|
||||
b.iter(|| black_box(foo.load(Ordering::Relaxed)));
|
||||
});
|
||||
group.bench_function("acquire_load", |b| {
|
||||
let foo = AtomicUsize::new(1);
|
||||
b.iter(|| black_box(foo.load(Ordering::Acquire)))
|
||||
});
|
||||
group.bench_function("log", |b| {
|
||||
b.iter(|| {
|
||||
log::log!(log::Level::Info, "log");
|
||||
})
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn bench_fields(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("no_subscriber_field");
|
||||
group.bench_function("span", |b| {
|
||||
b.iter(|| {
|
||||
black_box(tracing::span!(
|
||||
Level::TRACE,
|
||||
"span",
|
||||
foo = tracing::field::display(format!("bar {:?}", 2))
|
||||
));
|
||||
})
|
||||
});
|
||||
group.bench_function("event", |b| {
|
||||
b.iter(|| {
|
||||
tracing::event!(
|
||||
Level::TRACE,
|
||||
foo = tracing::field::display(format!("bar {:?}", 2))
|
||||
);
|
||||
})
|
||||
});
|
||||
group.bench_function("log", |b| {
|
||||
b.iter(|| log::log!(log::Level::Trace, "{}", format!("bar {:?}", 2)))
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_no_subscriber, bench_fields);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,160 @@
|
|||
#![allow(dead_code)]
|
||||
use criterion::{black_box, measurement::WallTime, Bencher};
|
||||
use tracing::{field, span, Event, Id, Metadata};
|
||||
|
||||
use std::{
|
||||
fmt::{self, Write},
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
pub fn for_all_recording(
|
||||
group: &mut criterion::BenchmarkGroup<'_, WallTime>,
|
||||
mut iter: impl FnMut(&mut Bencher<'_, WallTime>),
|
||||
) {
|
||||
// first, run benchmarks with no subscriber
|
||||
group.bench_function("none", &mut iter);
|
||||
|
||||
// then, run benchmarks with a scoped default subscriber
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
group.bench_function("scoped", &mut iter)
|
||||
});
|
||||
|
||||
let subscriber = VisitingSubscriber(Mutex::new(String::from("")));
|
||||
tracing::subscriber::with_default(subscriber, || {
|
||||
group.bench_function("scoped_recording", &mut iter);
|
||||
});
|
||||
|
||||
// finally, set a global default subscriber, and run the benchmarks again.
|
||||
tracing::subscriber::set_global_default(EnabledSubscriber)
|
||||
.expect("global default should not have already been set!");
|
||||
let _ = log::set_logger(&NOP_LOGGER);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
group.bench_function("global", &mut iter);
|
||||
}
|
||||
|
||||
pub fn for_all_dispatches(
|
||||
group: &mut criterion::BenchmarkGroup<'_, WallTime>,
|
||||
mut iter: impl FnMut(&mut Bencher<'_, WallTime>),
|
||||
) {
|
||||
// first, run benchmarks with no subscriber
|
||||
group.bench_function("none", &mut iter);
|
||||
|
||||
// then, run benchmarks with a scoped default subscriber
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
group.bench_function("scoped", &mut iter)
|
||||
});
|
||||
|
||||
// finally, set a global default subscriber, and run the benchmarks again.
|
||||
tracing::subscriber::set_global_default(EnabledSubscriber)
|
||||
.expect("global default should not have already been set!");
|
||||
let _ = log::set_logger(&NOP_LOGGER);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
group.bench_function("global", &mut iter);
|
||||
}
|
||||
|
||||
const NOP_LOGGER: NopLogger = NopLogger;
|
||||
|
||||
struct NopLogger;
|
||||
|
||||
impl log::Log for NopLogger {
|
||||
fn enabled(&self, _metadata: &log::Metadata) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
let mut this = self;
|
||||
let _ = write!(this, "{}", record.args());
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
impl Write for &NopLogger {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
black_box(s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Simulates a subscriber that records span data.
|
||||
struct VisitingSubscriber(Mutex<String>);
|
||||
|
||||
struct Visitor<'a>(MutexGuard<'a, String>);
|
||||
|
||||
impl<'a> field::Visit for Visitor<'a> {
|
||||
fn record_debug(&mut self, _field: &field::Field, value: &dyn fmt::Debug) {
|
||||
let _ = write!(&mut *self.0, "{:?}", value);
|
||||
}
|
||||
}
|
||||
|
||||
impl tracing::Subscriber for VisitingSubscriber {
|
||||
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
|
||||
let mut visitor = Visitor(self.0.lock().unwrap());
|
||||
span.record(&mut visitor);
|
||||
Id::from_u64(0xDEAD_FACE)
|
||||
}
|
||||
|
||||
fn record(&self, _span: &Id, values: &span::Record<'_>) {
|
||||
let mut visitor = Visitor(self.0.lock().unwrap());
|
||||
values.record(&mut visitor);
|
||||
}
|
||||
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
let mut visitor = Visitor(self.0.lock().unwrap());
|
||||
event.record(&mut visitor);
|
||||
}
|
||||
|
||||
fn record_follows_from(&self, span: &Id, follows: &Id) {
|
||||
let _ = (span, follows);
|
||||
}
|
||||
|
||||
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||
let _ = metadata;
|
||||
true
|
||||
}
|
||||
|
||||
fn enter(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
|
||||
fn exit(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
}
|
||||
|
||||
/// A subscriber that is enabled but otherwise does nothing.
|
||||
struct EnabledSubscriber;
|
||||
|
||||
impl tracing::Subscriber for EnabledSubscriber {
|
||||
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
|
||||
let _ = span;
|
||||
Id::from_u64(0xDEAD_FACE)
|
||||
}
|
||||
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
let _ = event;
|
||||
}
|
||||
|
||||
fn record(&self, span: &Id, values: &span::Record<'_>) {
|
||||
let _ = (span, values);
|
||||
}
|
||||
|
||||
fn record_follows_from(&self, span: &Id, follows: &Id) {
|
||||
let _ = (span, follows);
|
||||
}
|
||||
|
||||
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||
let _ = metadata;
|
||||
true
|
||||
}
|
||||
|
||||
fn enter(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
|
||||
fn exit(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use tracing::{span, Level};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_recording(&mut c.benchmark_group("span_fields"), |b| {
|
||||
b.iter(|| {
|
||||
let span = span!(
|
||||
Level::TRACE,
|
||||
"span",
|
||||
foo = "foo",
|
||||
bar = "bar",
|
||||
baz = 3,
|
||||
quuux = tracing::field::debug(0.99)
|
||||
);
|
||||
criterion::black_box(span)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,13 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use tracing::{span, Level};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_recording(&mut c.benchmark_group("span_no_fields"), |b| {
|
||||
b.iter(|| span!(Level::TRACE, "span"))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,20 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use tracing::{span, Level};
|
||||
|
||||
mod shared;
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
shared::for_all_recording(&mut c.benchmark_group("span_repeated"), |b| {
|
||||
let n = black_box(N_SPANS);
|
||||
b.iter(|| (0..n).fold(mk_span(0), |_, i| mk_span(i as u64)))
|
||||
});
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mk_span(i: u64) -> tracing::Span {
|
||||
span!(Level::TRACE, "span", i = i)
|
||||
}
|
||||
|
||||
const N_SPANS: usize = 100;
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
|
@ -1,189 +0,0 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use tracing::Level;
|
||||
|
||||
use std::{
|
||||
fmt,
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
use tracing::{field, span, Event, Id, Metadata};
|
||||
|
||||
/// A subscriber that is enabled but otherwise does nothing.
|
||||
struct EnabledSubscriber;
|
||||
|
||||
impl tracing::Subscriber for EnabledSubscriber {
|
||||
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
|
||||
let _ = span;
|
||||
Id::from_u64(0xDEAD_FACE)
|
||||
}
|
||||
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
let _ = event;
|
||||
}
|
||||
|
||||
fn record(&self, span: &Id, values: &span::Record<'_>) {
|
||||
let _ = (span, values);
|
||||
}
|
||||
|
||||
fn record_follows_from(&self, span: &Id, follows: &Id) {
|
||||
let _ = (span, follows);
|
||||
}
|
||||
|
||||
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||
let _ = metadata;
|
||||
true
|
||||
}
|
||||
|
||||
fn enter(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
|
||||
fn exit(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
}
|
||||
|
||||
/// Simulates a subscriber that records span data.
|
||||
struct VisitingSubscriber(Mutex<String>);
|
||||
|
||||
struct Visitor<'a>(MutexGuard<'a, String>);
|
||||
|
||||
impl<'a> field::Visit for Visitor<'a> {
|
||||
fn record_debug(&mut self, _field: &field::Field, value: &dyn fmt::Debug) {
|
||||
use std::fmt::Write;
|
||||
let _ = write!(&mut *self.0, "{:?}", value);
|
||||
}
|
||||
}
|
||||
|
||||
impl tracing::Subscriber for VisitingSubscriber {
|
||||
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
|
||||
let mut visitor = Visitor(self.0.lock().unwrap());
|
||||
span.record(&mut visitor);
|
||||
Id::from_u64(0xDEAD_FACE)
|
||||
}
|
||||
|
||||
fn record(&self, _span: &Id, values: &span::Record<'_>) {
|
||||
let mut visitor = Visitor(self.0.lock().unwrap());
|
||||
values.record(&mut visitor);
|
||||
}
|
||||
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
let mut visitor = Visitor(self.0.lock().unwrap());
|
||||
event.record(&mut visitor);
|
||||
}
|
||||
|
||||
fn record_follows_from(&self, span: &Id, follows: &Id) {
|
||||
let _ = (span, follows);
|
||||
}
|
||||
|
||||
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||
let _ = metadata;
|
||||
true
|
||||
}
|
||||
|
||||
fn enter(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
|
||||
fn exit(&self, span: &Id) {
|
||||
let _ = span;
|
||||
}
|
||||
}
|
||||
|
||||
const N_SPANS: usize = 100;
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("span_no_fields", |b| {
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
b.iter(|| span!(Level::TRACE, "span"))
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("enter_span", |b| {
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
let span = span!(Level::TRACE, "span");
|
||||
#[allow(clippy::unit_arg)]
|
||||
b.iter(|| black_box(span.in_scope(|| {})))
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("span_repeatedly", |b| {
|
||||
#[inline]
|
||||
fn mk_span(i: u64) -> tracing::Span {
|
||||
span!(Level::TRACE, "span", i = i)
|
||||
}
|
||||
|
||||
let n = black_box(N_SPANS);
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
b.iter(|| (0..n).fold(mk_span(0), |_, i| mk_span(i as u64)))
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("span_with_fields", |b| {
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
b.iter(|| {
|
||||
span!(
|
||||
Level::TRACE,
|
||||
"span",
|
||||
foo = "foo",
|
||||
bar = "bar",
|
||||
baz = 3,
|
||||
quuux = tracing::field::debug(0.99)
|
||||
)
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("span_with_fields_record", |b| {
|
||||
let subscriber = VisitingSubscriber(Mutex::new(String::from("")));
|
||||
tracing::subscriber::with_default(subscriber, || {
|
||||
b.iter(|| {
|
||||
span!(
|
||||
Level::TRACE,
|
||||
"span",
|
||||
foo = "foo",
|
||||
bar = "bar",
|
||||
baz = 3,
|
||||
quuux = tracing::field::debug(0.99)
|
||||
)
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_dispatch(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("dispatch");
|
||||
group.bench_function("no_dispatch_get_ref", |b| {
|
||||
b.iter(|| {
|
||||
tracing::dispatcher::get_default(|current| {
|
||||
black_box(¤t);
|
||||
})
|
||||
})
|
||||
});
|
||||
group.bench_function("no_dispatch_get_clone", |b| {
|
||||
b.iter(|| {
|
||||
let current = tracing::dispatcher::get_default(|current| current.clone());
|
||||
black_box(current);
|
||||
})
|
||||
});
|
||||
group.bench_function("get_ref", |b| {
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
b.iter(|| {
|
||||
tracing::dispatcher::get_default(|current| {
|
||||
black_box(¤t);
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
group.bench_function("get_clone", |b| {
|
||||
tracing::subscriber::with_default(EnabledSubscriber, || {
|
||||
b.iter(|| {
|
||||
let current = tracing::dispatcher::get_default(|current| current.clone());
|
||||
black_box(current);
|
||||
})
|
||||
})
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark, bench_dispatch);
|
||||
criterion_main!(benches);
|
|
@ -743,6 +743,7 @@
|
|||
//! - [`tracing-forest`] provides a subscriber that preserves contextual coherence by
|
||||
//! grouping together logs from the same spans during writing.
|
||||
//! - [`tracing-loki`] provides a layer for shipping logs to [Grafana Loki].
|
||||
//! - [`tracing-logfmt`] provides a layer that formats events and spans into the logfmt format.
|
||||
//!
|
||||
//! 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!
|
||||
|
@ -779,6 +780,7 @@
|
|||
//! [`tracing-forest`]: https://crates.io/crates/tracing-forest
|
||||
//! [`tracing-loki`]: https://crates.io/crates/tracing-loki
|
||||
//! [Grafana Loki]: https://grafana.com/oss/loki/
|
||||
//! [`tracing-logfmt`]: https://crates.io/crates/tracing-logfmt
|
||||
//!
|
||||
//! <pre class="ignore" style="white-space:normal;font:inherit;">
|
||||
//! <strong>Note</strong>: Some of these ecosystem crates are currently
|
||||
|
@ -809,7 +811,7 @@
|
|||
//!
|
||||
//! ```toml
|
||||
//! [dependencies]
|
||||
//! tracing = { version = "0.1.35", default-features = false }
|
||||
//! tracing = { version = "0.1.36", default-features = false }
|
||||
//! ```
|
||||
//!
|
||||
//! <pre class="ignore" style="white-space:normal;font:inherit;">
|
||||
|
@ -892,7 +894,7 @@
|
|||
//! [flags]: #crate-feature-flags
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg), deny(rustdoc::broken_intra_doc_links))]
|
||||
#![doc(html_root_url = "https://docs.rs/tracing/0.1.35")]
|
||||
#![doc(html_root_url = "https://docs.rs/tracing/0.1.36")]
|
||||
#![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/"
|
||||
|
|
|
@ -1136,7 +1136,7 @@ impl Span {
|
|||
///
|
||||
/// // Now, record a value for parting as well.
|
||||
/// // (note that the field name is passed as a string slice)
|
||||
/// span.record("parting", &"goodbye world!");
|
||||
/// span.record("parting", "goodbye world!");
|
||||
/// ```
|
||||
/// However, it may also be used to record a _new_ value for a field whose
|
||||
/// value was already recorded:
|
||||
|
@ -1154,7 +1154,7 @@ impl Span {
|
|||
/// }
|
||||
/// Err(_) => {
|
||||
/// // Things are no longer okay!
|
||||
/// span.record("is_okay", &false);
|
||||
/// span.record("is_okay", false);
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -1181,17 +1181,17 @@ impl Span {
|
|||
/// // 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");
|
||||
/// 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");
|
||||
/// span.record("parting", "you will be remembered");
|
||||
/// ```
|
||||
///
|
||||
/// [`field::Empty`]: super::field::Empty
|
||||
/// [`Metadata`]: super::Metadata
|
||||
pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
|
||||
pub fn record<Q: ?Sized, V>(&self, field: &Q, value: V) -> &Self
|
||||
where
|
||||
Q: field::AsField,
|
||||
V: field::Value,
|
||||
|
@ -1201,7 +1201,7 @@ impl Span {
|
|||
self.record_all(
|
||||
&meta
|
||||
.fields()
|
||||
.value_set(&[(&field, Some(value as &dyn field::Value))]),
|
||||
.value_set(&[(&field, Some(&value as &dyn field::Value))]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1614,4 +1614,10 @@ mod test {
|
|||
impl AssertSync for Span {}
|
||||
impl AssertSync for Entered<'_> {}
|
||||
impl AssertSync for EnteredSpan {}
|
||||
|
||||
#[test]
|
||||
fn test_record_backwards_compat() {
|
||||
Span::current().record("some-key", &"some text");
|
||||
Span::current().record("some-key", &false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ pub use tracing_core::subscriber::*;
|
|||
#[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.
|
||||
/// Sets this [`Subscriber`] as the default for the current thread 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.
|
||||
/// [`Event`].
|
||||
///
|
||||
///
|
||||
/// [`Span`]: super::span::Span
|
||||
/// [`Subscriber`]: super::subscriber::Subscriber
|
||||
|
@ -43,13 +43,10 @@ where
|
|||
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`]
|
||||
/// Sets the [`Subscriber`] as the default for the current thread 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.
|
||||
/// The default subscriber is used when creating a new [`Span`] or [`Event`].
|
||||
///
|
||||
/// [`Span`]: super::span::Span
|
||||
/// [`Subscriber`]: super::subscriber::Subscriber
|
||||
|
|
|
@ -474,3 +474,27 @@ fn option_ref_mut_values() {
|
|||
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn string_field() {
|
||||
let (subscriber, handle) = subscriber::mock()
|
||||
.event(event::mock().with_fields(field::mock("my_string").with_value(&"hello").only()))
|
||||
.event(
|
||||
event::mock().with_fields(field::mock("my_string").with_value(&"hello world!").only()),
|
||||
)
|
||||
.done()
|
||||
.run_with_handle();
|
||||
with_default(subscriber, || {
|
||||
let mut my_string = String::from("hello");
|
||||
|
||||
tracing::event!(Level::INFO, my_string);
|
||||
|
||||
// the string is not moved by using it as a field!
|
||||
my_string.push_str(" world!");
|
||||
|
||||
tracing::event!(Level::INFO, my_string);
|
||||
});
|
||||
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче