Skip to content

Commit 52c9dd0

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

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
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: 5 additions & 3 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])
@@ -124,9 +129,6 @@ pub struct MetricAggregator {
124129
handle: Option<JoinHandle<()>>,
125130
}
126131

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

0 commit comments

Comments
 (0)