Skip to content

Commit 45a4ac1

Browse files
committed
ref(metrics): Minor code-level changes
1 parent f2c6410 commit 45a4ac1

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

sentry-core/src/cadence.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ pub struct SentryMetricSink<S> {
1717
impl<S> SentryMetricSink<S> {
1818
/// Creates a new [`SentryMetricSink`], wrapping the given [`MetricSink`].
1919
pub fn try_new(sink: S) -> Result<Self, S> {
20-
let hub = Hub::current();
21-
let Some(client) = hub.client() else {
22-
return Err(sink);
23-
};
24-
25-
Ok(Self { client, sink })
20+
match Hub::current().client() {
21+
Some(client) => Ok(Self { client, sink }),
22+
None => Err(sink),
23+
}
2624
}
2725
}
2826

sentry-core/src/metrics.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use sentry_types::protocol::latest::{Envelope, EnvelopeItem};
99

1010
use crate::client::TransportArc;
1111

12+
const BUCKET_INTERVAL: Duration = Duration::from_secs(10);
13+
const FLUSH_INTERVAL: Duration = Duration::from_secs(10);
14+
1215
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
1316
enum MetricType {
1417
Counter,
@@ -56,12 +59,14 @@ struct GaugeValue {
5659
sum: f64,
5760
count: u64,
5861
}
62+
5963
enum BucketValue {
6064
Counter(f64),
6165
Distribution(Vec<f64>),
6266
Set(BTreeSet<String>),
6367
Gauge(GaugeValue),
6468
}
69+
6570
impl BucketValue {
6671
fn distribution(val: f64) -> BucketValue {
6772
Self::Distribution(vec![val])
@@ -89,7 +94,9 @@ impl BucketValue {
8994
(BucketValue::Distribution(d1), BucketValue::Distribution(d2)) => {
9095
d1.extend(d2);
9196
}
92-
(BucketValue::Set(s1), BucketValue::Set(s2)) => s1.extend(s2),
97+
(BucketValue::Set(s1), BucketValue::Set(s2)) => {
98+
s1.extend(s2);
99+
}
93100
(BucketValue::Gauge(g1), BucketValue::Gauge(g2)) => {
94101
g1.last = g2.last;
95102
g1.min = g1.min.min(g2.min);
@@ -99,6 +106,7 @@ impl BucketValue {
99106
}
100107
_ => return Err(()),
101108
}
109+
102110
Ok(())
103111
}
104112
}
@@ -124,9 +132,6 @@ pub struct MetricAggregator {
124132
handle: Option<JoinHandle<()>>,
125133
}
126134

127-
const BUCKET_INTERVAL: Duration = Duration::from_secs(10);
128-
const FLUSH_INTERVAL: Duration = Duration::from_secs(10);
129-
130135
impl MetricAggregator {
131136
pub fn new(transport: TransportArc) -> Self {
132137
let (sender, receiver) = mpsc::sync_channel(30);

0 commit comments

Comments
 (0)