Skip to content

Commit fbadf2f

Browse files
authored
feat(subscriber): rename TasksLayer to ConsoleLayer (#207)
The `TasksLayer` type doesn't *just* record data from task spans; it also records async op and resource spans and events. When it was initially added, it only recorded task data, and it was named `TasksLayer` because I wasn't sure if we were eventually going to add other layers for other kinds of data or not. Now that it also collects the async op and resource spans, we should maybe give it a name that doesn't suggest it's _specifically_ for tasks. This branch renames `TasksLayer` to `ConsoleLayer`. The other option would be to just call it `console_subscriber::Layer`. But, I'm not as big a fan of that, as it means that if the `tracing_subscriber::Layer` trait is also in scope, the `console_subscriber::Layer` type would always have to be prefixed; it can't be imported. So, I thought `ConsoleLayer` was better.
1 parent 6261e15 commit fbadf2f

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

console-subscriber/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ For programmatic configuration, a [builder interface][builder] is also provided:
9595
```rust
9696
use std::time::Duration;
9797

98-
console_subscriber::TasksLayer::builder()
98+
console_subscriber::ConsoleLayer::builder()
9999
// set how long the console will retain data from completed tasks
100100
.retention(Duration::from_secs(60))
101101
// set the address the server is bound to

console-subscriber/src/builder.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Server, TasksLayer};
1+
use super::{ConsoleLayer, Server};
22
use std::{
33
net::{SocketAddr, ToSocketAddrs},
44
path::PathBuf,
@@ -14,7 +14,7 @@ use tracing_subscriber::{
1414
registry::LookupSpan,
1515
};
1616

17-
/// Builder for configuring [`TasksLayer`]s.
17+
/// Builder for configuring [`ConsoleLayer`]s.
1818
#[derive(Clone, Debug)]
1919
pub struct Builder {
2020
/// The maximum capacity for the channel of events from the subscriber to
@@ -41,10 +41,10 @@ pub struct Builder {
4141
impl Default for Builder {
4242
fn default() -> Self {
4343
Self {
44-
event_buffer_capacity: TasksLayer::DEFAULT_EVENT_BUFFER_CAPACITY,
45-
client_buffer_capacity: TasksLayer::DEFAULT_CLIENT_BUFFER_CAPACITY,
46-
publish_interval: TasksLayer::DEFAULT_PUBLISH_INTERVAL,
47-
retention: TasksLayer::DEFAULT_RETENTION,
44+
event_buffer_capacity: ConsoleLayer::DEFAULT_EVENT_BUFFER_CAPACITY,
45+
client_buffer_capacity: ConsoleLayer::DEFAULT_CLIENT_BUFFER_CAPACITY,
46+
publish_interval: ConsoleLayer::DEFAULT_PUBLISH_INTERVAL,
47+
retention: ConsoleLayer::DEFAULT_RETENTION,
4848
server_addr: SocketAddr::new(Server::DEFAULT_IP, Server::DEFAULT_PORT),
4949
recording_path: None,
5050
}
@@ -57,7 +57,7 @@ impl Builder {
5757
///
5858
/// When this channel is at capacity, additional events will be dropped.
5959
///
60-
/// By default, this is [`TasksLayer::DEFAULT_EVENT_BUFFER_CAPACITY`].
60+
/// By default, this is [`ConsoleLayer::DEFAULT_EVENT_BUFFER_CAPACITY`].
6161
pub fn event_buffer_capacity(self, event_buffer_capacity: usize) -> Self {
6262
Self {
6363
event_buffer_capacity,
@@ -70,7 +70,7 @@ impl Builder {
7070
///
7171
/// When this channel is at capacity, the client may be disconnected.
7272
///
73-
/// By default, this is [`TasksLayer::DEFAULT_CLIENT_BUFFER_CAPACITY`].
73+
/// By default, this is [`ConsoleLayer::DEFAULT_CLIENT_BUFFER_CAPACITY`].
7474
pub fn client_buffer_capacity(self, client_buffer_capacity: usize) -> Self {
7575
Self {
7676
client_buffer_capacity,
@@ -83,7 +83,7 @@ impl Builder {
8383
/// A shorter duration will allow clients to update more frequently, but may
8484
/// result in the program spending more time preparing task data updates.
8585
///
86-
/// By default, this is [`TasksLayer::DEFAULT_PUBLISH_INTERVAL`].
86+
/// By default, this is [`ConsoleLayer::DEFAULT_PUBLISH_INTERVAL`].
8787
pub fn publish_interval(self, publish_interval: Duration) -> Self {
8888
Self {
8989
publish_interval,
@@ -98,7 +98,7 @@ impl Builder {
9898
/// will reduce memory usage, but less historical data from completed tasks
9999
/// will be retained.
100100
///
101-
/// By default, this is [`TasksLayer::DEFAULT_RETENTION`].
101+
/// By default, this is [`ConsoleLayer::DEFAULT_RETENTION`].
102102
pub fn retention(self, retention: Duration) -> Self {
103103
Self { retention, ..self }
104104
}
@@ -122,9 +122,9 @@ impl Builder {
122122
}
123123
}
124124

125-
/// Completes the builder, returning a [`TasksLayer`] and [`Server`] task.
126-
pub fn build(self) -> (TasksLayer, Server) {
127-
TasksLayer::build(self)
125+
/// Completes the builder, returning a [`ConsoleLayer`] and [`Server`] task.
126+
pub fn build(self) -> (ConsoleLayer, Server) {
127+
ConsoleLayer::build(self)
128128
}
129129

130130
/// Configures this builder from a standard set of environment variables:
@@ -165,7 +165,7 @@ impl Builder {
165165
/// This function represents the easiest way to get started using
166166
/// tokio-console.
167167
///
168-
/// In addition to the [`TasksLayer`], which collects instrumentation data
168+
/// In addition to the [`ConsoleLayer`], which collects instrumentation data
169169
/// consumed by the console, the default [`Subscriber`][sub] initialized by this
170170
/// function also includes a [`tracing_subscriber::fmt`] layer, which logs
171171
/// tracing spans and events to stdout. Which spans and events are logged will
@@ -207,7 +207,7 @@ impl Builder {
207207
/// ```rust
208208
/// use tracing_subscriber::prelude::*;
209209
///
210-
/// let console_layer = console_subscriber::TasksLayer::builder().spawn();
210+
/// let console_layer = console_subscriber::ConsoleLayer::builder().spawn();
211211
///
212212
/// tracing_subscriber::registry()
213213
/// .with(console_layer)
@@ -237,7 +237,7 @@ impl Builder {
237237
.init();
238238
}
239239

240-
/// Returns a new `tracing` [`Layer`] consisting of a [`TasksLayer`]
240+
/// Returns a new `tracing` [`Layer`] consisting of a [`ConsoleLayer`]
241241
/// and a [filter] that enables the spans and events required by the console.
242242
///
243243
/// This function spawns the console subscriber's [`Server`] in its own Tokio
@@ -276,7 +276,7 @@ impl Builder {
276276
/// ```rust
277277
/// use tracing_subscriber::prelude::*;
278278
///
279-
/// let console_layer = console_subscriber::TasksLayer::builder()
279+
/// let console_layer = console_subscriber::ConsoleLayer::builder()
280280
/// .with_default_env()
281281
/// .spawn();
282282
///
@@ -342,7 +342,7 @@ impl Builder {
342342
/// This function represents the easiest way to get started using
343343
/// tokio-console.
344344
///
345-
/// In addition to the [`TasksLayer`], which collects instrumentation data
345+
/// In addition to the [`ConsoleLayer`], which collects instrumentation data
346346
/// consumed by the console, the default [`Subscriber`][sub] initialized by this
347347
/// function also includes a [`tracing_subscriber::fmt`] layer, which logs
348348
/// tracing spans and events to stdout. Which spans and events are logged will
@@ -395,16 +395,16 @@ impl Builder {
395395
///
396396
/// Calling `console_subscriber::init` is equivalent to the following:
397397
/// ```rust
398-
/// use console_subscriber::TasksLayer;
398+
/// use console_subscriber::ConsoleLayer;
399399
///
400-
/// TasksLayer::builder().with_default_env().init();
400+
/// ConsoleLayer::builder().with_default_env().init();
401401
/// ```
402402
/// [`Targets`]: https://docs.rs/tracing-subscriber/latest/tracing-subscriber/filter/struct.Targets.html
403403
pub fn init() {
404-
TasksLayer::builder().with_default_env().init();
404+
ConsoleLayer::builder().with_default_env().init();
405405
}
406406

407-
/// Returns a new `tracing_subscriber` [`Layer`] configured with a [`TasksLayer`]
407+
/// Returns a new `tracing_subscriber` [`Layer`] configured with a [`ConsoleLayer`]
408408
/// and a [filter] that enables the spans and events required by the console.
409409
///
410410
/// This function spawns the console subscriber's [`Server`] in its own Tokio
@@ -415,9 +415,9 @@ pub fn init() {
415415
///
416416
/// This function is equivalent to the following:
417417
/// ```
418-
/// use console_subscriber::TasksLayer;
418+
/// use console_subscriber::ConsoleLayer;
419419
///
420-
/// let layer = TasksLayer::builder().with_default_env().spawn();
420+
/// let layer = ConsoleLayer::builder().with_default_env().spawn();
421421
/// # use tracing_subscriber::prelude::*;
422422
/// # tracing_subscriber::registry().with(layer).init(); // to suppress must_use warnings
423423
/// ```
@@ -466,7 +466,7 @@ pub fn spawn<S>() -> impl Layer<S>
466466
where
467467
S: Subscriber + for<'a> LookupSpan<'a>,
468468
{
469-
TasksLayer::builder().with_default_env().spawn::<S>()
469+
ConsoleLayer::builder().with_default_env().spawn::<S>()
470470
}
471471

472472
fn duration_from_env(var_name: &str) -> Option<Duration> {

console-subscriber/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use builder::{init, spawn};
3838
use crate::aggregator::Id;
3939
use crate::visitors::{PollOpVisitor, StateUpdateVisitor};
4040

41-
pub struct TasksLayer {
41+
pub struct ConsoleLayer {
4242
current_spans: ThreadLocal<RefCell<SpanStack>>,
4343
tx: mpsc::Sender<Event>,
4444
flush: Arc<aggregator::Flush>,
@@ -208,12 +208,12 @@ enum WakeOp {
208208
Drop,
209209
}
210210

211-
impl TasksLayer {
211+
impl ConsoleLayer {
212212
pub fn new() -> (Self, Server) {
213213
Self::builder().build()
214214
}
215215

216-
/// Returns a [`Builder`] for configuring a `TasksLayer`.
216+
/// Returns a [`Builder`] for configuring a `ConsoleLayer`.
217217
pub fn builder() -> Builder {
218218
Builder::default()
219219
}
@@ -271,7 +271,7 @@ impl TasksLayer {
271271
}
272272
}
273273

274-
impl TasksLayer {
274+
impl ConsoleLayer {
275275
pub const DEFAULT_EVENT_BUFFER_CAPACITY: usize = 1024 * 10;
276276
pub const DEFAULT_CLIENT_BUFFER_CAPACITY: usize = 1024 * 4;
277277
pub const DEFAULT_PUBLISH_INTERVAL: Duration = Duration::from_secs(1);
@@ -378,7 +378,7 @@ impl TasksLayer {
378378
}
379379
}
380380

381-
impl<S> Layer<S> for TasksLayer
381+
impl<S> Layer<S> for ConsoleLayer
382382
where
383383
S: Subscriber + for<'a> LookupSpan<'a>,
384384
{
@@ -626,9 +626,9 @@ where
626626
}
627627
}
628628

629-
impl fmt::Debug for TasksLayer {
629+
impl fmt::Debug for ConsoleLayer {
630630
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
631-
f.debug_struct("TasksLayer")
631+
f.debug_struct("ConsoleLayer")
632632
// mpsc::Sender debug impl is not very useful
633633
.field("tx", &format_args!("<...>"))
634634
.field("tx.capacity", &self.tx.capacity())

0 commit comments

Comments
 (0)