Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] registry part 2 #412

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
4f5e737
sketch traits
hawkw Oct 25, 2019
0d3c78f
copy over david's code
hawkw Oct 28, 2019
957aeff
copy over more of david's code
hawkw Oct 28, 2019
987fb09
hack up david's code a bit
hawkw Oct 28, 2019
e47b2a4
it compiles
Oct 28, 2019
8b124d0
replace current span stack with fmt's
Oct 29, 2019
0e35fd5
address some of eliza's comments.
Oct 29, 2019
e1835bc
Change span store to be `Arc<Slab<RwLock<BigSpan>>>`, from `Arc<Slab<…
Oct 29, 2019
dc20476
undo `RwLock`
Oct 29, 2019
8535077
Rename BigSpan -> Data; implement fmt-style ref counting.
Oct 29, 2019
21866a3
address eliza's comments.
Oct 29, 2019
60aad49
Use release in drop; handle panic safety.
Oct 29, 2019
4765d31
add todos
Oct 29, 2019
303ca31
remove unused.
Oct 29, 2019
ebbfb5a
more fixes, sorry
Oct 29, 2019
3aa4398
thank u, eliza
Oct 29, 2019
a249a67
remove visitor; un-implement events.
Oct 29, 2019
d607ad6
introduce extensions, copied from `http::Extensions`
davidbarsky Oct 30, 2019
5141d35
copy over FmtLayer{Builder}
davidbarsky Oct 30, 2019
631cd62
make methods public
davidbarsky Oct 30, 2019
0cb934a
start examples
davidbarsky Oct 30, 2019
80f4edd
bad sloggish subscriber example
davidbarsky Oct 30, 2019
96b8839
add generic params to FmtLayer; implement a (possibly wrong) `current…
davidbarsky Oct 30, 2019
8b253ed
huh
davidbarsky Oct 30, 2019
f14b505
i am bad at traits [fails to run example]
davidbarsky Oct 30, 2019
63b723e
WIP
davidbarsky Oct 31, 2019
d57fbf0
it works, but i hate it
davidbarsky Oct 31, 2019
d4b6282
remove dead code
davidbarsky Oct 31, 2019
fb438f3
Tidy, add debug + doc comments.
davidbarsky Oct 31, 2019
e3f68ec
remove breaking bound; allowing builder to function correctly.
davidbarsky Oct 31, 2019
ae969fa
add color-backtrace for debugging
davidbarsky Oct 31, 2019
7a4c321
visit spans with each event
davidbarsky Oct 31, 2019
bc4c8c2
made more complex examples, added an `EventFormatter` builder method,…
davidbarsky Oct 31, 2019
c0484b5
implement `WithExtensions`
davidbarsky Oct 31, 2019
e924afa
hmm
davidbarsky Oct 31, 2019
da324b6
with extensions
davidbarsky Oct 31, 2019
7a9a713
try fix
davidbarsky Oct 31, 2019
7bffbc7
try "do what fmt does"
davidbarsky Nov 1, 2019
a4d6f65
handle contextual parents
davidbarsky Nov 1, 2019
e6496f6
Cleanup parent visitation code at the cost of allocation
davidbarsky Nov 1, 2019
8f75dbc
SVO
davidbarsky Nov 5, 2019
8947cae
apply suggestions
Nov 7, 2019
38247d1
introduce `log` integration
Nov 7, 2019
3187388
do parents _right_
Nov 7, 2019
fbb4f23
PR comments
Nov 8, 2019
9854fa4
docs and nit addressing
Nov 8, 2019
2934fd3
more fixes
Nov 8, 2019
4a18905
get tests & examples to compile
Nov 8, 2019
d478268
compiles now!
Nov 8, 2019
3c7f4eb
docs improvements
hawkw Nov 8, 2019
56deff7
Apply docs suggestions from code review
hawkw Nov 8, 2019
92b07d4
Apply suggestions from code review
hawkw Nov 8, 2019
c942c19
remove `is_interested`
hawkw Nov 8, 2019
416526b
make registry feature stable, default enabled
hawkw Nov 8, 2019
2689906
api polish, bring back fmt subscriber
hawkw Nov 8, 2019
059ed97
remove `color-backtrace`
Nov 8, 2019
6beeb57
remove remaining examples
Nov 8, 2019
09b5f40
use 0.0.6 slab
Nov 8, 2019
d3794d0
address some unused import warnings
Nov 9, 2019
dcbc6d3
rm `span.rs`
Nov 9, 2019
3d819a0
reduce additional warnings
Nov 9, 2019
2174dc2
dox
Nov 9, 2019
bf170f4
more
Nov 9, 2019
8efa918
impl builder methods
Nov 9, 2019
d48191b
Apply docs suggestions from code review
hawkw Nov 9, 2019
65946ca
add with_writer docs
hawkw Nov 9, 2019
e9437b3
make method names more consistent
hawkw Nov 9, 2019
c4c528e
shorter & more consistent builder method names
hawkw Nov 9, 2019
0e6dd75
fix doctests
hawkw Nov 9, 2019
1901f7e
add blanket LookupMetadata impl for LookupSpan
hawkw Nov 9, 2019
1b32811
remove unneeded LookupMetadata bounds
hawkw Nov 9, 2019
d9b9e54
don't expose external types in pub APIs
hawkw Nov 9, 2019
54b9878
better comment for `FormattedFields`
hawkw Nov 9, 2019
ba7d2c3
undo accidental change
hawkw Nov 9, 2019
4307d28
fix downcasting
hawkw Nov 9, 2019
20cceeb
fix test contamination from FmtLayer Always interest
hawkw Nov 9, 2019
989cf0b
move stack to the right place
hawkw Nov 9, 2019
9dc5402
fix json test
Nov 9, 2019
6048810
apply https://github.com/tokio-rs/tracing/pull/415
Nov 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
tracing = "0.1"
tracing-core = "0.1"
tracing-tower = { version = "0.1.0", path = "../tracing-tower" }
tracing-subscriber = { version = "0.1", path = "../tracing-subscriber" }
tracing-subscriber = { version = "0.1", path = "../tracing-subscriber", features = ["registry_unstable", "json", "chrono"] }
tracing-futures = { version = "0.1.0", path = "../tracing-futures" }
tracing-attributes = "0.1.2"
tracing-log = { path = "../tracing-log", version = "0.1.1", features = ["env_logger"] }
Expand Down Expand Up @@ -44,6 +44,9 @@ tower-hyper = "0.1"
tower-http-util = "0.1"
rand = "0.7"

