Skip to content

Commit e58616f

Browse files
authored
feat(cli): add tracing-samply (#669)
1 parent 1a888f7 commit e58616f

File tree

4 files changed

+66
-9
lines changed

4 files changed

+66
-9
lines changed

Cargo.lock

Lines changed: 41 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tracing-subscriber = { workspace = true, optional = true, features = [
3232

3333
tracing-chrome = { version = "0.7", optional = true }
3434
tracing-tracy = { version = "0.11", optional = true, features = ["demangle"] }
35+
tracing-samply = { version = "0.1.5", optional = true }
3536

3637
mimalloc = { version = "0.1", optional = true }
3738

@@ -64,3 +65,4 @@ tracing-chrome = [
6465
]
6566
tracy = ["tracing", "dep:tracing-tracy", "solar-config/tracy"]
6667
tracy-allocator = ["tracing", "tracy", "solar-config/tracy-allocator"]
68+
tracing-samply = ["tracing", "dep:tracing-samply", "solar-config/tracing-samply"]

crates/cli/src/utils.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ fn try_init_logger(dst: LogDestination) -> Result<impl Sized, String> {
110110
}
111111
(Some(tracy_layer().boxed()), Default::default())
112112
}
113-
Ok(s) => return Err(format!("unknown profiler '{s}'; valid values: 'chrome', 'tracy'")),
113+
Ok("samply") => {
114+
if !cfg!(feature = "tracing-samply") {
115+
return Err("samply profiler support is not compiled in".to_string());
116+
}
117+
(Some(samply_layer().map_err(|e| e.to_string())?.boxed()), Default::default())
118+
}
119+
Ok(s) => {
120+
return Err(format!(
121+
"unknown profiler '{s}'; valid values: 'chrome', 'tracy', 'samply'"
122+
));
123+
}
114124
Err(_) => Default::default(),
115125
};
116126
tracing_subscriber::Registry::default()
@@ -140,7 +150,6 @@ fn tracy_layer() -> tracing_tracy::TracyLayer<impl tracing_tracy::Config> {
140150

141151
tracing_tracy::TracyLayer::new(Config(Default::default()))
142152
}
143-
144153
#[cfg(feature = "tracing")]
145154
#[cfg(not(feature = "tracy"))]
146155
fn tracy_layer() -> tracing_subscriber::layer::Identity {
@@ -158,13 +167,23 @@ where
158167
{
159168
tracing_chrome::ChromeLayerBuilder::new().include_args(true).build()
160169
}
161-
162170
#[cfg(feature = "tracing")]
163171
#[cfg(not(feature = "tracing-chrome"))]
164172
fn chrome_layer() -> (tracing_subscriber::layer::Identity, ()) {
165173
(tracing_subscriber::layer::Identity::new(), ())
166174
}
167175

176+
#[cfg(feature = "tracing")]
177+
#[cfg(feature = "tracing-samply")]
178+
fn samply_layer() -> std::io::Result<tracing_samply::SamplyLayer> {
179+
tracing_samply::SamplyLayer::new()
180+
}
181+
#[cfg(feature = "tracing")]
182+
#[cfg(not(feature = "tracing-samply"))]
183+
fn samply_layer() -> std::io::Result<tracing_subscriber::layer::Identity> {
184+
Ok(tracing_subscriber::layer::Identity::new())
185+
}
186+
168187
/*
169188
pub(crate) fn env_to_bool(value: Option<&std::ffi::OsStr>) -> bool {
170189
value.is_some_and(|value| value == "1" || value == "true")

crates/config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ tracing-off = []
4949
tracing-chrome = []
5050
tracy = []
5151
tracy-allocator = []
52+
tracing-samply = []

0 commit comments

Comments
 (0)