Skip to content

Commit

Permalink
Revert "update rate limiting for Sentry events to allow for burst"
Browse files Browse the repository at this point in the history
This reverts commit 6496207.
  • Loading branch information
krlvi committed Feb 6, 2024
1 parent 4462d08 commit 1501699
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions gitbutler-app/src/sentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ use governor::{
Quota, RateLimiter,
};
use nonzero_ext::nonzero;
use once_cell::sync::OnceCell;
use sentry::ClientInitGuard;
use sentry_tracing::SentryLayer;
use tracing::Subscriber;
use tracing_subscriber::{filter::FilterExt, registry::LookupSpan};
use tracing_subscriber::registry::LookupSpan;

use crate::users;

static SENTRY_BURST: once_cell::sync::Lazy<RateLimiter<NotKeyed, InMemoryState, QuantaClock>> =
once_cell::sync::Lazy::new(|| RateLimiter::direct(Quota::per_second(nonzero!(15_u32))));

static SENTRY_HOUR_LIMIT: once_cell::sync::Lazy<RateLimiter<NotKeyed, InMemoryState, QuantaClock>> =
once_cell::sync::Lazy::new(|| RateLimiter::direct(Quota::per_hour(nonzero!(100_u32))));
static SENTRY_QUOTA: Quota = Quota::per_second(nonzero!(1_u32)); // 1 per second at most.
static SENTRY_LIMIT: OnceCell<RateLimiter<NotKeyed, InMemoryState, QuantaClock>> = OnceCell::new();

/// Should be called once on application startup, and the returned guard should be kept alive for
/// the lifetime of the application.
Expand All @@ -31,9 +29,7 @@ pub fn init(name: &str, version: String) -> ClientInitGuard {
}.into()),
release: Some(version.into()),
before_send: Some({
Arc::new(|event|
SENTRY_BURST.check().and(SENTRY_HOUR_LIMIT.check()).is_ok().then_some(event)
)}),
Arc::new(|event| SENTRY_LIMIT.get_or_init(|| RateLimiter::direct(SENTRY_QUOTA)).check().is_ok().then_some(event))}),
attach_stacktrace: true,
traces_sample_rate: match name {
"GitButler Dev" | "GitButler Nightly" => 0.2_f32,
Expand Down

0 comments on commit 1501699

Please sign in to comment.