-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
952 additions
and
182 deletions.
There are no files selected for viewing
This file contains 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 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 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 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; | ||
} | ||
} |
This file contains 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 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 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 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 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 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.