refactor(hermes): improve logging

This commit is contained in:
Ali Behjati 2023-12-08 14:48:47 +00:00
parent f12df1528b
commit 245cc231fd
4 changed files with 36 additions and 13 deletions

15
hermes/Cargo.lock generated
View File

@ -1574,7 +1574,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermes"
version = "0.4.4"
version = "0.4.5"
dependencies = [
"anyhow",
"async-trait",
@ -4900,6 +4900,16 @@ dependencies = [
"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.17"
@ -4910,12 +4920,15 @@ dependencies = [
"nu-ansi-term",
"once_cell",
"regex",
"serde",
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
"tracing-serde",
]
[[package]]

View File

@ -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"
@ -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" }

View File

@ -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.

View File

@ -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()
}