From 6b6a34065e050417e8aafab8915a2cee270cc09d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 14 Jun 2024 14:10:57 +0300 Subject: feat(tvix/tracing): add tracing-tracy support This introduces another feature flag, "tracy" to the `tvix-tracing` crate. If enabled (not enabled by default), it'll add an additional layer emitting packets in a format that https://github.com/wolfpld/tracy can display. I had to be a bit tricky with the combinatorial complexity when adding this, but the resulting code still seems manageable. Change-Id: Ica824496728fa276ceae3f7a9754be0166e6558f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10952 Tested-by: BuildkiteCI Reviewed-by: Simon Hauser Reviewed-by: flokli --- tvix/tracing/src/lib.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'tvix/tracing/src') diff --git a/tvix/tracing/src/lib.rs b/tvix/tracing/src/lib.rs index 36bd7cec10c0..08e100781073 100644 --- a/tvix/tracing/src/lib.rs +++ b/tvix/tracing/src/lib.rs @@ -13,6 +13,8 @@ use opentelemetry_sdk::{ trace::BatchConfigBuilder, Resource, }; +#[cfg(feature = "tracy")] +use tracing_tracy::TracyLayer; lazy_static! { pub static ref PB_PROGRESS_STYLE: ProgressStyle = ProgressStyle::with_template( @@ -173,12 +175,31 @@ impl TracingBuilder { let (tracer, tx) = gen_otlp_tracer(service_name.to_string()); // Create a tracing layer with the configured tracer let layer = tracing_opentelemetry::layer().with_tracer(tracer); - subscriber.with(Some(layer)).try_init()?; + + #[cfg(feature = "tracy")] + { + subscriber + .with(TracyLayer::default()) + .with(Some(layer)) + .try_init()?; + } + + #[cfg(not(feature = "tracy"))] + { + subscriber.with(Some(layer)).try_init()?; + } return Ok(TracingHandle { tx: Some(tx) }); } } + #[cfg(feature = "tracy")] + { + subscriber.with(TracyLayer::default()).try_init()?; + } + #[cfg(not(feature = "tracy"))] + { + subscriber.try_init()?; + } - subscriber.try_init()?; Ok(TracingHandle { tx: None }) } } -- cgit 1.4.1