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

Print a warning if the rate limit was reached #2595

Merged
merged 3 commits into from
Jan 21, 2025
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Add SentryReplayQuality setting (`options.experimental.replay.quality`) ([#2582](https://github.com/getsentry/sentry-dart/pull/2582))
- SPM Support ([#2280](https://github.com/getsentry/sentry-dart/pull/2280))

### Enhancements

- Print a warning if the rate limit was reached ([#2595](https://github.com/getsentry/sentry-dart/pull/2595))

### Fixes

- WASM compat for Drift ([#2580](https://github.com/getsentry/sentry-dart/pull/2580))
Expand Down
4 changes: 4 additions & 0 deletions dart/lib/src/transport/http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class HttpTransport implements Transport {
if (response.statusCode == 200) {
return _parseEventId(response);
}
if (response.statusCode == 429) {
_options.logger(
SentryLevel.warning, 'Rate limit reached, failed to send envelope');
}
return SentryId.empty();
}

Expand Down
24 changes: 24 additions & 0 deletions dart/test/transport/http_transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ void main() {
expect(mockRateLimiter.errorCode, 429);
expect(mockRateLimiter.retryAfterHeader, '1');
expect(mockRateLimiter.sentryRateLimitHeader, isNull);

expect(fixture.loggedLevel, SentryLevel.warning);
expect(
fixture.loggedMessage, 'Rate limit reached, failed to send envelope');
});

test('sentryRateLimitHeader', () async {
Expand Down Expand Up @@ -207,6 +211,10 @@ void main() {
await sut.send(envelope);

expect(fixture.clientReportRecorder.discardedEvents.isEmpty, isTrue);

expect(fixture.loggedLevel, SentryLevel.warning);
expect(
fixture.loggedMessage, 'Rate limit reached, failed to send envelope');
});

test('does record lost event for error >= 500', () async {
Expand Down Expand Up @@ -237,6 +245,8 @@ class Fixture {
late var clientReportRecorder = MockClientReportRecorder();

HttpTransport getSut(http.Client client, RateLimiter rateLimiter) {
options.debug = true;
options.logger = mockLogger;
options.httpClient = client;
options.recorder = clientReportRecorder;
options.clock = () {
Expand All @@ -254,4 +264,18 @@ class Fixture {
final tracer = SentryTracer(context, MockHub());
return SentryTransaction(tracer);
}

SentryLevel? loggedLevel;
String? loggedMessage;

void mockLogger(
SentryLevel level,
String message, {
String? logger,
Object? exception,
StackTrace? stackTrace,
}) {
loggedLevel = level;
loggedMessage = message;
}
}
Loading