From d4518cd2bfc786554615a80fcbb2056a39aeec0d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 21 Jul 2023 14:27:43 -0700 Subject: [PATCH] spans on the stat add function --- web3_proxy/Cargo.toml | 4 ++-- web3_proxy/src/stats/stat_buffer.rs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index e6f76722..e471dc01 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -48,6 +48,7 @@ check-if-email-exists = "0.9.0" chrono = { version = "0.4.26" } console-subscriber = { version = "0.1.10", features = ["env-filter", "parking_lot"], optional = true } counter = "0.5.7" +derivative = "2.2.0" derive_more = { version = "0.99.17", features = ["nightly"] } ethbloom = { version = "0.13.0" } ethers = { version = "2.0.8", default-features = false, features = ["rustls", "ws"] } @@ -83,6 +84,7 @@ rust_decimal = { version = "1.30.0", features = ["maths"] } sentry = { version = "0.31.5", default-features = false, features = ["anyhow", "backtrace", "contexts", "panic", "reqwest", "rustls", "serde_json", "tracing"] } sentry-tracing = "0.31.5" serde = { version = "1.0.173" } +serde-inline-default = "0.1.1" serde_json = { version = "1.0.103", default-features = false, features = ["raw_value"] } serde_prometheus = "0.2.3" strum = { version = "0.25.0", features = ["derive"] } @@ -102,8 +104,6 @@ uuid = { version = "1.4.1", default-features = false, features = ["fast-rng", "v # TODO: why doesn't this work in dev-dependencies test-log = { version = "0.2.12", default-features = false, features = ["trace"] } -serde-inline-default = "0.1.1" -derivative = "2.2.0" [dev-dependencies] env_logger = "0.10" diff --git a/web3_proxy/src/stats/stat_buffer.rs b/web3_proxy/src/stats/stat_buffer.rs index e2f75b5b..7e384a06 100644 --- a/web3_proxy/src/stats/stat_buffer.rs +++ b/web3_proxy/src/stats/stat_buffer.rs @@ -13,7 +13,7 @@ use migration::sea_orm::prelude::Decimal; use std::time::Duration; use tokio::sync::{broadcast, mpsc, oneshot}; use tokio::time::{interval, sleep}; -use tracing::{error, info, trace, warn}; +use tracing::{error, info, trace, warn, Instrument}; use ulid::Ulid; #[derive(Debug, Default)] @@ -277,29 +277,46 @@ impl StatBuffer { let accounting_key = stat.accounting_key(self.billing_period_seconds); if accounting_key.is_registered() { + let span = tracing::trace_span!( + "accounting", + key = tracing::field::debug(&accounting_key) + ) + .or_current(); self.accounting_db_buffer .entry(accounting_key) .or_default() .add(stat.clone(), approximate_balance_remaining) + .instrument(span) .await; } } if self.influxdb_client.is_some() { if let Some(opt_in_timeseries_key) = stat.owned_timeseries_key(active_premium) { + let span = tracing::trace_span!( + "owned_timeseries", + key = tracing::field::debug(&opt_in_timeseries_key) + ) + .or_current(); self.opt_in_timeseries_buffer .entry(opt_in_timeseries_key) .or_default() .add(stat.clone(), approximate_balance_remaining) + .instrument(span) .await; } let global_timeseries_key = stat.global_timeseries_key(); - + let span = tracing::trace_span!( + "global_timeseries", + key = tracing::field::debug(&global_timeseries_key) + ) + .or_current(); self.global_timeseries_buffer .entry(global_timeseries_key) .or_default() .add(stat, approximate_balance_remaining) + .instrument(span) .await; }