feat: add tracing-tracy (#20958)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
DaniPopes
2026-01-12 18:37:37 +00:00
committed by GitHub
parent 2663942b50
commit 23f3f8e820
17 changed files with 101 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ workflows:
# Check that `A` activates the features of `B`.
"propagate-feature",
# These are the features to check:
"--features=std,op,dev,asm-keccak,jemalloc,jemalloc-prof,tracy-allocator,serde-bincode-compat,serde,test-utils,arbitrary,bench,alloy-compat,min-error-logs,min-warn-logs,min-info-logs,min-debug-logs,min-trace-logs,otlp,js-tracer,portable,keccak-cache-global",
"--features=std,op,dev,asm-keccak,jemalloc,jemalloc-prof,tracy-allocator,tracy,serde-bincode-compat,serde,test-utils,arbitrary,bench,alloy-compat,min-error-logs,min-warn-logs,min-info-logs,min-debug-logs,min-trace-logs,otlp,js-tracer,portable,keccak-cache-global",
# Do not try to add a new section to `[features]` of `A` only because `B` exposes that feature. There are edge-cases where this is still needed, but we can add them manually.
"--left-side-feature-missing=ignore",
# Ignore the case that `A` it outside of the workspace. Otherwise it will report errors in external dependencies that we have no influence on.

14
Cargo.lock generated
View File

@@ -7923,6 +7923,7 @@ dependencies = [
"rand 0.8.5",
"rand 0.9.2",
"reth-fs-util",
"reth-tracing",
"secp256k1 0.30.0",
"serde",
"snmalloc-rs",
@@ -11037,6 +11038,8 @@ dependencies = [
"tracing-logfmt",
"tracing-samply",
"tracing-subscriber 0.3.22",
"tracing-tracy",
"tracy-client",
]
[[package]]
@@ -13347,6 +13350,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 0.3.22",
"tracy-client",
]
[[package]]
name = "tracy-client"
version = "0.18.3"

View File

@@ -734,6 +734,7 @@ tracing-journald = "0.3"
tracing-logfmt = "0.3.3"
tracing-samply = "0.1"
tracing-subscriber = { version = "0.3", default-features = false }
tracing-tracy = "0.11"
triehash = "0.8"
typenum = "1.15.0"
vergen = "9.0.4"

View File

@@ -71,7 +71,11 @@ jemalloc = [
"reth-node-core/jemalloc",
]
jemalloc-prof = ["reth-cli-util/jemalloc-prof"]
tracy-allocator = ["reth-cli-util/tracy-allocator"]
tracy-allocator = ["reth-cli-util/tracy-allocator", "tracy"]
tracy = [
"reth-node-core/tracy",
"reth-tracing/tracy",
]
min-error-logs = [
"tracing/release_max_level_error",

View File

@@ -85,7 +85,11 @@ jemalloc = [
"reth-node-core/jemalloc",
]
jemalloc-prof = ["reth-cli-util/jemalloc-prof"]
tracy-allocator = ["reth-cli-util/tracy-allocator"]
tracy-allocator = ["reth-cli-util/tracy-allocator", "tracy"]
tracy = [
"reth-node-core/tracy",
"reth-tracing/tracy",
]
min-error-logs = [
"tracing/release_max_level_error",

View File

@@ -131,6 +131,11 @@ jemalloc-unprefixed = [
tracy-allocator = [
"reth-cli-util/tracy-allocator",
"reth-ethereum-cli/tracy-allocator",
"tracy",
]
tracy = [
"reth-ethereum-cli/tracy",
"reth-node-core/tracy",
]
# Because jemalloc is default and preferred over snmalloc when both features are

View File

@@ -26,7 +26,8 @@ rand_08.workspace = true
thiserror.workspace = true
serde.workspace = true
tracy-client = { workspace = true, optional = true, features = ["demangle"] }
tracy-client = { workspace = true, optional = true }
reth-tracing = { workspace = true, optional = true }
[dev-dependencies]
rand.workspace = true
@@ -46,7 +47,7 @@ jemalloc-prof = ["jemalloc", "tikv-jemallocator?/profiling"]
jemalloc-unprefixed = ["jemalloc", "tikv-jemallocator?/unprefixed_malloc_on_supported_platforms"]
# Wraps the selected allocator in the tracy profiling allocator
tracy-allocator = ["dep:tracy-client"]
tracy-allocator = ["dep:tracy-client", "dep:reth-tracing"]
snmalloc = ["dep:snmalloc-rs"]

View File

@@ -25,7 +25,6 @@ cfg_if::cfg_if! {
cfg_if::cfg_if! {
if #[cfg(feature = "tracy-allocator")] {
type AllocatorWrapper = tracy_client::ProfiledAllocator<AllocatorInner>;
tracy_client::register_demangler!();
const fn new_allocator_wrapper() -> AllocatorWrapper {
AllocatorWrapper::new(AllocatorInner {}, 100)
}

View File

@@ -8,6 +8,9 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "tracy-allocator")]
use reth_tracing as _;
pub mod allocator;
pub mod cancellation;

View File

@@ -58,7 +58,8 @@ jemalloc-symbols = [
"jemalloc-prof",
"reth-node-metrics/jemalloc-symbols",
]
tracy-allocator = []
tracy-allocator = ["tracy"]
tracy = ["reth-tracing/tracy", "reth-node-core/tracy"]
# Because jemalloc is default and preferred over snmalloc when both features are
# enabled, `--no-default-features` should be used when enabling snmalloc or

View File

@@ -82,6 +82,7 @@ jemalloc = ["reth-cli-util/jemalloc"]
asm-keccak = ["alloy-primitives/asm-keccak"]
keccak-cache-global = ["alloy-primitives/keccak-cache-global"]
otlp = ["reth-tracing/otlp"]
tracy = ["reth-tracing/tracy"]
min-error-logs = ["tracing/release_max_level_error"]
min-warn-logs = ["tracing/release_max_level_warn"]

View File

@@ -75,6 +75,20 @@ pub struct LogArgs {
)]
pub samply_filter: String,
/// Emit traces to tracy. Only useful when profiling.
#[arg(long = "log.tracy", global = true, hide = true)]
pub tracy: bool,
/// The filter to use for traces emitted to tracy.
#[arg(
long = "log.tracy.filter",
value_name = "FILTER",
global = true,
default_value = "debug",
hide = true
)]
pub tracy_filter: String,
/// Sets whether or not the formatter emits ANSI terminal escape codes for colors and other
/// text formatting.
#[arg(
@@ -148,6 +162,12 @@ impl LogArgs {
tracer = tracer.with_samply(config);
}
#[cfg(feature = "tracy")]
if self.tracy {
let config = self.layer_info(LogFormat::Terminal, self.tracy_filter.clone(), false);
tracer = tracer.with_tracy(config);
}
let guard = tracer.init_with_layers(layers)?;
Ok(guard)
}

