Skip to content

Commit 245cc23

Browse files
committed
refactor(hermes): improve logging
1 parent f12df15 commit 245cc23

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

hermes/Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hermes/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55
edition = "2021"
66

@@ -44,7 +44,7 @@ tokio = { version = "1.26.0", features = ["full"] }
4444
tonic = { version = "0.10.1", features = ["tls"] }
4545
tower-http = { version = "0.4.0", features = ["cors"] }
4646
tracing = { version = "0.1.37", features = ["log"] }
47-
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
47+
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] }
4848
utoipa = { version = "3.4.0", features = ["axum_extras"] }
4949
utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
5050
wormhole-sdk = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1" }

hermes/src/main.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,19 @@ async fn init() -> Result<()> {
107107
#[tracing::instrument]
108108
async fn main() -> Result<()> {
109109
// Initialize a Tracing Subscriber
110-
tracing::subscriber::set_global_default(
111-
tracing_subscriber::fmt()
112-
.compact()
113-
.with_file(false)
114-
.with_line_number(true)
115-
.with_thread_ids(true)
116-
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
117-
.with_ansi(std::io::stderr().is_terminal())
118-
.finish(),
119-
)?;
110+
let fmt_builder = tracing_subscriber::fmt()
111+
.with_file(false)
112+
.with_line_number(true)
113+
.with_thread_ids(true)
114+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
115+
.with_ansi(std::io::stderr().is_terminal());
116+
117+
// Use the compact formatter if we're in a terminal, otherwise use the JSON formatter.
118+
if std::io::stderr().is_terminal() {
119+
tracing::subscriber::set_global_default(fmt_builder.compact().finish())?;
120+
} else {
121+
tracing::subscriber::set_global_default(fmt_builder.json().finish())?;
122+
}
120123

121124
// Launch the application. If it fails, print the full backtrace and exit. RUST_BACKTRACE
122125
// should be set to 1 for this otherwise it will only print the top-level error.

hermes/src/state/benchmarks.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ impl Benchmarks for crate::state::State {
112112

113113
let response = request.send().await?;
114114

115+
if response.status() != reqwest::StatusCode::OK {
116+
return Err(anyhow::anyhow!(format!(
117+
"Price update for price ids {:?} with publish time {} not found in benchmarks. Status code: {}, message: {}",
118+
price_ids, publish_time, response.status(), response.text().await?
119+
)));
120+
}
121+
115122
let benchmark_updates: BenchmarkUpdates = response.json().await?;
116123
benchmark_updates.try_into()
117124
}

0 commit comments

Comments
 (0)