-
Notifications
You must be signed in to change notification settings - Fork 0
feat(observability): add Firebase Performance Monitoring with opt-in toggle #35
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
10 commits
Select commit
Hold shift + click to select a range
88e8fc4
feat(observability): add firebase_performance dependency
using-system 6cdbe6d
feat(observability): enable crash reporting by default
using-system 7d169b5
feat(observability): add PerformancePreferenceStorage
using-system afb5a7b
feat(l10n): add performance monitoring l10n keys
using-system bcf1324
feat(observability): add performance preference providers
using-system af3a552
feat(observability): initialize performance monitoring at startup
using-system 3953747
feat(observability): add PerformanceToggleTile widget
using-system 83ba528
docs: add firebase_performance to SPEC.md
using-system bd0800f
feat(observability): add performance toggle to observability section
using-system 79d7c20
fix(observability): address PR review comments
using-system 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
26 changes: 26 additions & 0 deletions
26
lib/features/observability/data/performance_preference_storage.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,26 @@ | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:shared_preferences/shared_preferences.dart'; | ||
|
|
||
| class PerformancePreferenceStorage { | ||
| PerformancePreferenceStorage(this._prefs); | ||
|
|
||
| static const _key = 'observability_performance_enabled'; | ||
|
|
||
| final SharedPreferences _prefs; | ||
|
|
||
| bool read() { | ||
| try { | ||
| return _prefs.getBool(_key) ?? true; | ||
| } catch (error, stack) { | ||
| debugPrint('Failed to read performance preference: $error\n$stack'); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| Future<void> write(bool enabled) async { | ||
| final didWrite = await _prefs.setBool(_key, enabled); | ||
| if (!didWrite) { | ||
| throw Exception('Failed to persist performance preference.'); | ||
| } | ||
| } | ||
| } |
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
40 changes: 40 additions & 0 deletions
40
lib/features/observability/presentation/performance_toggle_tile.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,40 @@ | ||
| import 'package:cookmate/l10n/app_localizations.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
|
||
| import '../providers.dart'; | ||
|
|
||
| class PerformanceToggleTile extends ConsumerWidget { | ||
| const PerformanceToggleTile({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final l10n = AppLocalizations.of(context); | ||
| final performanceAsync = ref.watch(performancePreferenceProvider); | ||
| final enabled = performanceAsync.valueOrNull ?? true; | ||
|
|
||
| return SwitchListTile( | ||
| secondary: const Icon(Icons.speed), | ||
| title: Text(l10n.settingsPerformanceTitle), | ||
| subtitle: Text(l10n.settingsPerformanceDescription), | ||
| value: enabled, | ||
| onChanged: performanceAsync.isLoading ? null : (value) async { | ||
| try { | ||
| await ref | ||
| .read(performancePreferenceProvider.notifier) | ||
| .setPreference(value); | ||
| } catch (error, stack) { | ||
| debugPrint('Failed to change performance: $error\n$stack'); | ||
| if (context.mounted) { | ||
| ScaffoldMessenger.of(context).showSnackBar( | ||
| SnackBar( | ||
| content: | ||
| Text(l10n.settingsPerformanceChangeFailureSnackbar), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| }, | ||
| ); | ||
| } | ||
| } |
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
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
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
39 changes: 39 additions & 0 deletions
39
test/features/observability/data/performance_preference_storage_test.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,39 @@ | ||
| import 'package:cookmate/features/observability/data/performance_preference_storage.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:shared_preferences/shared_preferences.dart'; | ||
|
|
||
| void main() { | ||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| late PerformancePreferenceStorage storage; | ||
|
|
||
| setUp(() async { | ||
| SharedPreferences.setMockInitialValues(<String, Object>{}); | ||
| final prefs = await SharedPreferences.getInstance(); | ||
| storage = PerformancePreferenceStorage(prefs); | ||
| }); | ||
|
|
||
| test('read returns true when nothing is stored', () { | ||
| expect(storage.read(), true); | ||
| }); | ||
|
|
||
| test('write then read returns the written value', () async { | ||
| await storage.write(false); | ||
| expect(storage.read(), false); | ||
| }); | ||
|
|
||
| test('write overwrites a previous value', () async { | ||
| await storage.write(false); | ||
| await storage.write(true); | ||
| expect(storage.read(), true); | ||
| }); | ||
|
|
||
| test('read returns true when stored value is corrupted', () async { | ||
| SharedPreferences.setMockInitialValues(<String, Object>{ | ||
| 'observability_performance_enabled': 'not_a_bool', | ||
| }); | ||
| final prefs = await SharedPreferences.getInstance(); | ||
| final s = PerformancePreferenceStorage(prefs); | ||
| expect(s.read(), true); | ||
| }); | ||
| } |
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.