Fix log and analytics bugs

This commit is contained in:
problematicconsumer
2023-10-03 21:12:14 +03:30
parent ba071643ce
commit 8f15022443
16 changed files with 86 additions and 57 deletions

View File

@@ -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(),

View 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,
};
}

View File

@@ -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';