firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

🐛 [firebase_crashlytics] Errors reported with recordError have custom keys mixed up #10556

Open jhenriquedsilva opened 1 year ago

jhenriquedsilva commented 1 year ago

Bug report

Describe the bug

When errors are reported with recordError close to each other, their custom keys get mixed up.

                  WidgetsFlutterBinding.ensureInitialized();
                  await Firebase.initializeApp();
                  FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
                  PlatformDispatcher.instance.onError = (final error, final stack) {
                      FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
                      return true;
                   };
                  final firebase = FirebaseCrashlytics.instance;

                  await firebase.setCustomKey('log category', 'error');
                  await firebase.setCustomKey('log level', 1);
                  await firebase.setCustomKey('logger name', 'LoginPresenter');
                  await firebase.recordError(null, StackTrace.current, reason: 'Error without exception');

                  await firebase.setCustomKey('log category', 'error');
                  await firebase.setCustomKey('log level', 1);
                  await firebase.setCustomKey('logger name', 'SignupPresenter');
                  await firebase.recordError(Exception('Error'), StackTrace.current, reason: null);

                  await firebase.setCustomKey('log category', 'warn');
                  await firebase.setCustomKey('log level', 2);
                  await firebase.setCustomKey('logger name', 'LoginState');
                  await firebase.recordError(null, StackTrace.current, reason: 'Warn without exception');

                  await firebase.setCustomKey('log category', 'warn');
                  await firebase.setCustomKey('log level', 2);
                  await firebase.setCustomKey('logger name', 'SignupState');
                  await firebase.recordError(Exception('Exception'), StackTrace.current, reason: null);

Steps to reproduce

Steps to reproduce the behavior:

  1. Run the code above in main.dart file
  2. Wait till crash report is sent
  3. Check the Crashlytics console

I explicitly have set the reason to null when the error is related to SignupState, but the reason appears as 'Warn without exception' in the console

Screenshot 2023-03-02 at 16 15 26

In the first call to recordError, I have set the Exception argument to null and the reason to Error without exception. In the second call to recordError, the exception is passed and the reason is set to null. However, the report is exactly the same. That is, the logger_name, flutter_error_exception, and flutter_error_reason keys values have not changed:

Screenshot 2023-03-02 at 16 21 27

Expected behavior

