-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Thank you for your Pull Request. Please provide a description above and review the requirements below. Bug fixes and new features should include tests. Contributors guide: https://github.com/tokio-rs/tokio/blob/master/CONTRIBUTING.md --> ## Motivation In asynchronous systems like Tokio, interpreting traditional log messages can often be quite challenging. Since individual tasks are multiplexed on the same thread, associated events and log lines are intermixed making it difficult to trace the logic flow. Currently, none of the available logging frameworks or libraries in Rust offer the ability to trace logical paths through a futures-based program. There also are complementary goals that can be accomplished with such a system. For example, metrics / instrumentation can be tracked by observing emitted events, or trace data can be exported to a distributed tracing or event processing system. In addition, it can often be useful to generate this diagnostic data in a structured manner that can be consumed programmatically. While prior art for structured logging in Rust exists, it is not currently standardized, and is not "Tokio-friendly". ## Solution This branch adds a new library to the tokio project, `tokio-trace`. `tokio-trace` expands upon logging-style diagnostics by allowing libraries and applications to record structured events with additional information about *temporality* and *causality* --- unlike a log message, a span in `tokio-trace` has a beginning and end time, may be entered and exited by the flow of execution, and may exist within a nested tree of similar spans. In addition, `tokio-trace` spans are *structured*, with the ability to record typed data as well as textual messages. The `tokio-trace-core` crate contains the core primitives for this system, which are expected to remain stable, while `tokio-trace` crate provides a more "batteries-included" API. In particular, it provides macros which are a superset of the `log` crate's `error!`, `warn!`, `info!`, `debug!`, and `trace!` macros, allowing users to begin the process of adopting `tokio-trace` by performing a drop-in replacement. ## Notes Work on this project had previously been carried out in the [tokio-trace-prototype] repository. In addition to the `tokio-trace` and `tokio-trace-core` crates, the `tokio-trace-prototype` repo also contains prototypes or sketches of adapter, compatibility, and utility crates which provide useful functionality for `tokio-trace`, but these crates are not yet ready for a release. When this branch is merged, that repository will be archived, and the remaining unstable crates will be moved to a new `tokio-trace-nursery` repository. Remaining issues on the `tokio-trace-prototype` repo will be moved to the appropriate new repo. The crates added in this branch are not _identical_ to the current head of the `tokio-trace-prototype` repo, as I did some final clean-up and docs polish in this branch prior to merging this PR. [tokio-trace-prototype]: https://github.com/hawkw/tokio-trace-prototype Closes: #561 Signed-off-by: Eliza Weisman <[email protected]>
- Loading branch information
Showing
34 changed files
with
6,340 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
|
||
members = [ | ||
".", | ||
"tokio-trace-proc-macros", | ||
"tokio-trace-fmt", | ||
"tokio-trace-futures", | ||
|
@@ -13,3 +14,34 @@ members = [ | |
"tokio-trace-subscriber", | ||
"tokio-trace-serde", | ||
] | ||
|
||
[package] | ||
name = "tokio-trace" | ||
version = "0.0.1" | ||
authors = ["Eliza Weisman <[email protected]>"] | ||
license = "MIT" | ||
repository = "https://github.com/tokio-rs/tokio" | ||
homepage = "https://tokio.rs" | ||
description = """ | ||
A scoped, structured logging and diagnostics system. | ||
""" | ||
categories = ["development-tools::debugging", "asynchronous"] | ||
keywords = ["logging", "tracing"] | ||
|
||
# Not yet ready for production. | ||
publish = false | ||
|
||
[dependencies] | ||
tokio-trace-core = { path = "tokio-trace-core" } | ||
|
||
[dev-dependencies] | ||
ansi_term = "0.11" | ||
humantime = "1.1.1" | ||
futures = "0.1" | ||
log = "0.4" | ||
|
||
# These are used for the "basic" example from the tokio-trace-prototype repo, | ||
# which is currently not included as it used the `tokio-trace-log` crate, and | ||
# that crate is currently unstable. | ||
# env_logger = "0.5" | ||
# tokio-trace-log = { path = "../tokio-trace-log" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Tokio Contributors | ||
|
||
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: | ||
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 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. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![feature(test)] | ||
#[macro_use] | ||
extern crate tokio_trace; | ||
#[macro_use] | ||
extern crate log; | ||
extern crate test; | ||
use test::Bencher; | ||
|
||
#[bench] | ||
fn bench_span_no_subscriber(b: &mut Bencher) { | ||
b.iter(|| { | ||
span!("span"); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_log_no_logger(b: &mut Bencher) { | ||
b.iter(|| { | ||
log!(log::Level::Info, "log"); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_costly_field_no_subscriber(b: &mut Bencher) { | ||
b.iter(|| { | ||
span!( | ||
"span", | ||
foo = tokio_trace::field::display(format!("bar {:?}", 2)) | ||
); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_no_span_no_subscriber(b: &mut Bencher) { | ||
b.iter(|| {}); | ||
} | ||
|
||
#[bench] | ||
fn bench_1_atomic_load(b: &mut Bencher) { | ||
// This is just included as a baseline. | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
let foo = AtomicUsize::new(1); | ||
b.iter(|| foo.load(Ordering::Relaxed)); | ||
} |
Oops, something went wrong.