tracy: Hook up tracing to tracy for automatic spans

Jakub Konka created

Change summary

Cargo.lock                 | 14 ++++++++++++++
Cargo.toml                 |  3 +++
crates/collab/Cargo.toml   |  4 ++--
crates/zed/Cargo.toml      |  5 ++++-
crates/zed/src/zed-main.rs |  6 ++++++
5 files changed, 29 insertions(+), 3 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -16890,6 +16890,17 @@ dependencies = [
  "tracing-serde",
 ]
 
+[[package]]
+name = "tracing-tracy"
+version = "0.11.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0eaa1852afa96e0fe9e44caa53dc0bd2d9d05e0f2611ce09f97f8677af56e4ba"
+dependencies = [
+ "tracing-core",
+ "tracing-subscriber",
+ "tracy-client",
+]
+
 [[package]]
 name = "tracy-client"
 version = "0.18.2"
@@ -20358,6 +20369,9 @@ dependencies = [
  "time",
  "title_bar",
  "toolchain_selector",
+ "tracing",
+ "tracing-subscriber",
+ "tracing-tracy",
  "tracy-client",
  "tree-sitter-md",
  "tree-sitter-rust",

Cargo.toml 🔗

@@ -667,6 +667,9 @@ tokio = { version = "1" }
 tokio-tungstenite = { version = "0.26", features = ["__rustls-tls"] }
 toml = "0.8"
 tower-http = "0.4.4"
+tracing = "0.1.40"
+tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json", "registry", "tracing-log"] } # workaround for https://github.com/tokio-rs/tracing/issues/2927
+tracing-tracy = { version = "0.11.4", default-features = false, features = ["enable"] }
 tracy-client = { version = "0.18.2", default-features = false, features = ["enable", "demangle"] }
 tree-sitter = { version = "0.25.10", features = ["wasm"] }
 tree-sitter-bash = "0.25.0"

crates/collab/Cargo.toml 🔗

@@ -64,8 +64,8 @@ tokio = { workspace = true, features = ["full"] }
 toml.workspace = true
 tower = "0.4"
 tower-http = { workspace = true, features = ["trace"] }
-tracing = "0.1.40"
-tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json", "registry", "tracing-log"] } # workaround for https://github.com/tokio-rs/tracing/issues/2927
+tracing.workspace = true
+tracing-subscriber.workspace = true
 util.workspace = true
 uuid.workspace = true
 workspace-hack.workspace = true

crates/zed/Cargo.toml 🔗

@@ -19,7 +19,7 @@ name = "zed"
 path = "src/main.rs"
 
 [features]
-tracy = ["dep:tracy-client", "gpui/tracy"]
+tracy = ["dep:tracy-client", "dep:tracing", "dep:tracing-subscriber", "dep:tracing-tracy", "gpui/tracy"]
 tracy-memory = ["tracy"]
 
 [dependencies]
@@ -150,6 +150,9 @@ theme_selector.workspace = true
 time.workspace = true
 title_bar.workspace = true
 toolchain_selector.workspace = true
+tracing = { workspace = true, optional = true }
+tracing-subscriber = { workspace = true, optional = true }
+tracing-tracy = { workspace = true, optional = true }
 tracy-client = { workspace = true, optional = true }
 ui.workspace = true
 ui_input.workspace = true

crates/zed/src/zed-main.rs 🔗

@@ -4,8 +4,14 @@
 pub fn main() {
     #[cfg(feature = "tracy")]
     {
+        use tracing_subscriber::layer::SubscriberExt;
+
         tracy_client::register_demangler!();
         tracy_client::Client::start();
+        tracing::subscriber::set_global_default(
+            tracing_subscriber::registry().with(tracing_tracy::TracyLayer::default()),
+        )
+        .expect("setup tracy layer");
     }
 
     // separated out so that the file containing the main function can be imported by other crates,