# TODO(david): remove, but this is handy for debugging crashes
color-backtrace = { git = "https://github.com/athre0z/color-backtrace" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove before flight


# sloggish example
ansi_term = "0.11"
humantime = "1.2"
Expand Down
10 changes: 7 additions & 3 deletions examples/examples/attrs-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use tracing::{debug, info};
use tracing_attributes::instrument;
use tracing_subscriber::{
registry::{FmtLayer, Registry},
EnvFilter, Layer,
};

#[instrument]
fn nth_fibonacci(n: u64) -> u64 {
Expand All @@ -28,9 +32,9 @@ fn fibonacci_seq(to: u64) -> Vec<u64> {

fn main() {
use tracing_subscriber::fmt;
let subscriber = fmt::Subscriber::builder()
.with_env_filter("attrs_args=trace")
.finish();
let subscriber = FmtLayer::default()
.and_then(EnvFilter::try_new("attrs_basic=trace").unwrap())
.with_subscriber(Registry::default());

tracing::subscriber::with_default(subscriber, || {
let n = 5;
Expand Down
8 changes: 5 additions & 3 deletions examples/examples/attrs-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use tracing::{debug, info, span, Level};
use tracing_attributes::instrument;
use tracing_subscriber::{EnvFilter, FmtLayer, Layer, Registry};

#[instrument]
#[inline]
Expand All @@ -11,9 +12,10 @@ fn suggest_band() -> String {
}

fn main() {
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
.with_env_filter("attrs_basic=trace")
.finish();
let subscriber = FmtLayer::default()
.and_then(EnvFilter::try_new("attrs_basic=trace").unwrap())
.with_subscriber(Registry::default());

tracing::subscriber::with_default(subscriber, || {
let num_recs = 1;

Expand Down
44 changes: 44 additions & 0 deletions examples/examples/fmt-layer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#![deny(rust_2018_idioms)]
use std::io;
use tracing::{debug, Level};
use tracing_subscriber::{
fmt::format::Format,
fmt::time::ChronoUtc,
layer::Layer,
registry::{FmtLayer, Registry},
};

#[path = "fmt/yak_shave.rs"]
mod yak_shave;

fn main() {
color_backtrace::install();

let stderr = FmtLayer::builder()
.with_writer(io::stderr)
.with_event_formatter(
Format::default()
.with_timer(ChronoUtc::rfc3339())
.with_ansi(false)
.with_target(false)
.json(),
)
.build();

let stdout = FmtLayer::builder()
.with_writer(io::stdout)
.build();

let subscriber = stdout.and_then(stderr).with_subscriber(Registry::default());
tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");

let number_of_yaks = 3;
debug!("preparing to shave {} yaks", number_of_yaks);

let number_shaved = yak_shave::shave_all(number_of_yaks);

debug!(
message = "yak shaving completed.",
all_yaks_shaved = number_shaved == number_of_yaks,
);
}
6 changes: 4 additions & 2 deletions examples/examples/fmt-stderr.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![deny(rust_2018_idioms)]
use std::io;
use tracing::error;
use tracing_subscriber::{FmtLayer, Layer, Registry};

fn main() {
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
let subscriber = FmtLayer::builder()
.with_writer(io::stderr)
.finish();
.build()
.with_subscriber(Registry::default());

tracing::subscriber::with_default(subscriber, || {
error!("This event will be printed to `stderr`.");
Expand Down
24 changes: 14 additions & 10 deletions examples/examples/fmt/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#![deny(rust_2018_idioms)]
use tracing::debug;
use std::io;
use tracing::{debug, Level};
use tracing_subscriber::{
layer::Layer,
registry::{FmtLayer, Registry},
};

mod yak_shave;

fn main() {
let subscriber = tracing_subscriber::fmt::Subscriber::new();
tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");

tracing::subscriber::with_default(subscriber, || {
let number_of_yaks = 3;
debug!("preparing to shave {} yaks", number_of_yaks);
let number_of_yaks = 3;
debug!("preparing to shave {} yaks", number_of_yaks);

let number_shaved = yak_shave::shave_all(number_of_yaks);
let number_shaved = yak_shave::shave_all(number_of_yaks);

debug!(
message = "yak shaving completed.",
all_yaks_shaved = number_shaved == number_of_yaks,
);
});
debug!(
message = "yak shaving completed.",
all_yaks_shaved = number_shaved == number_of_yaks,
);
}
8 changes: 4 additions & 4 deletions examples/examples/futures-proxy-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
use tracing_subscriber::{fmt, EnvFilter};
use tracing_subscriber::{EnvFilter, Layer, FmtLayer, Registry};

let subscriber = fmt::Subscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let subscriber = FmtLayer::default()
.and_then(EnvFilter::from_default_env())
.with_subscriber(Registry::default());
tracing::subscriber::set_global_default(subscriber)?;

let listen_addr = env::args()
Expand Down
10 changes: 6 additions & 4 deletions examples/examples/futures-spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ fn subtask(number: usize) -> impl Future<Item = usize, Error = ()> {
}

fn main() {
use tracing_subscriber::fmt;
let subscriber = fmt::Subscriber::builder()
.with_max_level(Level::TRACE)
.finish();
use tracing_subscriber::{EnvFilter, FmtLayer, Layer, Registry};

let subscriber = FmtLayer::default()
.and_then(EnvFilter::try_new("futures-spawn=trace").unwrap())
.with_subscriber(Registry::default());

let _ = tracing::subscriber::set_global_default(subscriber);
tokio::run(parent_task(10));
}
12 changes: 8 additions & 4 deletions examples/examples/hyper-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use std::str;

use tracing::{debug, error, info, span, Level};
use tracing_futures::{Instrument, Instrumented};
use tracing_subscriber::{
layer::Layer,
registry::{FmtLayer, Registry},
};

type BoxFut = Box<dyn Future<Item = Response<Body>, Error = hyper::Error> + Send>;

Expand Down Expand Up @@ -109,16 +113,16 @@ fn echo(req: Request<Body>) -> Instrumented<BoxFut> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
use tracing_log::env_logger::BuilderExt;

let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_max_level(Level::TRACE)
.finish();
let stdout = FmtLayer::builder().build();
let subscriber = stdout.with_subscriber(Registry::default());

let mut builder = env_logger::Builder::new();
builder
.filter(Some("hyper_echo"), log::LevelFilter::Off)
.filter(Some("hyper"), log::LevelFilter::Trace)
.emit_traces() // from `tracing_log::env_logger::BuilderExt`
.try_init()?;
tracing::subscriber::set_global_default(subscriber)?;
tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");

let local_addr: std::net::SocketAddr = ([127, 0, 0, 1], 3000).into();
let server_span = span!(Level::TRACE, "server", %local_addr);
Expand Down
11 changes: 7 additions & 4 deletions examples/examples/subscriber-filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
mod yak_shave;

fn main() {
use tracing_subscriber::{fmt, EnvFilter};
use tracing_subscriber::{
registry::{FmtLayer, Registry},
EnvFilter, Layer,
};

let subscriber = fmt::Subscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let subscriber = FmtLayer::default()
.and_then(EnvFilter::from_default_env())
.with_subscriber(Registry::default());

tracing::subscriber::with_default(subscriber, || {
let number_of_yaks = 3;
Expand Down
8 changes: 5 additions & 3 deletions examples/examples/tower-h2-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tower_h2::{Body, RecvBody};
use tower_service::Service;
use tower_util::MakeService;
use tracing_futures::Instrument;
use tracing_subscriber::{FmtLayer, Layer, Registry};
use tracing_tower::InstrumentableService;

pub struct Conn(SocketAddr);
Expand All @@ -24,9 +25,10 @@ fn main() {
let filter = EnvFilter::from_default_env()
.add_directive("tower_h2_client=trace".parse().unwrap())
.add_directive("tracing_tower=trace".parse().unwrap());
let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(filter)
.finish();

let subscriber = FmtLayer::default()
.and_then(filter)
.with_subscriber(Registry::default());
let _ = tracing::subscriber::set_global_default(subscriber);

let mut rt = Runtime::new().unwrap();
Expand Down
7 changes: 4 additions & 3 deletions examples/examples/tower-h2-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tokio::net::TcpListener;
use tower_h2::{Body, RecvBody, Server};
use tower_service::Service;
use tracing_futures::Instrument;
use tracing_subscriber::{FmtLayer, Layer, Registry};
use tracing_tower::InstrumentMake;

type Response = http::Response<RspBody>;
Expand Down Expand Up @@ -99,9 +100,9 @@ fn main() {
let filter = EnvFilter::from_default_env()
.add_directive("tower_h2_server=trace".parse().unwrap())
.add_directive("tracing_tower=trace".parse().unwrap());
let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(filter)
.finish();
let subscriber = FmtLayer::default()
.and_then(filter)
.with_subscriber(Registry::default());
let _ = tracing::subscriber::set_global_default(subscriber);

let addr = "[::1]:8888".parse().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions examples/examples/tower-load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ use tower_hyper::server::Server;
use std::{error::Error, fmt, net::SocketAddr};
use tracing;
use tracing_futures::Instrument;
use tracing_subscriber::FmtSubscriber;
use tracing_subscriber::{reload, EnvFilter, FmtLayer, Layer, Registry};

fn main() {
let builder = FmtSubscriber::builder()
.with_env_filter("info,tower_load=debug")
.with_filter_reloading();
let handle = builder.reload_handle();
let filter = EnvFilter::try_new("info,tower_load=debug").unwrap();
let (filter, handle) = reload::Layer::new(filter);
let layer = filter.and_then(FmtLayer::default());
let subscriber = layer.with_subscriber(Registry::default());

let _ = tracing::subscriber::set_global_default(builder.finish());
let _ = tracing::subscriber::set_global_default(subscriber);

let addr = "[::1]:3000".parse().unwrap();
let admin_addr = "[::1]:3001".parse().unwrap();
Expand Down
8 changes: 7 additions & 1 deletion tracing-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ default = ["env-filter", "smallvec", "fmt", "ansi", "chrono", "tracing-log"]
env-filter = ["matchers", "regex", "lazy_static"]
fmt = ["owning_ref"]
ansi = ["fmt", "ansi_term"]
registry_unstable = []
registry_unstable = ["sharded-slab"]
json = ["tracing-serde", "serde", "serde_json"]

# Alias for `env-filter`; renamed in version 0.1.2, and will be removed in 0.2.
Expand All @@ -49,9 +49,15 @@ serde_json = { version = "1.0", optional = true }
serde = { version = "1.0", optional = true }
tracing-serde = { path = "../tracing-serde", optional = true }

# a hack, trying out a formatter
humantime = "1.2"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove before flight (unused?)


# opt-in deps
parking_lot = { version = ">= 0.7, < 0.10", features = ["owning_ref"], optional = true }

# registry
sharded-slab = { git = "https://github.com/davidbarsky/sharded-slab", optional = true }
davidbarsky marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
tracing = "0.1"
log = "0.4"
Expand Down
Loading