mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-24 10:31:07 +00:00
Add optional ability to log spans
This commit is contained in:
parent
cd80ab16c3
commit
6daa745446
5 changed files with 22 additions and 2 deletions
|
@ -14,6 +14,7 @@ concurrency = 32
|
|||
[tracing.logging]
|
||||
format = "normal"
|
||||
targets = "info"
|
||||
log_spans = false
|
||||
|
||||
[tracing.console]
|
||||
buffer_capacity = 102400
|
||||
|
|
|
@ -17,6 +17,7 @@ impl Args {
|
|||
old_repo_cache_capacity,
|
||||
log_format,
|
||||
log_targets,
|
||||
log_spans,
|
||||
console_address,
|
||||
console_buffer_capacity,
|
||||
opentelemetry_url,
|
||||
|
@ -36,6 +37,7 @@ impl Args {
|
|||
logging: Logging {
|
||||
format: log_format,
|
||||
targets: log_targets.map(Serde::new),
|
||||
log_spans,
|
||||
},
|
||||
console: Console {
|
||||
address: console_address,
|
||||
|
@ -550,6 +552,8 @@ struct Logging {
|
|||
format: Option<LogFormat>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
targets: Option<Serde<Targets>>,
|
||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||
log_spans: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize)]
|
||||
|
@ -854,6 +858,9 @@ pub(super) struct Args {
|
|||
/// Log levels to print to stdout, respects RUST_LOG formatting
|
||||
#[arg(long)]
|
||||
log_targets: Option<Targets>,
|
||||
/// Whether to log openning and closing of tracing spans to stdout
|
||||
#[arg(long)]
|
||||
log_spans: bool,
|
||||
|
||||
/// Address and port to expose tokio-console metrics
|
||||
#[arg(long)]
|
||||
|
|
|
@ -53,6 +53,7 @@ struct TracingDefaults {
|
|||
struct LoggingDefaults {
|
||||
format: LogFormat,
|
||||
targets: Serde<Targets>,
|
||||
log_spans: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
|
@ -207,6 +208,7 @@ impl Default for LoggingDefaults {
|
|||
LoggingDefaults {
|
||||
format: LogFormat::Normal,
|
||||
targets: "info".parse().expect("Valid targets string"),
|
||||
log_spans: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,8 @@ pub(crate) struct Logging {
|
|||
pub(crate) format: LogFormat,
|
||||
|
||||
pub(crate) targets: Serde<Targets>,
|
||||
|
||||
pub(crate) log_spans: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
|
|
@ -6,7 +6,9 @@ use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
|
|||
use tracing::subscriber::set_global_default;
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_log::LogTracer;
|
||||
use tracing_subscriber::{layer::SubscriberExt, registry::LookupSpan, Layer, Registry};
|
||||
use tracing_subscriber::{
|
||||
fmt::format::FmtSpan, layer::SubscriberExt, registry::LookupSpan, Layer, Registry,
|
||||
};
|
||||
|
||||
pub(super) fn init_tracing(tracing: &Tracing) -> color_eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
@ -15,7 +17,13 @@ pub(super) fn init_tracing(tracing: &Tracing) -> color_eyre::Result<()> {
|
|||
|
||||
opentelemetry::global::set_text_map_propagator(TraceContextPropagator::new());
|
||||
|
||||
let format_layer = tracing_subscriber::fmt::layer();
|
||||
let fmt_span = if tracing.logging.log_spans {
|
||||
FmtSpan::NEW | FmtSpan::CLOSE
|
||||
} else {
|
||||
FmtSpan::NONE
|
||||
};
|
||||
|
||||
let format_layer = tracing_subscriber::fmt::layer().with_span_events(fmt_span);
|
||||
|
||||
match tracing.logging.format {
|
||||
LogFormat::Compact => with_format(format_layer.compact(), tracing),
|
||||
|
|
Loading…
Reference in a new issue