Add journald support through tracing-journald (#2034)
* Add journald support through tracing-journald * change journald to use_journald * more fixes
This commit is contained in:
parent
afac2c2846
commit
5b2f1cdfd5
|
@ -3738,6 +3738,16 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-journald"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fe1f0ed2b7a5fcb6da2bc9e783587d9a0c8b9535e50224afe04e543eae8a2d6"
|
||||
dependencies = [
|
||||
"tracing-core",
|
||||
"tracing-subscriber 0.2.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.1.2"
|
||||
|
@ -4505,6 +4515,7 @@ dependencies = [
|
|||
"tracing-error",
|
||||
"tracing-flame",
|
||||
"tracing-futures",
|
||||
"tracing-journald",
|
||||
"tracing-subscriber 0.2.17",
|
||||
"vergen",
|
||||
"zebra-chain",
|
||||
|
|
|
@ -12,10 +12,17 @@ if the config had `endpoint_addr = '127.0.0.1:3000'`, then
|
|||
|
||||
See the [`filter`][filter] documentation for more details.
|
||||
|
||||
Zebra also has support for generating [flamegraphs] of tracing spans,
|
||||
configured using the [`flamegraph`][flamegraph] option.
|
||||
Zebra also has support for:
|
||||
|
||||
* Generating [flamegraphs] of tracing spans, configured using the
|
||||
[`flamegraph`][flamegraph] option.
|
||||
* Sending tracing spans and events to [systemd-journald][systemd_journald],
|
||||
on Linux distributions that use `systemd`. Configured using the
|
||||
[`use_journald`][use_journald] option.
|
||||
|
||||
[tracing_section]: https://doc.zebra.zfnd.org/zebrad/config/struct.TracingSection.html
|
||||
[filter]: https://doc.zebra.zfnd.org/zebrad/config/struct.TracingSection.html#structfield.filter
|
||||
[flamegraph]: https://doc.zebra.zfnd.org/zebrad/config/struct.TracingSection.html#structfield.flamegraph
|
||||
[flamegraphs]: http://www.brendangregg.com/flamegraphs.html
|
||||
[systemd_journald]: https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html
|
||||
[use_journald]: https://doc.zebra.zfnd.org/zebrad/config/struct.TracingSection.html#structfield.use_journald
|
||||
|
|
|
@ -34,6 +34,7 @@ thiserror = "1"
|
|||
tracing = "0.1"
|
||||
tracing-futures = "0.2"
|
||||
tracing-flame = "0.1.0"
|
||||
tracing-journald = "0.1.0"
|
||||
tracing-subscriber = { version = "0.2.17", features = ["tracing-log"] }
|
||||
tracing-error = "0.1.2"
|
||||
metrics = "0.13.0-alpha.8"
|
||||
|
|
|
@ -31,17 +31,29 @@ impl Tracing {
|
|||
.with_filter_reloading();
|
||||
let filter_handle = builder.reload_handle();
|
||||
|
||||
let subscriber = builder.finish().with(ErrorLayer::default());
|
||||
|
||||
let flamegrapher = if let Some(path) = flame_root {
|
||||
let (flamelayer, flamegrapher) = if let Some(path) = flame_root {
|
||||
let (flamelayer, flamegrapher) = flame::layer(path);
|
||||
subscriber.with(flamelayer).init();
|
||||
Some(flamegrapher)
|
||||
(Some(flamelayer), Some(flamegrapher))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let journaldlayer = if config.use_journald {
|
||||
let layer = tracing_journald::layer()
|
||||
.map_err(|e| FrameworkErrorKind::ComponentError.context(e))?;
|
||||
Some(layer)
|
||||
} else {
|
||||
subscriber.init();
|
||||
None
|
||||
};
|
||||
|
||||
let subscriber = builder.finish().with(ErrorLayer::default());
|
||||
match (flamelayer, journaldlayer) {
|
||||
(None, None) => subscriber.init(),
|
||||
(Some(layer1), None) => subscriber.with(layer1).init(),
|
||||
(None, Some(layer2)) => subscriber.with(layer2).init(),
|
||||
(Some(layer1), Some(layer2)) => subscriber.with(layer1).with(layer2).init(),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
filter_handle,
|
||||
flamegrapher,
|
||||
|
|
|
@ -105,6 +105,10 @@ pub struct TracingSection {
|
|||
/// If you provide a path with an extension the extension will be ignored and
|
||||
/// replaced with `.folded` and `.svg` for the respective files.
|
||||
pub flamegraph: Option<PathBuf>,
|
||||
|
||||
/// The use_journald flag sends tracing events to systemd-journald, on Linux
|
||||
/// distributions that use systemd.
|
||||
pub use_journald: bool,
|
||||
}
|
||||
|
||||
impl Default for TracingSection {
|
||||
|
@ -114,6 +118,7 @@ impl Default for TracingSection {
|
|||
filter: None,
|
||||
endpoint_addr: None,
|
||||
flamegraph: None,
|
||||
use_journald: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue