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",
|
"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]]
|
[[package]]
|
||||||
name = "tracing-log"
|
name = "tracing-log"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
|
@ -4505,6 +4515,7 @@ dependencies = [
|
||||||
"tracing-error",
|
"tracing-error",
|
||||||
"tracing-flame",
|
"tracing-flame",
|
||||||
"tracing-futures",
|
"tracing-futures",
|
||||||
|
"tracing-journald",
|
||||||
"tracing-subscriber 0.2.17",
|
"tracing-subscriber 0.2.17",
|
||||||
"vergen",
|
"vergen",
|
||||||
"zebra-chain",
|
"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.
|
See the [`filter`][filter] documentation for more details.
|
||||||
|
|
||||||
Zebra also has support for generating [flamegraphs] of tracing spans,
|
Zebra also has support for:
|
||||||
configured using the [`flamegraph`][flamegraph] option.
|
|
||||||
|
* 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
|
[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
|
[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
|
[flamegraph]: https://doc.zebra.zfnd.org/zebrad/config/struct.TracingSection.html#structfield.flamegraph
|
||||||
[flamegraphs]: http://www.brendangregg.com/flamegraphs.html
|
[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 = "0.1"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
tracing-flame = "0.1.0"
|
tracing-flame = "0.1.0"
|
||||||
|
tracing-journald = "0.1.0"
|
||||||
tracing-subscriber = { version = "0.2.17", features = ["tracing-log"] }
|
tracing-subscriber = { version = "0.2.17", features = ["tracing-log"] }
|
||||||
tracing-error = "0.1.2"
|
tracing-error = "0.1.2"
|
||||||
metrics = "0.13.0-alpha.8"
|
metrics = "0.13.0-alpha.8"
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,29 @@ impl Tracing {
|
||||||
.with_filter_reloading();
|
.with_filter_reloading();
|
||||||
let filter_handle = builder.reload_handle();
|
let filter_handle = builder.reload_handle();
|
||||||
|
|
||||||
let subscriber = builder.finish().with(ErrorLayer::default());
|
let (flamelayer, flamegrapher) = if let Some(path) = flame_root {
|
||||||
|
|
||||||
let flamegrapher = if let Some(path) = flame_root {
|
|
||||||
let (flamelayer, flamegrapher) = flame::layer(path);
|
let (flamelayer, flamegrapher) = flame::layer(path);
|
||||||
subscriber.with(flamelayer).init();
|
(Some(flamelayer), Some(flamegrapher))
|
||||||
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 {
|
} else {
|
||||||
subscriber.init();
|
|
||||||
None
|
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 {
|
Ok(Self {
|
||||||
filter_handle,
|
filter_handle,
|
||||||
flamegrapher,
|
flamegrapher,
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,10 @@ pub struct TracingSection {
|
||||||
/// If you provide a path with an extension the extension will be ignored and
|
/// If you provide a path with an extension the extension will be ignored and
|
||||||
/// replaced with `.folded` and `.svg` for the respective files.
|
/// replaced with `.folded` and `.svg` for the respective files.
|
||||||
pub flamegraph: Option<PathBuf>,
|
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 {
|
impl Default for TracingSection {
|
||||||
|
|
@ -114,6 +118,7 @@ impl Default for TracingSection {
|
||||||
filter: None,
|
filter: None,
|
||||||
endpoint_addr: None,
|
endpoint_addr: None,
|
||||||
flamegraph: None,
|
flamegraph: None,
|
||||||
|
use_journald: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue