Skip to content

Commit 659f5b2

Browse files
Denis AndrašecDenis Andrašec
Denis Andrašec
authored and
Denis Andrašec
committed
rename classes
1 parent 75ab5bb commit 659f5b2

10 files changed

+118
-121
lines changed

dart/lib/src/client_reports/client_report_recorder.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '../sentry_options.dart';
44
import 'client_report.dart';
55
import 'discarded_event.dart';
66
import 'outcome.dart';
7-
import '../transport/rate_limit_category.dart';
7+
import '../transport/data_category.dart';
88

99
@internal
1010
class ClientReportRecorder {
@@ -13,7 +13,8 @@ class ClientReportRecorder {
1313
final ClockProvider _clock;
1414
final Map<_QuantityKey, int> _quantities = {};
1515

16-
void recordLostEvent(final Outcome reason, final RateLimitCategory category) {
16+
void recordLostEvent(
17+
final DiscardReason reason, final DataCategory category) {
1718
final key = _QuantityKey(reason, category);
1819
var current = _quantities[key] ?? 0;
1920
_quantities[key] = current + 1;
@@ -38,8 +39,8 @@ class ClientReportRecorder {
3839
class _QuantityKey {
3940
_QuantityKey(this.reason, this.category);
4041

41-
final Outcome reason;
42-
final RateLimitCategory category;
42+
final DiscardReason reason;
43+
final DataCategory category;
4344

4445
@override
4546
int get hashCode => Object.hash(reason, category);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import 'package:meta/meta.dart';
22

33
import 'outcome.dart';
4-
import '../transport/rate_limit_category.dart';
4+
import '../transport/data_category.dart';
55

66
@internal
77
class DiscardedEvent {
88
DiscardedEvent(this.reason, this.category, this.quantity);
99

10-
final Outcome reason;
11-
final RateLimitCategory category;
10+
final DiscardReason reason;
11+
final DataCategory category;
1212
final int quantity;
1313
}

dart/lib/src/client_reports/outcome.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'package:meta/meta.dart';
22

33
@internal
4-
enum Outcome { ratelimitBackoff, networkError }
4+
enum DiscardReason { ratelimitBackoff, networkError }
55

6-
extension OutcomeExtension on Outcome {
6+
extension OutcomeExtension on DiscardReason {
77
String toStringValue() {
88
switch (this) {
9-
case Outcome.ratelimitBackoff:
9+
case DiscardReason.ratelimitBackoff:
1010
return 'ratelimit_backoff';
11-
case Outcome.networkError:
11+
case DiscardReason.networkError:
1212
return 'network_error';
1313
}
1414
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// Different category types of data sent to Sentry. Used for rate limiting and client reports.
2+
enum DataCategory {
3+
all,
4+
rate_limit_default, // default
5+
error,
6+
session,
7+
transaction,
8+
attachment,
9+
security,
10+
unknown
11+
}
12+
13+
extension DataCategoryExtension on DataCategory {
14+
static DataCategory fromStringValue(String stringValue) {
15+
switch (stringValue) {
16+
case '__all__':
17+
return DataCategory.all;
18+
case 'default':
19+
return DataCategory.rate_limit_default;
20+
case 'error':
21+
return DataCategory.error;
22+
case 'session':
23+
return DataCategory.session;
24+
case 'transaction':
25+
return DataCategory.transaction;
26+
case 'attachment':
27+
return DataCategory.attachment;
28+
case 'security':
29+
return DataCategory.security;
30+
}
31+
return DataCategory.unknown;
32+
}
33+
34+
String toStringValue() {
35+
switch (this) {
36+
case DataCategory.all:
37+
return '__all__';
38+
case DataCategory.rate_limit_default:
39+
return 'default';
40+
case DataCategory.error:
41+
return 'error';
42+
case DataCategory.session:
43+
return 'session';
44+
case DataCategory.transaction:
45+
return 'transaction';
46+
case DataCategory.attachment:
47+
return 'attachment';
48+
case DataCategory.security:
49+
return 'security';
50+
case DataCategory.unknown:
51+
return 'unknown';
52+
}
53+
}
54+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import 'rate_limit_category.dart';
1+
import 'data_category.dart';
22

3-
/// `RateLimit` containing limited `RateLimitCategory` and duration in milliseconds.
3+
/// `RateLimit` containing limited `DataCategory` and duration in milliseconds.
44
class RateLimit {
55
RateLimit(this.category, this.duration);
66

7-
final RateLimitCategory category;
7+
final DataCategory category;
88
final Duration duration;
99
}

dart/lib/src/transport/rate_limit_category.dart

Lines changed: 0 additions & 54 deletions
This file was deleted.

dart/lib/src/transport/rate_limit_parser.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'rate_limit_category.dart';
1+
import 'data_category.dart';
22
import 'rate_limit.dart';
33

44
/// Parse rate limit categories and times from response header payloads.
@@ -29,23 +29,20 @@ class RateLimitParser {
2929
if (allCategories.isNotEmpty) {
3030
final categoryValues = allCategories.split(';');
3131
for (final categoryValue in categoryValues) {
32-
final category =
33-
RateLimitCategoryExtension.fromStringValue(categoryValue);
34-
if (category != RateLimitCategory.unknown) {
32+
final category = DataCategoryExtension.fromStringValue(categoryValue);
33+
if (category != DataCategory.unknown) {
3534
rateLimits.add(RateLimit(category, duration));
3635
}
3736
}
3837
} else {
39-
rateLimits.add(RateLimit(RateLimitCategory.all, duration));
38+
rateLimits.add(RateLimit(DataCategory.all, duration));
4039
}
4140
}
4241
return rateLimits;
4342
}
4443

4544
List<RateLimit> parseRetryAfterHeader() {
46-
return [
47-
RateLimit(RateLimitCategory.all, _parseRetryAfterOrDefault(_header))
48-
];
45+
return [RateLimit(DataCategory.all, _parseRetryAfterOrDefault(_header))];
4946
}
5047

5148
// Helper

dart/lib/src/transport/rate_limiter.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import '../sentry_options.dart';
44
import '../sentry_envelope.dart';
55
import '../sentry_envelope_item.dart';
66
import 'rate_limit.dart';
7-
import 'rate_limit_category.dart';
7+
import 'data_category.dart';
88

99
/// Controls retry limits on different category types sent to Sentry.
1010
class RateLimiter {
1111
RateLimiter(this._clockProvider);
1212

1313
final ClockProvider _clockProvider;
14-
final _rateLimitedUntil = <RateLimitCategory, DateTime>{};
14+
final _rateLimitedUntil = <DataCategory, DateTime>{};
1515

1616
/// Filter out envelopes that are rate limited.
1717
SentryEnvelope? filter(SentryEnvelope envelope) {
@@ -75,15 +75,15 @@ class RateLimiter {
7575
_clockProvider().millisecondsSinceEpoch);
7676

7777
// check all categories
78-
final dateAllCategories = _rateLimitedUntil[RateLimitCategory.all];
78+
final dateAllCategories = _rateLimitedUntil[DataCategory.all];
7979
if (dateAllCategories != null) {
8080
if (!currentDate.isAfter(dateAllCategories)) {
8181
return true;
8282
}
8383
}
8484

8585
// Unknown should not be rate limited
86-
if (RateLimitCategory.unknown == dataCategory) {
86+
if (DataCategory.unknown == dataCategory) {
8787
return false;
8888
}
8989

@@ -96,28 +96,27 @@ class RateLimiter {
9696
return false;
9797
}
9898

99-
RateLimitCategory _categoryFromItemType(String itemType) {
99+
DataCategory _categoryFromItemType(String itemType) {
100100
switch (itemType) {
101101
case 'event':
102-
return RateLimitCategory.error;
102+
return DataCategory.error;
103103
case 'session':
104-
return RateLimitCategory.session;
104+
return DataCategory.session;
105105
case 'attachment':
106-
return RateLimitCategory.attachment;
106+
return DataCategory.attachment;
107107
case 'transaction':
108-
return RateLimitCategory.transaction;
108+
return DataCategory.transaction;
109109
default:
110-
return RateLimitCategory.unknown;
110+
return DataCategory.unknown;
111111
}
112112
}
113113

114-
void _applyRetryAfterOnlyIfLonger(
115-
RateLimitCategory rateLimitCategory, DateTime date) {
116-
final oldDate = _rateLimitedUntil[rateLimitCategory];
114+
void _applyRetryAfterOnlyIfLonger(DataCategory dataCategory, DateTime date) {
115+
final oldDate = _rateLimitedUntil[dataCategory];
117116

118117
// only overwrite its previous date if the limit is even longer
119118
if (oldDate == null || date.isAfter(oldDate)) {
120-
_rateLimitedUntil[rateLimitCategory] = date;
119+
_rateLimitedUntil[dataCategory] = date;
121120
}
122121
}
123122
}

dart/test/client_reports/client_report_recorder_test.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:sentry/src/client_reports/outcome.dart';
2-
import 'package:sentry/src/transport/rate_limit_category.dart';
2+
import 'package:sentry/src/transport/data_category.dart';
33
import 'package:test/test.dart';
44

55
import 'package:sentry/src/client_reports/client_report_recorder.dart';
@@ -23,7 +23,7 @@ void main() {
2323
test('flush returns client report with current date', () {
2424
final sut = fixture.getSut();
2525

26-
sut.recordLostEvent(Outcome.ratelimitBackoff, RateLimitCategory.error);
26+
sut.recordLostEvent(DiscardReason.ratelimitBackoff, DataCategory.error);
2727

2828
final clientReport = sut.flush();
2929

@@ -33,47 +33,47 @@ void main() {
3333
test('record lost event', () {
3434
final sut = fixture.getSut();
3535

36-
sut.recordLostEvent(Outcome.ratelimitBackoff, RateLimitCategory.error);
37-
sut.recordLostEvent(Outcome.ratelimitBackoff, RateLimitCategory.error);
36+
sut.recordLostEvent(DiscardReason.ratelimitBackoff, DataCategory.error);
37+
sut.recordLostEvent(DiscardReason.ratelimitBackoff, DataCategory.error);
3838

3939
final clientReport = sut.flush();
4040

4141
final event = clientReport?.discardedEvents
42-
.firstWhere((element) => element.category == RateLimitCategory.error);
42+
.firstWhere((element) => element.category == DataCategory.error);
4343

44-
expect(event?.reason, Outcome.ratelimitBackoff);
45-
expect(event?.category, RateLimitCategory.error);
44+
expect(event?.reason, DiscardReason.ratelimitBackoff);
45+
expect(event?.category, DataCategory.error);
4646
expect(event?.quantity, 2);
4747
});
4848

4949
test('record outcomes with different categories recorded separately', () {
5050
final sut = fixture.getSut();
5151

52-
sut.recordLostEvent(Outcome.ratelimitBackoff, RateLimitCategory.error);
52+
sut.recordLostEvent(DiscardReason.ratelimitBackoff, DataCategory.error);
5353
sut.recordLostEvent(
54-
Outcome.ratelimitBackoff, RateLimitCategory.transaction);
54+
DiscardReason.ratelimitBackoff, DataCategory.transaction);
5555

5656
final clientReport = sut.flush();
5757

5858
final first = clientReport?.discardedEvents
59-
.firstWhere((event) => event.category == RateLimitCategory.error);
59+
.firstWhere((event) => event.category == DataCategory.error);
6060

61-
final second = clientReport?.discardedEvents.firstWhere(
62-
(event) => event.category == RateLimitCategory.transaction);
61+
final second = clientReport?.discardedEvents
62+
.firstWhere((event) => event.category == DataCategory.transaction);
6363

64-
expect(first?.reason, Outcome.ratelimitBackoff);
65-
expect(first?.category, RateLimitCategory.error);
64+
expect(first?.reason, DiscardReason.ratelimitBackoff);
65+
expect(first?.category, DataCategory.error);
6666
expect(first?.quantity, 1);
6767

68-
expect(second?.reason, Outcome.ratelimitBackoff);
69-
expect(second?.category, RateLimitCategory.transaction);
68+
expect(second?.reason, DiscardReason.ratelimitBackoff);
69+
expect(second?.category, DataCategory.transaction);
7070
expect(second?.quantity, 1);
7171
});
7272

7373
test('calling flush multiple times returns null', () {
7474
final sut = fixture.getSut();
7575

76-
sut.recordLostEvent(Outcome.ratelimitBackoff, RateLimitCategory.error);
76+
sut.recordLostEvent(DiscardReason.ratelimitBackoff, DataCategory.error);
7777

7878
sut.flush();
7979
final clientReport = sut.flush();

0 commit comments

Comments
 (0)