Fix log and analytics bugs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:hiddify/utils/sentry_utils.dart';
|
||||
import 'package:loggy/loggy.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
@@ -33,6 +34,8 @@ class SentryLoggyIntegration extends LoggyPrinter
|
||||
|
||||
@override
|
||||
Future<void> onLog(LogRecord record) async {
|
||||
if (!canSendEvent(record.error)) return;
|
||||
|
||||
if (_shouldLog(record.level, _minEventLevel)) {
|
||||
await _hub.captureEvent(
|
||||
record.toEvent(),
|
||||
|
||||
21
lib/utils/sentry_utils.dart
Normal file
21
lib/utils/sentry_utils.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:hiddify/domain/failures.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
FutureOr<SentryEvent?> sentryBeforeSend(SentryEvent event, {Hint? hint}) {
|
||||
if (canSendEvent(event.throwable)) return event;
|
||||
return null;
|
||||
}
|
||||
|
||||
bool canSendEvent(dynamic throwable) {
|
||||
return switch (throwable) {
|
||||
UnexpectedFailure(:final error) => canSendEvent(error),
|
||||
DioException _ => false,
|
||||
SocketException _ => false,
|
||||
ExpectedException _ => false,
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@ export 'placeholders.dart';
|
||||
export 'platform_utils.dart';
|
||||
export 'sentry_loggy_integration.dart';
|
||||
export 'sentry_riverpod_observer.dart';
|
||||
export 'sentry_utils.dart';
|
||||
export 'text_utils.dart';
|
||||
export 'uri_utils.dart';
|
||||
export 'validators.dart';
|
||||
|
||||
Reference in New Issue
Block a user