Page MenuHomePhabricator

D11744.id39526.diff
No OneTemporary

D11744.id39526.diff

diff --git a/services/identity/Cargo.lock b/services/identity/Cargo.lock
--- a/services/identity/Cargo.lock
+++ b/services/identity/Cargo.lock
@@ -3014,6 +3014,16 @@
"tracing-core",
]
+[[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]]
name = "tracing-subscriber"
version = "0.3.18"
@@ -3024,12 +3034,15 @@
"nu-ansi-term",
"once_cell",
"regex",
+ "serde",
+ "serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
+ "tracing-serde",
]
[[package]]
diff --git a/services/identity/Cargo.toml b/services/identity/Cargo.toml
--- a/services/identity/Cargo.toml
+++ b/services/identity/Cargo.toml
@@ -17,7 +17,7 @@
"grpc_clients",
] }
tracing = "0.1"
-tracing-subscriber = { version = "0.3", features = ["env-filter"] }
+tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
chrono = "0.4.31"
rand = "0.8"
constant_time_eq = "0.2.2"
diff --git a/services/identity/src/constants.rs b/services/identity/src/constants.rs
--- a/services/identity/src/constants.rs
+++ b/services/identity/src/constants.rs
@@ -236,6 +236,10 @@
pub const ALLOW_ORIGIN_LIST: &str = "ALLOW_ORIGIN_LIST";
}
+// Tracing
+
+pub const COMM_SERVICES_USE_JSON_LOGS: &str = "COMM_SERVICES_USE_JSON_LOGS";
+
// Regex
pub const VALID_USERNAME_REGEX_STRING: &str =
diff --git a/services/identity/src/main.rs b/services/identity/src/main.rs
--- a/services/identity/src/main.rs
+++ b/services/identity/src/main.rs
@@ -26,9 +26,10 @@
mod tunnelbroker;
mod websockets;
-use constants::IDENTITY_SERVICE_SOCKET_ADDR;
+use constants::{COMM_SERVICES_USE_JSON_LOGS, IDENTITY_SERVICE_SOCKET_ADDR};
use cors::cors_layer;
use keygen::generate_and_persist_keypair;
+use std::env;
use sync_identity_search::sync_index;
use tracing::{self, info, Level};
use tracing_subscriber::EnvFilter;
@@ -45,9 +46,22 @@
.with_env_var(EnvFilter::DEFAULT_ENV)
.from_env_lossy();
- let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish();
+ let use_json_logs: bool = env::var(COMM_SERVICES_USE_JSON_LOGS)
+ .unwrap_or("false".to_string())
+ .parse()
+ .unwrap_or_default();
+
+ if use_json_logs {
+ let subscriber = tracing_subscriber::fmt()
+ .json()
+ .with_env_filter(filter)
+ .finish();
+ tracing::subscriber::set_global_default(subscriber)?;
+ } else {
+ let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish();
+ tracing::subscriber::set_global_default(subscriber)?;
+ }
- tracing::subscriber::set_global_default(subscriber)?;
match config::parse_cli_command() {
Command::Keygen { dir } => {
generate_and_persist_keypair(dir)?;

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 7:40 AM (22 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2534285
Default Alt Text
D11744.id39526.diff (2 KB)

Event Timeline