Skip to content

feat(metrics): Preliminary work for metrics aggregation #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 76 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test = ["client"]
log = { version = "0.4.8", optional = true, features = ["std"] }
once_cell = "1"
rand = { version = "0.8.1", optional = true }
rng = "0.1.0"
sentry-types = { version = "0.31.7", path = "../sentry-types" }
serde = { version = "1.0.104", features = ["derive"] }
serde_json = { version = "1.0.46" }
Expand Down
10 changes: 10 additions & 0 deletions sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use sentry_types::protocol::v7::SessionUpdate;
use sentry_types::random_uuid;

use crate::constants::SDK_INFO;
use crate::metrics::MetricsAggregator;
use crate::protocol::{ClientSdkInfo, Event};
use crate::session::SessionFlusher;
use crate::types::{Dsn, Uuid};
Expand Down Expand Up @@ -45,6 +46,7 @@ pub struct Client {
options: ClientOptions,
transport: TransportArc,
session_flusher: RwLock<Option<SessionFlusher>>,
pub(crate) metrics_aggregator: RwLock<Option<MetricsAggregator>>,
integrations: Vec<(TypeId, Arc<dyn Integration>)>,
pub(crate) sdk_info: ClientSdkInfo,
}
Expand All @@ -65,10 +67,12 @@ impl Clone for Client {
transport.clone(),
self.options.session_mode,
)));
let metrics_aggregator = RwLock::new(Some(MetricsAggregator::new(transport.clone())));
Client {
options: self.options.clone(),
transport,
session_flusher,
metrics_aggregator,
integrations: self.integrations.clone(),
sdk_info: self.sdk_info.clone(),
}
Expand Down Expand Up @@ -136,10 +140,12 @@ impl Client {
transport.clone(),
options.session_mode,
)));
let metrics_aggregator = RwLock::new(Some(MetricsAggregator::new(transport.clone())));
Client {
options,
transport,
session_flusher,
metrics_aggregator,
integrations,
sdk_info,
}
Expand Down Expand Up @@ -313,6 +319,9 @@ impl Client {
if let Some(ref flusher) = *self.session_flusher.read().unwrap() {
flusher.flush();
}
if let Some(ref aggregator) = *self.metrics_aggregator.read().unwrap() {
aggregator.flush();
}
if let Some(ref transport) = *self.transport.read().unwrap() {
transport.flush(timeout.unwrap_or(self.options.shutdown_timeout))
} else {
Expand All @@ -329,6 +338,7 @@ impl Client {
/// `shutdown_timeout` in the client options.
pub fn close(&self, timeout: Option<Duration>) -> bool {
drop(self.session_flusher.write().unwrap().take());
drop(self.metrics_aggregator.write().unwrap().take());
let transport_opt = self.transport.write().unwrap().take();
if let Some(transport) = transport_opt {
sentry_debug!("client close; request transport to shut down");
Expand Down
3 changes: 3 additions & 0 deletions sentry-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ mod intodsn;
mod performance;
mod scope;
mod transport;
mod units;

// public api or exports from this crate
pub use crate::api::*;
Expand All @@ -145,6 +146,8 @@ mod hub_impl;
mod session;
#[cfg(feature = "client")]
pub use crate::client::Client;
#[cfg(feature = "client")]
mod metrics;

// test utilities
#[cfg(feature = "test")]
Expand Down
Loading