mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-26 03:59:55 +00:00
Merge pull request #1003 from zed-industries/moar-logs
Log JSON in Kubernetes
This commit is contained in:
commit
1e366b8093
4 changed files with 35 additions and 6 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -5333,6 +5333,16 @@ dependencies = [
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-serde"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.3.11"
|
version = "0.3.11"
|
||||||
|
@ -5343,12 +5353,15 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"matchers",
|
"matchers",
|
||||||
"regex",
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
|
"tracing-serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -45,7 +45,7 @@ toml = "0.5.8"
|
||||||
tracing = "0.1.34"
|
tracing = "0.1.34"
|
||||||
tracing-log = "0.1.3"
|
tracing-log = "0.1.3"
|
||||||
tracing-opentelemetry = "0.17"
|
tracing-opentelemetry = "0.17"
|
||||||
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.11", features = ["env-filter", "json"] }
|
||||||
|
|
||||||
[dependencies.sqlx]
|
[dependencies.sqlx]
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
|
|
|
@ -83,6 +83,8 @@ spec:
|
||||||
key: token
|
key: token
|
||||||
- name: RUST_LOG
|
- name: RUST_LOG
|
||||||
value: ${RUST_LOG}
|
value: ${RUST_LOG}
|
||||||
|
- name: LOG_JSON
|
||||||
|
value: "true"
|
||||||
- name: HONEYCOMB_DATASET
|
- name: HONEYCOMB_DATASET
|
||||||
value: "collab"
|
value: "collab"
|
||||||
- name: HONEYCOMB_API_KEY
|
- name: HONEYCOMB_API_KEY
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use tracing_log::LogTracer;
|
use tracing_log::LogTracer;
|
||||||
use tracing_subscriber::filter::EnvFilter;
|
use tracing_subscriber::{filter::EnvFilter, fmt::format::JsonFields, Layer};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
#[derive(Default, Deserialize)]
|
#[derive(Default, Deserialize)]
|
||||||
|
@ -23,6 +23,7 @@ pub struct Config {
|
||||||
pub honeycomb_api_key: Option<String>,
|
pub honeycomb_api_key: Option<String>,
|
||||||
pub honeycomb_dataset: Option<String>,
|
pub honeycomb_dataset: Option<String>,
|
||||||
pub rust_log: Option<String>,
|
pub rust_log: Option<String>,
|
||||||
|
pub log_json: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
|
@ -152,10 +153,23 @@ pub fn init_tracing(config: &Config) -> Option<()> {
|
||||||
|
|
||||||
let subscriber = tracing_subscriber::Registry::default()
|
let subscriber = tracing_subscriber::Registry::default()
|
||||||
.with(open_telemetry_layer)
|
.with(open_telemetry_layer)
|
||||||
.with(
|
.with(if config.log_json.unwrap_or(false) {
|
||||||
|
Box::new(
|
||||||
|
tracing_subscriber::fmt::layer()
|
||||||
|
.fmt_fields(JsonFields::default())
|
||||||
|
.event_format(
|
||||||
|
tracing_subscriber::fmt::format()
|
||||||
|
.json()
|
||||||
|
.flatten_event(true)
|
||||||
|
.with_span_list(true),
|
||||||
|
),
|
||||||
|
) as Box<dyn Layer<_> + Send + Sync>
|
||||||
|
} else {
|
||||||
|
Box::new(
|
||||||
tracing_subscriber::fmt::layer()
|
tracing_subscriber::fmt::layer()
|
||||||
.event_format(tracing_subscriber::fmt::format().pretty()),
|
.event_format(tracing_subscriber::fmt::format().pretty()),
|
||||||
)
|
)
|
||||||
|
})
|
||||||
.with(EnvFilter::from_str(rust_log.as_str()).log_err()?);
|
.with(EnvFilter::from_str(rust_log.as_str()).log_err()?);
|
||||||
|
|
||||||
tracing::subscriber::set_global_default(subscriber).unwrap();
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue