From 59010caff5b7c6c089e4864e9fcdb060f4501f04 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 3 Dec 2020 01:14:02 +0100 Subject: [PATCH] Tracing chrome span names (#979) * Update tracing-chrome to 0.3.0 * bevy_log: Add fields to span names for tracing-chrome * Conditionally import tracing_subscriber modules based on feature --- crates/bevy_log/Cargo.toml | 2 +- crates/bevy_log/src/lib.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/bevy_log/Cargo.toml b/crates/bevy_log/Cargo.toml index d3c482932ae92..1a9ac14203cd9 100644 --- a/crates/bevy_log/Cargo.toml +++ b/crates/bevy_log/Cargo.toml @@ -18,7 +18,7 @@ bevy_app = { path = "../bevy_app", version = "0.3.0" } bevy_utils = { path = "../bevy_utils", version = "0.3.0" } tracing-subscriber = {version = "0.2.15", features = ["registry"]} -tracing-chrome = { version = "0.2.0", optional = true } +tracing-chrome = { version = "0.3.0", optional = true } [target.'cfg(target_os = "android")'.dependencies] android_log-sys = "0.2.0" diff --git a/crates/bevy_log/src/lib.rs b/crates/bevy_log/src/lib.rs index dc9c08a4cdb8a..98737d513b58f 100644 --- a/crates/bevy_log/src/lib.rs +++ b/crates/bevy_log/src/lib.rs @@ -12,6 +12,8 @@ pub use bevy_utils::tracing::{ }; use bevy_app::{AppBuilder, Plugin}; +#[cfg(feature = "tracing-chrome")] +use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields}; use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter}; /// Adds logging to Apps. @@ -55,7 +57,20 @@ impl Plugin for LogPlugin { let subscriber = subscriber.with(fmt_layer); #[cfg(feature = "tracing-chrome")] { - let (chrome_layer, guard) = tracing_chrome::ChromeLayerBuilder::new().build(); + let (chrome_layer, guard) = tracing_chrome::ChromeLayerBuilder::new() + .name_fn(Box::new(|event_or_span| match event_or_span { + tracing_chrome::EventOrSpan::Event(event) => event.metadata().name().into(), + tracing_chrome::EventOrSpan::Span(span) => { + if let Some(fields) = + span.extensions().get::>() + { + format!("{}: {}", span.metadata().name(), fields.fields.as_str()) + } else { + span.metadata().name().into() + } + } + })) + .build(); app.resources_mut().insert_thread_local(guard); let subscriber = subscriber.with(chrome_layer); bevy_utils::tracing::subscriber::set_global_default(subscriber)