Each report should correspond to the keys that are set before calling recordError


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [!] Flutter (Channel stable, 3.7.1, on macOS 13.1 22C65 darwin-arm64, locale en-BR) ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/2.16.2/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/jose.silva/development/sdks/flutter. Consider adding /Users/jose.silva/development/sdks/flutter/bin to the front of your path. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] IntelliJ IDEA Community Edition (version 2022.2.4) [✓] VS Code (version 1.75.1) [✓] Connected device (3 available) HTTP Host availability check is taking a long time...[✓] HTTP Host Availability ! Doctor found issues in 1 category. ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.19.1 Flutter SDK 3.7.1 client_mobile 0.1.0+2 dependencies: - carousel_slider 4.1.1 [flutter] - commons_base 1.3.2 [flutter] - commons_conversion 1.3.2 [flutter] - commons_time 1.3.2 [flutter commons_base commons_conversion time_machine] - commons_validation 1.3.2 [flutter commons_base] - dio 4.0.6 [http_parser path] - easy_localization 3.0.1 [flutter shared_preferences intl args path easy_logger flutter_localizations] - firebase_analytics 10.1.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 2.7.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.0.15 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 14.2.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_bloc 8.1.1 [flutter bloc provider] - flutter_secure_storage 5.1.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - intl 0.17.0 [clock path] - json_annotation 4.7.0 [meta] - lib_widgets_flutter 2.4.0 [flutter intl] - logging 1.0.2 - path 1.8.2 - sqflite 2.0.3+1 [flutter sqflite_common path] - timezone 0.9.1 [path] dev dependencies: - bloc_test 9.1.0 [bloc diff_match_patch meta mocktail test] - build_runner 2.2.0 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - json_serializable 6.5.4 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper] - test 1.22.0 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core] transitive dependencies: - _fe_analyzer_shared 47.0.0 [meta] - _flutterfire_internals 1.0.16 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 4.7.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - args 2.3.2 - async 2.10.0 [collection meta] - bloc 8.1.0 [meta] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.3.1 [analyzer async convert crypto glob logging meta path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.10 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.7 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.4.3 [built_collection collection fixnum meta] - characters 1.2.1 - checked_yaml 2.0.2 [json_annotation source_span yaml] - clock 1.1.1 - code_builder 4.4.0 [built_collection built_value collection matcher meta] - collection 1.17.0 - convert 3.1.1 [typed_data] - coverage 1.6.2 [args logging package_config path source_maps stack_trace vm_service] - crypto 3.0.2 [typed_data] - dart_style 2.2.4 [analyzer args path pub_semver source_span] - diff_match_patch 0.4.1 - easy_logger 0.0.2 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.3.17 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+8 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.5.3 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.2.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.3.15 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.2.10 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.11 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.1.0 - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_secure_storage_linux 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.1 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 1.1.3 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 2.1.3 [async path] - glob 2.1.1 [async collection file path string_scanner] - graphs 2.2.0 [collection] - http_multi_server 3.2.1 [async] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - io 1.0.4 [meta path string_scanner] - js 0.6.5 [meta] - lints 2.0.1 - matcher 0.12.13 [meta stack_trace] - material_color_utilities 0.2.0 - meta 1.8.0 - mime 1.0.4 - mocktail 0.3.0 [collection matcher test] - nested 1.0.0 [flutter] - node_preamble 2.0.1 - package_config 2.1.0 [path] - path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.5 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - provider 6.0.5 [collection flutter nested] - pub_semver 2.1.3 [collection meta] - pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml] - shared_preferences 2.0.17 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.0.15 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.1.3 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.3 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.1.0 [flutter plugin_platform_interface] - shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.3 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.4.0 [async collection http_parser path stack_trace stream_channel] - shelf_packages_handler 3.0.1 [path shelf shelf_static] - shelf_static 1.1.1 [convert http_parser mime path shelf] - shelf_web_socket 1.0.3 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.2.6 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.3 [analyzer collection source_gen] - source_map_stack_trace 2.1.1 [path source_maps stack_trace] - source_maps 0.10.11 [source_span] - source_span 1.9.1 [collection path term_glyph] - sqflite_common 2.4.2+2 [synchronized path meta] - stack_trace 1.11.0 [path] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - synchronized 3.0.1 - term_glyph 1.2.1 - test_api 0.4.16 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - test_core 0.4.20 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api] - time_machine 0.9.17 [meta collection] - timing 1.0.1 [json_annotation] - typed_data 1.3.1 [collection] - vector_math 2.1.4 - vm_service 9.4.0 - watcher 1.0.2 [async path] - web_socket_channel 2.3.0 [async crypto stream_channel] - webkit_inspection_protocol 1.2.0 [logging] - win32 3.1.3 [ffi] - xdg_directories 0.2.0+3 [meta path process] - yaml 3.1.1 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

Thanks for the report. Was able to replicate using code sample provided.

An old similar issue for reference: https://github.com/firebase/flutterfire/issues/3421

niklaesAtMonta commented 1 year ago

@darshankawar any news on this? :)

Lyokone commented 11 months ago

Hi @jhenriquedsilva, I think it may be happening because custom keys are global and associated with an exception only when crashes are sent to crashlytics. Could you try to add await firebase.sendUnsentReports(); after each exception recorded. Anyway, it seems directly related to the native SDK since we are just a thin wrapper around these functions.

google-oss-bot commented 11 months ago

Hey @jhenriquedsilva. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

jhenriquedsilva commented 10 months ago

@Lyokone I have tried to do what you have recommended, but the call to await firebase.sendUnsentReports(); does not solve the problem. I think it is not related to the custom keys, but rather to the reason. When the reason is set to null, the library completely ignores that and uses the last non-null reason of the previous calls. Therefore, the reason is not being cleaned correctly(I think that's the bug).

image (8)

image (10)

russellwheatley commented 10 months ago

This behaviour is not a result of FlutterFire, but the way it is processed by the underlying native SDK. Interestingly, there has been movement by the Firebase android SDK to allow custom keys for specific exceptions which you can follow here: https://github.com/firebase/firebase-android-sdk/issues/3551