Skip to content

Commit b5fc518

Browse files
committed
add dev option to bypass sample rate for sentry events
1 parent ae2bf88 commit b5fc518

4 files changed

Lines changed: 41 additions & 12 deletions

File tree

lib/Backend/utilities/sentry.dart

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:package_info_plus/package_info_plus.dart';
99
import 'package:sentry_flutter/sentry_flutter.dart';
1010
import 'package:sentry_logging/sentry_logging.dart';
1111
import 'package:tail_app/Backend/utilities/hive.dart';
12+
import 'package:tail_app/Backend/utilities/settings.dart';
1213
import 'package:universal_io/io.dart';
1314

1415
import '../../constants.dart';
@@ -18,10 +19,13 @@ import '../logging_wrappers.dart';
1819
Random _random = Random();
1920

2021
Future<String> getSentryEnvironment() async {
21-
if (!kReleaseMode) {
22-
return 'debug';
23-
}
22+
final ISentrySpan? span = Sentry.getSpan()?.startChild(
23+
'Sentry.getEnvironment',
24+
);
2425
try {
26+
if (!kReleaseMode) {
27+
return 'debug';
28+
}
2529
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
2630
PackageInfo packageInfo = await PackageInfo.fromPlatform();
2731
String referral = packageInfo.installerStore ?? "";
@@ -47,6 +51,9 @@ Future<String> getSentryEnvironment() async {
4751
}
4852
} catch (e, s) {
4953
_logger.severe("Failed to determine environment for sentry", e, s);
54+
span?.status = SpanStatus.internalError();
55+
} finally {
56+
span?.finish();
5057
}
5158
return 'production';
5259
}
@@ -56,13 +63,14 @@ FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async {
5663
if (isHiveReady) {
5764
DynamicConfigInfo dynamicConfigInfo = await getDynamicConfigInfo();
5865
reportingEnabled =
59-
HiveProxy.getOrDefault(
60-
settings,
61-
allowErrorReporting,
62-
defaultValue: allowErrorReportingDefault,
63-
) &&
64-
dynamicConfigInfo.featureFlags.enableErrorReporting &&
65-
_random.nextDouble() <= dynamicConfigInfo.sentryConfig.sampleRate;
66+
disableSentryFiltering ||
67+
(HiveProxy.getOrDefault(
68+
settings,
69+
allowErrorReporting,
70+
defaultValue: allowErrorReportingDefault,
71+
) &&
72+
dynamicConfigInfo.featureFlags.enableErrorReporting &&
73+
_random.nextDouble() <= dynamicConfigInfo.sentryConfig.sampleRate);
6674
}
6775
if (reportingEnabled) {
6876
return event;
@@ -77,8 +85,9 @@ FutureOr<SentryTransaction?> beforeSendTransaction(
7785
) async {
7886
if (isHiveReady) {
7987
DynamicConfigInfo dynamicConfigInfo = await getDynamicConfigInfo();
80-
if (_random.nextDouble() <=
81-
dynamicConfigInfo.sentryConfig.tracesSampleRate) {
88+
if (disableSentryFiltering ||
89+
_random.nextDouble() <=
90+
dynamicConfigInfo.sentryConfig.tracesSampleRate) {
8291
return transaction;
8392
} else {
8493
return null;

lib/Backend/utilities/settings.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ bool get isDeveloperEnabled => HiveProxy.getOrDefault(
66
showDebugging,
77
defaultValue: showDebuggingDefault,
88
);
9+
10+
bool get disableSentryFiltering =>
11+
isDeveloperEnabled &&
12+
HiveProxy.getOrDefault(settings, sendAllSentryEvents, defaultValue: false);

lib/Frontend/pages/developer/developer_menu.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ class _DeveloperMenuState extends State<DeveloperMenu> {
6464
throw Exception('Sentry Test');
6565
},
6666
),
67+
ListTile(
68+
title: const Text("Send all sentry events"),
69+
trailing: Switch(
70+
value: HiveProxy.getOrDefault(
71+
settings,
72+
sendAllSentryEvents,
73+
defaultValue: false,
74+
),
75+
onChanged: (bool value) async {
76+
setState(() {
77+
HiveProxy.put(settings, sendAllSentryEvents, value);
78+
});
79+
},
80+
),
81+
),
6782
ListTile(
6883
title: const Text("Theme Inspector"),
6984
leading: const Icon(Icons.color_lens),

lib/constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const String triggerActionCooldown = 'triggerActionCooldown';
3131
const String gearConnectRetryAttempts = 'gearConnectRetryAttempts';
3232
const String selectedLocale = 'selectedLocale';
3333
const String uwuTextEnabled = 'uwuTextEnabled';
34+
const String sendAllSentryEvents = "sendAllSentryEvents";
3435

3536
// Settings Default value
3637
const bool kitsuneModeDefault = false;

0 commit comments

Comments
 (0)