Skip to content

Commit

Permalink
feat(runtime): switch from json to logfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry authored and AngelOnFira committed Jul 6, 2024
1 parent 3b28c6e commit 2793134
Show file tree
Hide file tree
Showing 50 changed files with 1,414 additions and 10,716 deletions.
1,198 changes: 1,198 additions & 0 deletions infra/default-builds/dockerfiles/test-ds-echo/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ thiserror = "1.0"
tokio = { version = "1.29", features = ["full", "tracing"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "json", "ansi"] } # Used with attribute
tracing-logfmt = "0.3"

43 changes: 18 additions & 25 deletions lib/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, future::Future, sync::Once, time::Duration};

use thiserror::Error;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt::writer::MakeWriterExt, prelude::*};

mod metrics;

Expand Down Expand Up @@ -51,33 +51,26 @@ impl RunConfig {
let fmt_filter = tracing_subscriber::filter::LevelFilter::INFO;

if std::env::var("TOKIO_CONSOLE_ENABLE").is_ok() {
// JSON + tokio-console
let console_layer = console_subscriber::ConsoleLayer::builder()
.retention(std::time::Duration::from_secs(60))
.with_default_env()
.spawn();

let fmt_layer = tracing_subscriber::fmt::layer()
.json()
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::NONE)
.with_current_span(false)
.with_span_list(true)
.with_filter(fmt_filter);

// logfmt + tokio-console
tracing_subscriber::registry()
.with(console_layer)
.with(fmt_layer)
.with(
console_subscriber::ConsoleLayer::builder()
.retention(std::time::Duration::from_secs(60))
.with_default_env()
.spawn(),
)
.with(
tracing_logfmt::builder()
.layer()
.with_filter(fmt_filter)
.with_filter(fmt_filter),
)
.init();
} else {
// JSON
let fmt_layer = tracing_subscriber::fmt::layer()
.json()
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::NONE)
.with_current_span(false)
.with_span_list(true)
.with_filter(fmt_filter);

tracing_subscriber::registry().with(fmt_layer).init();
// logfmt
tracing_subscriber::registry()
.with(tracing_logfmt::builder().layer().with_filter(fmt_filter))
.init();
}
}
})
Expand Down
Loading

0 comments on commit 2793134

Please sign in to comment.