-
-
Notifications
You must be signed in to change notification settings - Fork 257
Feat: Client Report Recorder #809
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
54048ea
Introduce client report recorder
cd0dadf
Rename class
10c8bb5
use ClockProvider typedef
75ab5bb
use non-growable list
659f5b2
rename classes
93c8cea
Replace rate limit naming from default case prefix
4576880
rename file, introduce remaining enum cases
9c40c3b
Feat: Client Report Envelope Item (#810)
denrase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'discarded_event.dart'; | ||
import '../utils.dart'; | ||
|
||
@internal | ||
class ClientReport { | ||
ClientReport(this.timestamp, this.discardedEvents); | ||
|
||
final DateTime? timestamp; | ||
final List<DiscardedEvent> discardedEvents; | ||
|
||
Map<String, dynamic> toJson() { | ||
final json = <String, dynamic>{}; | ||
|
||
if (timestamp != null) { | ||
json['timestamp'] = formatDateAsIso8601WithMillisPrecision(timestamp!); | ||
} | ||
|
||
final eventsJson = discardedEvents | ||
.map((e) => e.toJson()) | ||
.where((e) => e.isNotEmpty) | ||
.toList(growable: false); | ||
if (eventsJson.isNotEmpty) { | ||
json['discarded_events'] = eventsJson; | ||
} | ||
|
||
return json; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../sentry_options.dart'; | ||
import 'client_report.dart'; | ||
import 'discarded_event.dart'; | ||
import 'discard_reason.dart'; | ||
import '../transport/data_category.dart'; | ||
|
||
@internal | ||
class ClientReportRecorder { | ||
ClientReportRecorder(this._clock); | ||
|
||
final ClockProvider _clock; | ||
final Map<_QuantityKey, int> _quantities = {}; | ||
|
||
void recordLostEvent( | ||
final DiscardReason reason, final DataCategory category) { | ||
final key = _QuantityKey(reason, category); | ||
var current = _quantities[key] ?? 0; | ||
_quantities[key] = current + 1; | ||
} | ||
|
||
ClientReport? flush() { | ||
if (_quantities.isEmpty) { | ||
return null; | ||
} | ||
|
||
final events = _quantities.keys.map((key) { | ||
final quantity = _quantities[key] ?? 0; | ||
return DiscardedEvent(key.reason, key.category, quantity); | ||
}).toList(growable: false); | ||
|
||
_quantities.clear(); | ||
|
||
return ClientReport(_clock(), events); | ||
} | ||
} | ||
|
||
class _QuantityKey { | ||
_QuantityKey(this.reason, this.category); | ||
|
||
final DiscardReason reason; | ||
final DataCategory category; | ||
|
||
@override | ||
int get hashCode => Object.hash(reason, category); | ||
|
||
@override | ||
bool operator ==(dynamic other) { | ||
return other is _QuantityKey && | ||
other.reason == reason && | ||
other.category == category; | ||
} | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
/// A reason that defines why events were lost, see | ||
/// https://develop.sentry.dev/sdk/client-reports/#envelope-item-payload. | ||
@internal | ||
enum DiscardReason { | ||
beforeSend, | ||
eventProcessor, | ||
sampleRate, | ||
networkError, | ||
queueOverflow, | ||
cacheOverflow, | ||
rateLimitBackoff, | ||
} | ||
|
||
extension OutcomeExtension on DiscardReason { | ||
String toStringValue() { | ||
switch (this) { | ||
case DiscardReason.beforeSend: | ||
return 'before_send'; | ||
case DiscardReason.eventProcessor: | ||
return 'event_processor'; | ||
case DiscardReason.sampleRate: | ||
return 'sample_rate'; | ||
case DiscardReason.networkError: | ||
return 'network_error'; | ||
case DiscardReason.queueOverflow: | ||
return 'queue_overflow'; | ||
case DiscardReason.cacheOverflow: | ||
return 'cache_overflow'; | ||
case DiscardReason.rateLimitBackoff: | ||
return 'ratelimit_backoff'; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'discard_reason.dart'; | ||
import '../transport/data_category.dart'; | ||
|
||
@internal | ||
class DiscardedEvent { | ||
DiscardedEvent(this.reason, this.category, this.quantity); | ||
|
||
final DiscardReason reason; | ||
final DataCategory category; | ||
final int quantity; | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'reason': reason.toStringValue(), | ||
'category': category.toStringValue(), | ||
'quantity': quantity, | ||
}; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
dart/lib/src/client_reports/noop_client_report_recorder.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../transport/data_category.dart'; | ||
import 'client_report.dart'; | ||
import 'client_report_recorder.dart'; | ||
import 'discard_reason.dart'; | ||
|
||
@internal | ||
class NoOpClientReportRecorder implements ClientReportRecorder { | ||
const NoOpClientReportRecorder(); | ||
|
||
@override | ||
ClientReport? flush() { | ||
return null; | ||
} | ||
|
||
@override | ||
void recordLostEvent(DiscardReason reason, DataCategory category) {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.