Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

- build(panic): Fix build without other dependencies ([#883](https://github.com/getsentry/sentry-rust/pull/883)) by @liskin
- The `sentry-panic` crate now builds successfully when used as a standalone dependency.
- fix(transport): add rate limits for logs ([#894](https://github.com/getsentry/sentry-rust/pull/894)) by @giortzisg

## 0.42.0

Expand Down
10 changes: 10 additions & 0 deletions sentry/src/transports/ratelimit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use httpdate::parse_http_date;
use std::time::{Duration, SystemTime};

use crate::protocol::EnvelopeItem;
use crate::protocol::ItemContainer;
use crate::Envelope;

/// A Utility that helps with rate limiting sentry requests.
Expand All @@ -12,6 +13,7 @@ pub struct RateLimiter {
session: Option<SystemTime>,
transaction: Option<SystemTime>,
attachment: Option<SystemTime>,
log_item: Option<SystemTime>,
}

impl RateLimiter {
Expand Down Expand Up @@ -56,6 +58,7 @@ impl RateLimiter {
"session" => self.session = new_time,
"transaction" => self.transaction = new_time,
"attachment" => self.attachment = new_time,
"log_item" => self.log_item = new_time,
_ => {}
}
}
Expand Down Expand Up @@ -89,6 +92,7 @@ impl RateLimiter {
RateLimitingCategory::Session => self.session,
RateLimitingCategory::Transaction => self.transaction,
RateLimitingCategory::Attachment => self.attachment,
RateLimitingCategory::LogItem => self.log_item,
}?;
time_left.duration_since(SystemTime::now()).ok()
}
Expand All @@ -112,6 +116,9 @@ impl RateLimiter {
}
EnvelopeItem::Transaction(_) => RateLimitingCategory::Transaction,
EnvelopeItem::Attachment(_) => RateLimitingCategory::Attachment,
EnvelopeItem::ItemContainer(ItemContainer::Logs(_)) => {
RateLimitingCategory::LogItem
}
_ => RateLimitingCategory::Any,
})
})
Expand All @@ -131,6 +138,8 @@ pub enum RateLimitingCategory {
Transaction,
/// Rate Limit pertaining to Attachments.
Attachment,
/// Rate Limit pertaining to Log Items.
LogItem,
}

#[cfg(test)]
Expand All @@ -145,6 +154,7 @@ mod tests {
assert!(rl.is_disabled(RateLimitingCategory::Error).unwrap() <= Duration::from_secs(120));
assert!(rl.is_disabled(RateLimitingCategory::Session).unwrap() <= Duration::from_secs(60));
assert!(rl.is_disabled(RateLimitingCategory::Transaction).is_none());
assert!(rl.is_disabled(RateLimitingCategory::LogItem).is_none());
assert!(rl.is_disabled(RateLimitingCategory::Any).is_none());

rl.update_from_sentry_header(
Expand Down
Loading