mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-20 11:21:14 +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]
|
[tracing.logging]
|
||||||
format = "normal"
|
format = "normal"
|
||||||
targets = "info"
|
targets = "info"
|
||||||
|
log_spans = false
|
||||||
|
|
||||||
[tracing.console]
|
[tracing.console]
|
||||||
buffer_capacity = 102400
|
buffer_capacity = 102400
|
||||||
|
|
|
@ -17,6 +17,7 @@ impl Args {
|
||||||
old_repo_cache_capacity,
|
old_repo_cache_capacity,
|
||||||
log_format,
|
log_format,
|
||||||
log_targets,
|
log_targets,
|
||||||
|
log_spans,
|
||||||
console_address,
|
console_address,
|
||||||
console_buffer_capacity,
|
console_buffer_capacity,
|
||||||
opentelemetry_url,
|
opentelemetry_url,
|
||||||
|
@ -36,6 +37,7 @@ impl Args {
|
||||||
logging: Logging {
|
logging: Logging {
|
||||||
format: log_format,
|
format: log_format,
|
||||||
targets: log_targets.map(Serde::new),
|
targets: log_targets.map(Serde::new),
|
||||||
|
log_spans,
|
||||||
},
|
},
|
||||||
console: Console {
|
console: Console {
|
||||||
address: console_address,
|
address: console_address,
|
||||||
|
@ -550,6 +552,8 @@ struct Logging {
|
||||||
format: Option<LogFormat>,
|
format: Option<LogFormat>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
targets: Option<Serde<Targets>>,
|
targets: Option<Serde<Targets>>,
|
||||||
|
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||||
|
log_spans: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, serde::Serialize)]
|
#[derive(Debug, Default, serde::Serialize)]
|
||||||
|
@ -854,6 +858,9 @@ pub(super) struct Args {
|
||||||
/// Log levels to print to stdout, respects RUST_LOG formatting
|
/// Log levels to print to stdout, respects RUST_LOG formatting
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
log_targets: Option<Targets>,
|
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
|
/// Address and port to expose tokio-console metrics
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
|
|
@ -53,6 +53,7 @@ struct TracingDefaults {
|
||||||
struct LoggingDefaults {
|
struct LoggingDefaults {
|
||||||
format: LogFormat,
|
format: LogFormat,
|
||||||
targets: Serde<Targets>,
|
targets: Serde<Targets>,
|
||||||
|
log_spans: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Serialize)]
|
||||||
|
@ -207,6 +208,7 @@ impl Default for LoggingDefaults {
|
||||||
LoggingDefaults {
|
LoggingDefaults {
|
||||||
format: LogFormat::Normal,
|
format: LogFormat::Normal,
|
||||||
targets: "info".parse().expect("Valid targets string"),
|
targets: "info".parse().expect("Valid targets string"),
|
||||||
|
log_spans: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,8 @@ pub(crate) struct Logging {
|
||||||
pub(crate) format: LogFormat,
|
pub(crate) format: LogFormat,
|
||||||
|
|
||||||
pub(crate) targets: Serde<Targets>,
|
pub(crate) targets: Serde<Targets>,
|
||||||
|
|
||||||
|
pub(crate) log_spans: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[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::subscriber::set_global_default;
|
||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_log::LogTracer;
|
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<()> {
|
pub(super) fn init_tracing(tracing: &Tracing) -> color_eyre::Result<()> {
|
||||||
color_eyre::install()?;
|
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());
|
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 {
|
match tracing.logging.format {
|
||||||
LogFormat::Compact => with_format(format_layer.compact(), tracing),
|
LogFormat::Compact => with_format(format_layer.compact(), tracing),
|
||||||
|
|
Loading…
Reference in a new issue