Skip to content

Commit

Permalink
Refactor levels for metrics, logging, and tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-cattermole committed May 28, 2024
1 parent 5525734 commit 7dd5924
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions limitador-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::propagation::TraceContextPropagator;

Check warning on line 37 in limitador-server/src/main.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/main.rs
use opentelemetry_sdk::{trace, Resource};
use prometheus_metrics::PrometheusMetrics;
use tracing_subscriber::Layer;
use std::fmt::Display;
use std::fs;
use std::path::Path;
Expand Down Expand Up @@ -221,9 +222,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap_or(LevelFilter::ERROR)

Check warning on line 222 in limitador-server/src/main.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/main.rs
});
let fmt_layer = if level >= LevelFilter::DEBUG {
tracing_subscriber::fmt::layer().with_span_events(FmtSpan::CLOSE)
tracing_subscriber::fmt::layer().with_span_events(FmtSpan::CLOSE).with_filter(level)
} else {
tracing_subscriber::fmt::layer()
tracing_subscriber::fmt::layer().with_filter(level)
};

let metrics_layer = MetricsLayer::new()
Expand Down Expand Up @@ -251,16 +252,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
KeyValue::new("service.name", "limitador"),
])))
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
let tracing_level = level.max(LevelFilter::INFO);
let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer);
tracing_subscriber::registry()
.with(level)
.with(metrics_layer)
.with(fmt_layer)
.with(tracing_level)
.with(telemetry_layer)
.init();
} else {
tracing_subscriber::registry()
.with(level)
.with(metrics_layer)
.with(fmt_layer)
.init();
Expand Down

0 comments on commit 7dd5924

Please sign in to comment.