Skip to content

Commit

Permalink
ref(metrics): Minor code-level changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-auer committed Dec 11, 2023
1 parent f2c6410 commit 52c9dd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 4 additions & 6 deletions sentry-core/src/cadence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ pub struct SentryMetricSink<S> {
impl<S> SentryMetricSink<S> {
/// Creates a new [`SentryMetricSink`], wrapping the given [`MetricSink`].
pub fn try_new(sink: S) -> Result<Self, S> {
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),
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions sentry-core/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,12 +59,14 @@ struct GaugeValue {
sum: f64,
count: u64,
}

enum BucketValue {
Counter(f64),
Distribution(Vec<f64>),
Set(BTreeSet<String>),
Gauge(GaugeValue),
}

impl BucketValue {
fn distribution(val: f64) -> BucketValue {
Self::Distribution(vec![val])
Expand Down Expand Up @@ -124,9 +129,6 @@ pub struct MetricAggregator {
handle: Option<JoinHandle<()>>,
}

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);
Expand Down

0 comments on commit 52c9dd0

Please sign in to comment.