Skip to content

Commit c164983

Browse files
committed
feat(metrics): Add a convenience API to track metrics directly
1 parent 1267668 commit c164983

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sentry-core/src/metrics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
99
use sentry_types::protocol::latest::{Envelope, EnvelopeItem};
1010

1111
use crate::client::TransportArc;
12+
use crate::Hub;
1213

1314
use crate::units::DurationUnit;
1415
pub use crate::units::MetricUnit;
@@ -344,6 +345,12 @@ impl MetricBuilder {
344345
pub fn finish(self) -> Metric {
345346
self.metric
346347
}
348+
349+
pub fn send(self) {
350+
if let Some(client) = Hub::current().client() {
351+
client.add_metric(self.finish());
352+
}
353+
}
347354
}
348355

349356
pub struct MetricAggregator {

0 commit comments

Comments
 (0)