spans on the stat add function

This commit is contained in:
Bryan Stitt 2023-07-21 14:27:43 -07:00
parent dc4b6d501c
commit d4518cd2bf
2 changed files with 21 additions and 4 deletions

View File

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

View File

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