Skip to content

Commit

Permalink
refactor(hermes): improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati committed Dec 11, 2023
1 parent f12df15 commit 245cc23
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
15 changes: 14 additions & 1 deletion hermes/Cargo.lock

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

4 changes: 2 additions & 2 deletions hermes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hermes"
version = "0.4.4"
version = "0.4.5"
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
edition = "2021"

Expand Down Expand Up @@ -44,7 +44,7 @@ tokio = { version = "1.26.0", features = ["full"] }
tonic = { version = "0.10.1", features = ["tls"] }
tower-http = { version = "0.4.0", features = ["cors"] }
tracing = { version = "0.1.37", features = ["log"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] }
utoipa = { version = "3.4.0", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
wormhole-sdk = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1" }
Expand Down
23 changes: 13 additions & 10 deletions hermes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,19 @@ async fn init() -> Result<()> {
#[tracing::instrument]
async fn main() -> Result<()> {
// Initialize a Tracing Subscriber
tracing::subscriber::set_global_default(
tracing_subscriber::fmt()
.compact()
.with_file(false)
.with_line_number(true)
.with_thread_ids(true)
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_ansi(std::io::stderr().is_terminal())
.finish(),
)?;
let fmt_builder = tracing_subscriber::fmt()
.with_file(false)
.with_line_number(true)
.with_thread_ids(true)
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_ansi(std::io::stderr().is_terminal());

// Use the compact formatter if we're in a terminal, otherwise use the JSON formatter.
if std::io::stderr().is_terminal() {
tracing::subscriber::set_global_default(fmt_builder.compact().finish())?;
} else {
tracing::subscriber::set_global_default(fmt_builder.json().finish())?;
}

// Launch the application. If it fails, print the full backtrace and exit. RUST_BACKTRACE
// should be set to 1 for this otherwise it will only print the top-level error.
Expand Down
7 changes: 7 additions & 0 deletions hermes/src/state/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ impl Benchmarks for crate::state::State {

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

if response.status() != reqwest::StatusCode::OK {
return Err(anyhow::anyhow!(format!(
"Price update for price ids {:?} with publish time {} not found in benchmarks. Status code: {}, message: {}",
price_ids, publish_time, response.status(), response.text().await?
)));
}

let benchmark_updates: BenchmarkUpdates = response.json().await?;
benchmark_updates.try_into()
}
Expand Down

0 comments on commit 245cc23

Please sign in to comment.