View File

@@ -38,7 +38,8 @@ js-tracer = [
jemalloc = ["reth-cli-util/jemalloc", "reth-optimism-cli/jemalloc"]
jemalloc-prof = ["jemalloc", "reth-cli-util/jemalloc-prof", "reth-optimism-cli/jemalloc-prof"]
jemalloc-symbols = ["jemalloc-prof", "reth-optimism-cli/jemalloc-symbols"]
tracy-allocator = ["reth-cli-util/tracy-allocator"]
tracy-allocator = ["reth-cli-util/tracy-allocator", "tracy"]
tracy = ["reth-optimism-cli/tracy"]
asm-keccak = ["reth-optimism-cli/asm-keccak", "reth-optimism-node/asm-keccak"]
keccak-cache-global = [

View File

@@ -99,6 +99,8 @@ jemalloc-symbols = [
"reth-node-metrics/jemalloc-symbols",
]
tracy = ["reth-tracing/tracy", "reth-node-core/tracy"]
dev = [
"dep:proptest",
"reth-cli-commands/arbitrary",

View File

@@ -22,6 +22,8 @@ tracing-appender.workspace = true
tracing-journald.workspace = true
tracing-logfmt.workspace = true
tracing-samply.workspace = true
tracing-tracy = { workspace = true, optional = true }
tracy-client = { workspace = true, optional = true, features = ["demangle"] }
# misc
clap = { workspace = true, features = ["derive"] }
@@ -31,3 +33,4 @@ rolling-file.workspace = true
[features]
default = ["otlp"]
otlp = ["reth-tracing-otlp"]
tracy = ["tracing-tracy", "tracy-client"]

View File

@@ -142,6 +142,15 @@ impl Layers {
Ok(())
}
#[cfg(feature = "tracy")]
pub(crate) fn tracy(&mut self, config: LayerInfo) -> eyre::Result<()> {
self.add_layer(tracing_tracy::TracyLayer::default().with_filter(build_env_filter(
Some(config.default_directive.parse()?),
&config.filters,
)?));
Ok(())
}
/// Add OTLP spans layer to the layer collection
#[cfg(feature = "otlp")]
pub fn with_span_layer(

View File

@@ -48,6 +48,9 @@ pub use tracing;
pub use tracing_appender;
pub use tracing_subscriber;
#[cfg(feature = "tracy")]
tracy_client::register_demangler!();
// Re-export our types
pub use formatter::LogFormat;
pub use layers::{FileInfo, FileWorkerGuard, Layers};
@@ -71,6 +74,8 @@ pub struct RethTracer {
journald: Option<String>,
file: Option<(LayerInfo, FileInfo)>,
samply: Option<LayerInfo>,
#[cfg(feature = "tracy")]
tracy: Option<LayerInfo>,
}
impl RethTracer {
@@ -79,7 +84,14 @@ impl RethTracer {
/// Initializes with default stdout layer configuration.
/// Journald and file layers are not set by default.
pub fn new() -> Self {
Self { stdout: LayerInfo::default(), journald: None, file: None, samply: None }
Self {
stdout: LayerInfo::default(),
journald: None,
file: None,
samply: None,
#[cfg(feature = "tracy")]
tracy: None,
}
}
/// Sets a custom configuration for the stdout layer.
@@ -115,6 +127,13 @@ impl RethTracer {
self.samply = Some(config);
self
}
/// Sets the tracy layer configuration.
#[cfg(feature = "tracy")]
pub fn with_tracy(mut self, config: LayerInfo) -> Self {
self.tracy = Some(config);
self
}
}
impl Default for RethTracer {
@@ -235,6 +254,11 @@ impl Tracer for RethTracer {
layers.samply(config)?;
}
#[cfg(feature = "tracy")]
if let Some(config) = self.tracy {
layers.tracy(config)?;
}
// The error is returned if the global default subscriber is already set,
// so it's safe to ignore it
let _ = tracing_subscriber::registry().with(layers.into_inner()).try_init();