Skip to content

Commit

Permalink
subscriber: allow to customize Registry with sharded_slab Config.
Browse files Browse the repository at this point in the history
Adds CollectionBuilder with_slab_config::<S>() func to this end. This e.g.
allows to use tracing in environment with >= 4k threads.

c.f. tokio-rs#1485
  • Loading branch information
arssher committed Dec 19, 2022
1 parent 02903cb commit 48aec0a
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 85 deletions.
13 changes: 13 additions & 0 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
Expand Up @@ -654,6 +654,19 @@ impl<C, N, E, W> Subscriber<C, N, E, W> {
_inner: self._inner,
}
}

/// Updates the collector type.
pub fn set_collector<C2>(self) -> Subscriber<C2, N, E, W> {
Subscriber {
fmt_event: self.fmt_event,
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span,
make_writer: self.make_writer,
is_ansi: self.is_ansi,
log_internal_errors: self.log_internal_errors,
_inner: PhantomData,
}
}
}

impl<C> Default for Subscriber<C> {
Expand Down
11 changes: 7 additions & 4 deletions tracing-subscriber/src/fmt/format/json.rs
Expand Up @@ -507,7 +507,10 @@ impl<'a> field::Visit for JsonVisitor<'a> {
#[cfg(test)]
mod test {
use super::*;
use crate::fmt::{format::FmtSpan, test::MockMakeWriter, time::FormatTime, CollectorBuilder};
use crate::fmt::{
format::FmtSpan, test::MockMakeWriter, time::FormatTime, CollectorBuilder,
DefaultSlabConfig,
};

use tracing::{self, collect::with_default};

Expand All @@ -521,7 +524,7 @@ mod test {
}
}

fn collector() -> CollectorBuilder<JsonFields, Format<Json>> {
fn collector() -> CollectorBuilder<DefaultSlabConfig, JsonFields, Format<Json>> {
crate::fmt::CollectorBuilder::default().json()
}

Expand Down Expand Up @@ -795,7 +798,7 @@ mod test {

fn test_json<T>(
expected: &str,
builder: crate::fmt::CollectorBuilder<JsonFields, Format<Json>>,
builder: crate::fmt::CollectorBuilder<DefaultSlabConfig, JsonFields, Format<Json>>,
producer: impl FnOnce() -> T,
) {
let make_writer = MockMakeWriter::default();
Expand All @@ -817,7 +820,7 @@ mod test {

fn test_json_with_line_number<T>(
expected: &str,
builder: crate::fmt::CollectorBuilder<JsonFields, Format<Json>>,
builder: crate::fmt::CollectorBuilder<DefaultSlabConfig, JsonFields, Format<Json>>,
producer: impl FnOnce() -> T,
) {
let make_writer = MockMakeWriter::default();
Expand Down

0 comments on commit 48aec0a

Please sign in to comment.