Skip to content

Commit f42a644

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dp-target-is-cow
* upstream/master: subscriber: update sharded-slab to 0.1, pool hashmap allocations (tokio-rs#1062) subscriber: remove deprecated type, structs, and methods tokio-rs#1030 core: rename Subscriber to Collect (tokio-rs#1015) chore: fix rustdoc warning in tracing-subscriber (tokio-rs#1061)
2 parents 4225d96 + 1bf9da2 commit f42a644

117 files changed

Lines changed: 2511 additions & 2287 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Tokio project, but does _not_ require the `tokio` runtime to be used.
3535

3636
### In Applications
3737

38-
In order to record trace events, executables have to use a `Subscriber`
39-
implementation compatible with `tracing`. A `Subscriber` implements a way of
38+
In order to record trace events, executables have to use a collector
39+
implementation compatible with `tracing`. A collector implements a way of
4040
collecting trace data, such as by logging it to standard output.
4141
[`tracing-subscriber`][tracing-subscriber-docs]'s [`fmt` module][fmt] provides
42-
a subscriber for logging traces with reasonable defaults. Additionally,
42+
a collector for logging traces with reasonable defaults. Additionally,
4343
`tracing-subscriber` is able to consume messages emitted by `log`-instrumented
4444
libraries and modules.
4545

@@ -51,14 +51,14 @@ tracing = "0.1"
5151
tracing-subscriber = "0.2"
5252
```
5353

54-
Then create and install a `Subscriber`, for example using [`init()`]:
54+
Then create and install a collector, for example using [`init()`]:
5555

5656
```rust
5757
use tracing::info;
5858
use tracing_subscriber;
5959

6060
fn main() {
61-
// install global subscriber configured based on RUST_LOG envvar.
61+
// install global collector configured based on RUST_LOG env var.
6262
tracing_subscriber::fmt::init();
6363

6464
let number_of_yaks = 3;
@@ -73,7 +73,7 @@ fn main() {
7373
}
7474
```
7575

76-
Using `init()` calls [`set_global_default()`] so this subscriber will be used
76+
Using `init()` calls [`set_global_default()`] so this collector will be used
7777
as the default in all threads for the remainder of the duration of the
7878
program, similar to how loggers work in the `log` crate.
7979

@@ -82,34 +82,34 @@ program, similar to how loggers work in the `log` crate.
8282
[`set_global_default`]: https://docs.rs/tracing/latest/tracing/subscriber/fn.set_global_default.html
8383

8484

85-
For more control, a subscriber can be built in stages and not set globally,
86-
but instead used to locally override the default subscriber. For example:
85+
For more control, a collector can be built in stages and not set globally,
86+
but instead used to locally override the default collector. For example:
8787

8888
```rust
8989
use tracing::{info, Level};
9090
use tracing_subscriber;
9191

9292
fn main() {
93-
let subscriber = tracing_subscriber::fmt()
93+
let collector = tracing_subscriber::fmt()
9494
// filter spans/events with level TRACE or higher.
9595
.with_max_level(Level::TRACE)
9696
// build but do not install the subscriber.
9797
.finish();
9898

99-
tracing::subscriber::with_default(subscriber, || {
99+
tracing::collector::with_default(collector, || {
100100
info!("This will be logged to stdout");
101101
});
102102
info!("This will _not_ be logged to stdout");
103103
}
104104
```
105105

106-
Any trace events generated outside the context of a subscriber will not be collected.
106+
Any trace events generated outside the context of a collector will not be collected.
107107

108-
This approach allows trace data to be collected by multiple subscribers
108+
This approach allows trace data to be collected by multiple collectors
109109
within different contexts in the program. Note that the override only applies to the
110110
currently executing thread; other threads will not see the change from with_default.
111111

112-
Once a subscriber has been set, instrumentation points may be added to the
112+
Once a collector has been set, instrumentation points may be added to the
113113
executable using the `tracing` crate's macros.
114114

115115
[`tracing-subscriber`]: https://docs.rs/tracing-subscriber/
@@ -186,7 +186,7 @@ pub fn shave_all(yaks: usize) -> usize {
186186
tracing = "0.1"
187187
```
188188

189-
Note: Libraries should *NOT* install a subscriber by using a method that calls
189+
Note: Libraries should *NOT* install a collector by using a method that calls
190190
[`set_global_default()`], as this will cause conflicts when executables try to
191191
set the default later.
192192

@@ -317,8 +317,8 @@ The crates included as part of Tracing are:
317317
* [`tracing-serde`]: A compatibility layer for serializing trace data with
318318
`serde` (unstable).
319319

320-
* [`tracing-subscriber`]: Subscriber implementations, and utilities for
321-
implementing and composing `Subscriber`s.
320+
* [`tracing-subscriber`]: Collector implementations, and utilities for
321+
implementing and composing `Collector`s.
322322
([crates.io][sub-crates]|[docs][sub-docs])
323323

324324
* [`tracing-tower`]: Compatibility with the `tower` ecosystem (unstable).
@@ -391,11 +391,11 @@ are not maintained by the `tokio` project. These include:
391391
pretty printing them.
392392
- [`spandoc`] provides a proc macro for constructing spans from doc comments
393393
_inside_ of functions.
394-
- [`tracing-wasm`] provides a `Subscriber`/`Layer` implementation that reports
394+
- [`tracing-wasm`] provides a `Collector`/`Subscriber` implementation that reports
395395
events and spans via browser `console.log` and [User Timing API (`window.performance`)].
396396
- [`test-env-log`] takes care of initializing `tracing` for tests, based on
397397
environment variables with an `env_logger` compatible syntax.
398-
- [`tracing-unwrap`] provides convenience methods to report failed unwraps on `Result` or `Option` types to a `Subscriber`.
398+
- [`tracing-unwrap`] provides convenience methods to report failed unwraps on `Result` or `Option` types to a `Collector`.
399399
- [`diesel-tracing`] provides integration with [`diesel`] database connections.
400400
- [`tracing-tracy`] provides a way to collect [Tracy] profiles in instrumented
401401
applications.

examples/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This directory contains a collection of examples that demonstrate the use of the
55

66
- **tracing**:
77
+ `counters`: Implements a very simple metrics system to demonstrate how
8-
subscribers can consume field values as typed data.
9-
+ `sloggish`: A demo `Subscriber` implementation that mimics the output of
8+
collectors can consume field values as typed data.
9+
+ `sloggish`: A demo `Collect` implementation that mimics the output of
1010
`slog-term`'s `Compact` formatter.
1111
- **tracing-attributes**:
1212
+ `attrs-basic`: A simple example of the `#[instrument]` attribute.
@@ -17,15 +17,15 @@ This directory contains a collection of examples that demonstrate the use of the
1717
record function arguments.
1818
- **tracing-subscriber**:
1919
+ `fmt`: Demonstrates the use of the `fmt` module in `tracing-subscriber`,
20-
which provides a subscriber implementation that logs traces to the console.
20+
which provides a collector implementation that logs traces to the console.
2121
+ `fmt-stderr`: Demonstrates overriding the output stream used by the `fmt`
22-
subscriber.
23-
+ `fmt-custom-field`: Demonstrates overriding how the `fmt` subscriber formats
22+
collector.
23+
+ `fmt-custom-field`: Demonstrates overriding how the `fmt` collector formats
2424
fields on spans and events.
25-
+ `fmt-custom-event`: Demonstrates overriding how the `fmt` subscriber formats
25+
+ `fmt-custom-event`: Demonstrates overriding how the `fmt` collector formats
2626
events.
2727
+ `subscriber-filter`: Demonstrates the `tracing-subscriber::filter` module,
28-
which provides a layer which adds configurable filtering to a subscriber
28+
which provides a layer which adds configurable filtering to a collector
2929
implementation.
3030
+ `tower-load`: Demonstrates how dynamically reloadable filters can be used to
3131
debug a server under load in production.
@@ -55,7 +55,7 @@ This directory contains a collection of examples that demonstrate the use of the
5555
simple `tower` HTTP/1.1 server.
5656
- **tracing-serde**:
5757
+ `serde-yak-shave`: Demonstrates the use of `tracing-serde` by implementing a
58-
subscriber that emits trace output as JSON.
58+
collector that emits trace output as JSON.
5959
- **tracing-log**:
6060
+ `hyper-echo`: Demonstrates how `tracing-log` can be used to record
6161
unstructured logs from dependencies as `tracing` events, by instrumenting

examples/examples/all-levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
// all spans/events with a level higher than TRACE (e.g, info, warn, etc.)
1212
// will be written to stdout.
1313
.with_max_level(Level::TRACE)
14-
// sets this to be the default, global subscriber for this application.
14+
// sets this to be the default, global collector for this application.
1515
.init();
1616
event();
1717

examples/examples/attrs-args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
.with_env_filter("attrs_args=trace")
3232
.finish();
3333

34-
tracing::subscriber::with_default(subscriber, || {
34+
tracing::collect::with_default(subscriber, || {
3535
let n = 5;
3636
let sequence = fibonacci_seq(n);
3737
info!("The first {} fibonacci numbers are {:?}", n, sequence);

examples/examples/attrs-basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
let subscriber = tracing_subscriber::fmt()
1515
.with_env_filter("attrs_basic=trace")
1616
.finish();
17-
tracing::subscriber::with_default(subscriber, || {
17+
tracing::collect::with_default(subscriber, || {
1818
let num_recs = 1;
1919

2020
let span = span!(Level::TRACE, "get_band_rec", ?num_recs);

examples/examples/attrs-literal-field-names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
let subscriber = tracing_subscriber::fmt()
1515
.with_env_filter("attrs_literal_field_names=trace")
1616
.finish();
17-
tracing::subscriber::with_default(subscriber, || {
17+
tracing::collect::with_default(subscriber, || {
1818
let span = span!(Level::TRACE, "get_band_rec", "guid:x-request-id" = "abcdef");
1919
let _enter = span.enter();
2020
suggest_band();

examples/examples/counters.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#![deny(rust_2018_idioms)]
22

33
use tracing::{
4+
collect::{self, Collect},
45
field::{Field, Visit},
5-
info, span,
6-
subscriber::{self, Subscriber},
7-
warn, Event, Id, Level, Metadata,
6+
info, span, warn, Event, Id, Level, Metadata,
87
};
98

109
use std::{
@@ -19,7 +18,7 @@ use std::{
1918
#[derive(Clone)]
2019
struct Counters(Arc<RwLock<HashMap<String, AtomicUsize>>>);
2120

22-
struct CounterSubscriber {
21+
struct CounterCollector {
2322
ids: AtomicUsize,
2423
counters: Counters,
2524
}
@@ -50,17 +49,17 @@ impl<'a> Visit for Count<'a> {
5049
fn record_debug(&mut self, _: &Field, _: &dyn fmt::Debug) {}
5150
}
5251

53-
impl CounterSubscriber {
52+
impl CounterCollector {
5453
fn visitor(&self) -> Count<'_> {
5554
Count {
5655
counters: self.counters.0.read().unwrap(),
5756
}
5857
}
5958
}
6059

61-
impl Subscriber for CounterSubscriber {
62-
fn register_callsite(&self, meta: &Metadata<'_>) -> subscriber::Interest {
63-
let mut interest = subscriber::Interest::never();
60+
impl Collect for CounterCollector {
61+
fn register_callsite(&self, meta: &Metadata<'_>) -> collect::Interest {
62+
let mut interest = collect::Interest::never();
6463
for key in meta.fields() {
6564
let name = key.name();
6665
if name.contains("count") {
@@ -70,7 +69,7 @@ impl Subscriber for CounterSubscriber {
7069
.unwrap()
7170
.entry(name.to_owned())
7271
.or_insert_with(|| AtomicUsize::new(0));
73-
interest = subscriber::Interest::always();
72+
interest = collect::Interest::always();
7473
}
7574
}
7675
interest
@@ -109,20 +108,20 @@ impl Counters {
109108
}
110109
}
111110

112-
fn new() -> (Self, CounterSubscriber) {
111+
fn new() -> (Self, CounterCollector) {
113112
let counters = Counters(Arc::new(RwLock::new(HashMap::new())));
114-
let subscriber = CounterSubscriber {
113+
let collector = CounterCollector {
115114
ids: AtomicUsize::new(1),
116115
counters: counters.clone(),
117116
};
118-
(counters, subscriber)
117+
(counters, collector)
119118
}
120119
}
121120

122121
fn main() {
123-
let (counters, subscriber) = Counters::new();
122+
let (counters, collector) = Counters::new();
124123

125-
tracing::subscriber::set_global_default(subscriber).unwrap();
124+
tracing::collect::set_global_default(collector).unwrap();
126125

127126
let mut foo: u64 = 2;
128127
span!(Level::TRACE, "my_great_span", foo_count = &foo).in_scope(|| {

examples/examples/custom-error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn do_another_thing(
5151
#[tracing::instrument]
5252
fn main() {
5353
tracing_subscriber::registry()
54-
.with(tracing_subscriber::fmt::layer())
54+
.with(tracing_subscriber::fmt::subscriber())
5555
// The `ErrorLayer` subscriber layer enables the use of `SpanTrace`.
5656
.with(ErrorLayer::default())
5757
.init();

examples/examples/fmt-stderr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tracing::error;
55
fn main() {
66
let subscriber = tracing_subscriber::fmt().with_writer(io::stderr).finish();
77

8-
tracing::subscriber::with_default(subscriber, || {
8+
tracing::collect::with_default(subscriber, || {
99
error!("This event will be printed to `stderr`.");
1010
});
1111
}

examples/examples/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
// all spans/events with a level higher than DEBUG (e.g, info, warn, etc.)
1010
// will be written to stdout.
1111
.with_max_level(Level::DEBUG)
12-
// sets this to be the default, global subscriber for this application.
12+
// sets this to be the default, global collector for this application.
1313
.init();
1414

1515
let number_of_yaks = 3;

0 commit comments

Comments
 (0)