diff --git a/console-subscriber/src/builder.rs b/console-subscriber/src/builder.rs index 85406c8ec..25eadcf21 100644 --- a/console-subscriber/src/builder.rs +++ b/console-subscriber/src/builder.rs @@ -333,6 +333,10 @@ impl Builder { self.recording_path = Some(path.into()); } + if let Some(capacity) = usize_from_env("TOKIO_CONSOLE_BUFFER_CAPACITY") { + self.event_buffer_capacity = capacity; + } + self } @@ -765,3 +769,14 @@ fn duration_from_env(var_name: &str) -> Option { ), } } + +fn usize_from_env(var_name: &str) -> Option { + let var = std::env::var(var_name).ok()?; + match var.parse::() { + Ok(num) => Some(num), + Err(e) => panic!( + "failed to parse a usize from `{}={:?}`: {}", + var_name, var, e + ), + } +}