diff --git a/sentry-core/src/cadence.rs b/sentry-core/src/cadence.rs index 10304ac3..691026fd 100644 --- a/sentry-core/src/cadence.rs +++ b/sentry-core/src/cadence.rs @@ -17,12 +17,10 @@ pub struct SentryMetricSink { impl SentryMetricSink { /// Creates a new [`SentryMetricSink`], wrapping the given [`MetricSink`]. pub fn try_new(sink: S) -> Result { - let hub = Hub::current(); - let Some(client) = hub.client() else { - return Err(sink); - }; - - Ok(Self { client, sink }) + match Hub::current().client() { + Some(client) => Ok(Self { client, sink }), + None => Err(sink), + } } } diff --git a/sentry-core/src/metrics.rs b/sentry-core/src/metrics.rs index 682ab695..a8b405e5 100644 --- a/sentry-core/src/metrics.rs +++ b/sentry-core/src/metrics.rs @@ -9,6 +9,9 @@ use sentry_types::protocol::latest::{Envelope, EnvelopeItem}; use crate::client::TransportArc; +const BUCKET_INTERVAL: Duration = Duration::from_secs(10); +const FLUSH_INTERVAL: Duration = Duration::from_secs(10); + #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] enum MetricType { Counter, @@ -56,12 +59,14 @@ struct GaugeValue { sum: f64, count: u64, } + enum BucketValue { Counter(f64), Distribution(Vec), Set(BTreeSet), Gauge(GaugeValue), } + impl BucketValue { fn distribution(val: f64) -> BucketValue { Self::Distribution(vec![val]) @@ -124,9 +129,6 @@ pub struct MetricAggregator { handle: Option>, } -const BUCKET_INTERVAL: Duration = Duration::from_secs(10); -const FLUSH_INTERVAL: Duration = Duration::from_secs(10); - impl MetricAggregator { pub fn new(transport: TransportArc) -> Self { let (sender, receiver) = mpsc::sync_channel(30);