feat(tvix/tracing): optional progressbar
Disable the progressbar on default and provide a interface for optionally enabling the progressbar. Change-Id: I0e31b1957e80cf64a8dcf65c6ceb3713975b8220 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11861 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de> Autosubmit: Simon Hauser <simon.hauser@helsinki-systems.de>
This commit is contained in:
parent
1446e3be99
commit
bd8d74a3ee
4 changed files with 19 additions and 6 deletions
|
@ -54,7 +54,9 @@ enum Commands {
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let _ = tvix_tracing::TracingBuilder::default().level(cli.log_level);
|
let _ = tvix_tracing::TracingBuilder::default()
|
||||||
|
.level(cli.log_level)
|
||||||
|
.enable_progressbar();
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Daemon {
|
Commands::Daemon {
|
||||||
|
|
|
@ -281,6 +281,7 @@ fn main() {
|
||||||
|
|
||||||
let _ = tvix_tracing::TracingBuilder::default()
|
let _ = tvix_tracing::TracingBuilder::default()
|
||||||
.level(args.log_level)
|
.level(args.log_level)
|
||||||
|
.enable_progressbar()
|
||||||
.build()
|
.build()
|
||||||
.expect("unable to set up tracing subscriber");
|
.expect("unable to set up tracing subscriber");
|
||||||
let tokio_runtime = tokio::runtime::Runtime::new().expect("failed to setup tokio runtime");
|
let tokio_runtime = tokio::runtime::Runtime::new().expect("failed to setup tokio runtime");
|
||||||
|
|
|
@ -506,7 +506,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let tracing_handle = {
|
let tracing_handle = {
|
||||||
let mut builder = tvix_tracing::TracingBuilder::default();
|
let mut builder = tvix_tracing::TracingBuilder::default();
|
||||||
builder = builder.level(cli.log_level);
|
builder = builder.level(cli.log_level).enable_progressbar();
|
||||||
#[cfg(feature = "otlp")]
|
#[cfg(feature = "otlp")]
|
||||||
{
|
{
|
||||||
if cli.otlp {
|
if cli.otlp {
|
||||||
|
|
|
@ -114,6 +114,7 @@ impl TracingHandle {
|
||||||
|
|
||||||
pub struct TracingBuilder {
|
pub struct TracingBuilder {
|
||||||
level: Level,
|
level: Level,
|
||||||
|
progess_bar: bool,
|
||||||
|
|
||||||
#[cfg(feature = "otlp")]
|
#[cfg(feature = "otlp")]
|
||||||
service_name: Option<&'static str>,
|
service_name: Option<&'static str>,
|
||||||
|
@ -123,6 +124,7 @@ impl Default for TracingBuilder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
TracingBuilder {
|
TracingBuilder {
|
||||||
level: Level::INFO,
|
level: Level::INFO,
|
||||||
|
progess_bar: false,
|
||||||
|
|
||||||
#[cfg(feature = "otlp")]
|
#[cfg(feature = "otlp")]
|
||||||
service_name: None,
|
service_name: None,
|
||||||
|
@ -145,6 +147,12 @@ impl TracingBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enable progress bar layer, default is disabled
|
||||||
|
pub fn enable_progressbar(mut self) -> TracingBuilder {
|
||||||
|
self.progess_bar = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// This will setup tracing based on the configuration passed in.
|
/// This will setup tracing based on the configuration passed in.
|
||||||
/// It will setup a stderr writer output layer and a EnvFilter based on the provided log
|
/// It will setup a stderr writer output layer and a EnvFilter based on the provided log
|
||||||
/// level (RUST_LOG still has a higher priority over the configured value).
|
/// level (RUST_LOG still has a higher priority over the configured value).
|
||||||
|
@ -167,10 +175,12 @@ impl TracingBuilder {
|
||||||
.with_writer(indicatif_layer.get_stderr_writer())
|
.with_writer(indicatif_layer.get_stderr_writer())
|
||||||
.compact(),
|
.compact(),
|
||||||
)
|
)
|
||||||
.with(indicatif_layer.with_filter(
|
.with((self.progess_bar).then(|| {
|
||||||
// only show progress for spans with indicatif.pb_show field being set
|
indicatif_layer.with_filter(
|
||||||
IndicatifFilter::new(false),
|
// only show progress for spans with indicatif.pb_show field being set
|
||||||
));
|
IndicatifFilter::new(false),
|
||||||
|
)
|
||||||
|
}));
|
||||||
|
|
||||||
// Setup otlp if a service_name is configured
|
// Setup otlp if a service_name is configured
|
||||||
#[cfg(feature = "otlp")]
|
#[cfg(feature = "otlp")]
|
||||||
|
|
Loading…
Reference in a new issue