Skip to content

Commit

Permalink
Merge pull request #348 from Kuadrant/tracing-info-level
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-cattermole committed Jun 3, 2024
2 parents 4b2dc62 + ab96ec5 commit e24873f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions limitador-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use std::path::Path;
use std::sync::Arc;
use std::time::Duration;
use std::{env, process};
use tracing_subscriber::Layer;

#[cfg(feature = "distributed_storage")]
use clap::parser::ValuesRef;
Expand Down Expand Up @@ -215,16 +216,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = {
let (config, version) = create_config();
println!("{LIMITADOR_HEADER} {version}");

let level = config.log_level.unwrap_or_else(|| {
tracing_subscriber::filter::EnvFilter::from_default_env()
.max_level_hint()
.unwrap_or(LevelFilter::ERROR)
});
let fmt_layer = if level >= LevelFilter::DEBUG {
tracing_subscriber::fmt::layer().with_span_events(FmtSpan::CLOSE)
} else {
tracing_subscriber::fmt::layer()
};

let fmt_layer = tracing_subscriber::fmt::layer()
.with_span_events(if level >= LevelFilter::DEBUG {
FmtSpan::CLOSE
} else {
FmtSpan::NONE
})
.with_filter(level);

let metrics_layer = MetricsLayer::new()
.gather(
Expand All @@ -240,6 +245,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

if !config.tracing_endpoint.is_empty() {
global::set_text_map_propagator(TraceContextPropagator::new());

let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
Expand All @@ -251,16 +257,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
KeyValue::new("service.name", "limitador"),
])))
.install_batch(opentelemetry_sdk::runtime::Tokio)?;

let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer);

// Init tracing subscriber with telemetry
tracing_subscriber::registry()
.with(level)
.with(metrics_layer)
.with(fmt_layer)
.with(level.max(LevelFilter::INFO))
.with(telemetry_layer)
.init();
} else {
// Init tracing subscriber without telemetry
tracing_subscriber::registry()
.with(level)
.with(metrics_layer)
.with(fmt_layer)
.init();
Expand Down

0 comments on commit e24873f

Please sign in to comment.