Skip to content
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

Add experimental metrics implementation #618

Merged
merged 34 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9f33090
Add experimental metrics implementation
Swatinem Oct 17, 2023
c83b9aa
finish up impl
Swatinem Oct 18, 2023
dd22afb
implement sets the naive way
Swatinem Oct 18, 2023
2fc55ae
do not emit an empty envelope item on shutdown
Swatinem Oct 18, 2023
97c9a0c
review
Swatinem Oct 20, 2023
b6bdece
add rate limit category
Swatinem Oct 23, 2023
331a457
fix typo
Swatinem Oct 23, 2023
a61de48
fix build
Swatinem Oct 23, 2023
06c483a
try to fix flush race on windows
Swatinem Oct 23, 2023
c692048
fix doc builds
Swatinem Oct 23, 2023
b568ebc
remove forced shutdown from metrics aggregator
Swatinem Oct 23, 2023
255c578
Merge branch 'master' into swatinem/metrics
jan-auer Dec 11, 2023
dc5ea74
ref(metrics): Minor review comments
jan-auer Dec 11, 2023
f2c6410
ref: Separate cadence from metrics feature
jan-auer Dec 11, 2023
45a4ac1
ref(metrics): Minor code-level changes
jan-auer Dec 11, 2023
d24c9b2
ref(metrics): Refactor to match Python SDK
jan-auer Dec 11, 2023
b515db3
fix: First bugfixes
jan-auer Dec 11, 2023
1267668
fix: Flakey submission
jan-auer Dec 11, 2023
c164983
feat(metrics): Add a convenience API to track metrics directly
jan-auer Dec 11, 2023
ba4afe0
fix: Move statsd parsing to metrics module
jan-auer Dec 11, 2023
bcc665b
ref(metrics): Reorganize and add docs
jan-auer Dec 11, 2023
32e6baa
test: Add a first unit test
jan-auer Dec 11, 2023
0ef19a3
feat(metrics): Inject default tags
jan-auer Dec 11, 2023
12bf258
ref(metrics): Simplify unit handling
jan-auer Dec 12, 2023
d90d14c
feat(metrics): Further improvements to docs and cadence
jan-auer Dec 12, 2023
524a5a9
fix(metrics): Sanitation behavior
jan-auer Dec 12, 2023
c506251
fix: Docs
jan-auer Dec 12, 2023
c3f7247
ref(metrics): Refactor worker into separate struct
jan-auer Dec 12, 2023
edbbb95
ref(metrics): Add more Debug impls
jan-auer Dec 12, 2023
55b7f28
ref: Rename metric item to "statsd"
jan-auer Dec 12, 2023
ab14afa
ref(metrics): Flush synchronously
jan-auer Dec 12, 2023
0c4064c
ref: Address review feedback
jan-auer Dec 12, 2023
139cdf3
ref(metrics): Reduce duplication of bucket key
jan-auer Dec 12, 2023
69080ab
meta: Changelog
jan-auer Dec 12, 2023
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
36 changes: 23 additions & 13 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ client = ["rand"]
# and macros actually expand features (and extern crate) where they are used!
debug-logs = ["dep:log"]
test = ["client"]
UNSTABLE_metrics = ["dep:cadence", "sentry-types/UNSTABLE_metrics"]

[dependencies]
cadence = { version = "0.29.0", optional = true }
log = { version = "0.4.8", optional = true, features = ["std"] }
once_cell = "1"
rand = { version = "0.8.1", optional = true }
Expand Down
27 changes: 27 additions & 0 deletions sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use sentry_types::protocol::v7::SessionUpdate;
use sentry_types::random_uuid;

use crate::constants::SDK_INFO;
#[cfg(feature = "UNSTABLE_metrics")]
use crate::metrics::MetricFlusher;
use crate::protocol::{ClientSdkInfo, Event};
use crate::session::SessionFlusher;
use crate::types::{Dsn, Uuid};
Expand Down Expand Up @@ -45,6 +47,8 @@ pub struct Client {
options: ClientOptions,
transport: TransportArc,
session_flusher: RwLock<Option<SessionFlusher>>,
#[cfg(feature = "UNSTABLE_metrics")]
metrics_flusher: RwLock<Option<MetricFlusher>>,
integrations: Vec<(TypeId, Arc<dyn Integration>)>,
pub(crate) sdk_info: ClientSdkInfo,
}
Expand All @@ -65,10 +69,14 @@ impl Clone for Client {
transport.clone(),
self.options.session_mode,
)));
#[cfg(feature = "UNSTABLE_metrics")]
let metrics_flusher = RwLock::new(Some(MetricFlusher::new(transport.clone())));
jan-auer marked this conversation as resolved.
Show resolved Hide resolved
Client {
options: self.options.clone(),
transport,
session_flusher,
#[cfg(feature = "UNSTABLE_metrics")]
metrics_flusher,
integrations: self.integrations.clone(),
sdk_info: self.sdk_info.clone(),
}
Expand Down Expand Up @@ -136,10 +144,16 @@ impl Client {
transport.clone(),
options.session_mode,
)));

#[cfg(feature = "UNSTABLE_metrics")]
let metrics_flusher = RwLock::new(Some(MetricFlusher::new(transport.clone())));

Client {
options,
transport,
session_flusher,
#[cfg(feature = "UNSTABLE_metrics")]
metrics_flusher,
integrations,
sdk_info,
}
Expand Down Expand Up @@ -308,11 +322,22 @@ impl Client {
}
}

#[cfg(feature = "UNSTABLE_metrics")]
pub(crate) fn send_metric(&self, metric: &str) {
if let Some(ref flusher) = *self.metrics_flusher.read().unwrap() {
flusher.send_metric(metric)
jan-auer marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Drains all pending events without shutting down.
pub fn flush(&self, timeout: Option<Duration>) -> bool {
if let Some(ref flusher) = *self.session_flusher.read().unwrap() {
flusher.flush();
}
#[cfg(feature = "UNSTABLE_metrics")]
if let Some(ref flusher) = *self.metrics_flusher.read().unwrap() {
flusher.flush();
}
if let Some(ref transport) = *self.transport.read().unwrap() {
transport.flush(timeout.unwrap_or(self.options.shutdown_timeout))
} else {
Expand All @@ -329,6 +354,8 @@ impl Client {
/// `shutdown_timeout` in the client options.
pub fn close(&self, timeout: Option<Duration>) -> bool {
drop(self.session_flusher.write().unwrap().take());
#[cfg(feature = "UNSTABLE_metrics")]
drop(self.metrics_flusher.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
4 changes: 4 additions & 0 deletions sentry-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,14 @@ pub use crate::transport::{Transport, TransportFactory};
mod client;
#[cfg(feature = "client")]
mod hub_impl;
#[cfg(all(feature = "client", feature = "UNSTABLE_metrics"))]
mod metrics;
#[cfg(feature = "client")]
mod session;
#[cfg(feature = "client")]
pub use crate::client::Client;
#[cfg(all(feature = "client", feature = "UNSTABLE_metrics"))]
pub use crate::metrics::SentryMetricSink;

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