From 06a48c45f97aa045787f7d380f5270ca2e71e2ab Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Tue, 6 Aug 2024 13:20:24 +1200 Subject: [PATCH] feat: Write coordinator logs in GCP compatible format --- coordinator/Cargo.lock | 1 + coordinator/Cargo.toml | 1 + coordinator/src/main.rs | 14 ++++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/coordinator/Cargo.lock b/coordinator/Cargo.lock index 0e4e5e24f..222416d8c 100644 --- a/coordinator/Cargo.lock +++ b/coordinator/Cargo.lock @@ -1307,6 +1307,7 @@ dependencies = [ "tonic 0.10.2", "tonic-build 0.10.2", "tracing", + "tracing-stackdriver", "tracing-subscriber", ] diff --git a/coordinator/Cargo.toml b/coordinator/Cargo.toml index a595dcf2f..6829bb03f 100644 --- a/coordinator/Cargo.toml +++ b/coordinator/Cargo.toml @@ -12,6 +12,7 @@ tokio = "1.28" tonic = "0.10.2" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } +tracing-stackdriver = "0.10.0" serde = "1.0.195" serde_json = "1.0.108" diff --git a/coordinator/src/main.rs b/coordinator/src/main.rs index fef71dd32..37cd3dcbd 100644 --- a/coordinator/src/main.rs +++ b/coordinator/src/main.rs @@ -33,10 +33,16 @@ async fn sleep(duration: Duration) -> anyhow::Result<()> { #[tokio::main] async fn main() -> anyhow::Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::fmt::layer()) - .with(tracing_subscriber::EnvFilter::from_default_env()) - .init(); + let subscriber = + tracing_subscriber::registry().with(tracing_subscriber::EnvFilter::from_default_env()); + + if std::env::var("GCP_LOGGING_ENABLED").is_ok() { + subscriber.with(tracing_stackdriver::layer()).init(); + } else { + subscriber + .with(tracing_subscriber::fmt::layer().compact()) + .init(); + } let rpc_url = std::env::var("RPC_URL").expect("RPC_URL is not set"); let registry_contract_id = std::env::var("REGISTRY_CONTRACT_ID")