Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include tracing_stackdriver layer to format logs for GCP #803

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions chain-signatures/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain-signatures/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tokio = { version = "1.28", features = ["full"] }
tokio-retry = "0.3"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-stackdriver = "0.10.0"
url = { version = "2.4.0", features = ["serde"] }

near-account-id = "1.0.0"
Expand Down
21 changes: 15 additions & 6 deletions chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use near_account_id::AccountId;
use near_crypto::{InMemorySigner, SecretKey};
use std::sync::Arc;
use tokio::sync::{mpsc, RwLock};
use tracing_subscriber::EnvFilter;
use tracing_stackdriver::layer as stackdriver_layer;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
use url::Url;

use mpc_keys::hpke;
Expand Down Expand Up @@ -144,14 +145,22 @@ fn is_running_on_gcp() -> bool {

pub fn run(cmd: Cli) -> anyhow::Result<()> {
// Install global collector configured based on RUST_LOG env var.
let mut subscriber = tracing_subscriber::fmt()
.with_thread_ids(true)
.with_env_filter(EnvFilter::from_default_env());
let stackdriver = stackdriver_layer().with_writer(std::io::stderr);

let mut fmt_layer = tracing_subscriber::fmt::layer().with_thread_ids(true);

if is_running_on_gcp() {
// Disable colored logging as it messes up GCP's log formatting
subscriber = subscriber.with_ansi(false);
fmt_layer = fmt_layer.with_ansi(false);
}
subscriber.init();

let subscriber = Registry::default()
.with(EnvFilter::from_default_env())
.with(fmt_layer)
.with(stackdriver);

tracing::subscriber::set_global_default(subscriber).expect("Failed to set subscriber");

let _span = tracing::trace_span!("cli").entered();

match cmd {
Expand Down
33 changes: 31 additions & 2 deletions integration-tests/chain-signatures/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading