-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added log observer * Updated flutter error logging * updated main * Updated & Refactored some initialization logic * Updated docs * Style updates * updated error message * Updated docs * Added no op tracking manager * Reworked error reporter * Format
- Loading branch information
1 parent
aa37ff2
commit 293948e
Showing
18 changed files
with
413 additions
and
491 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,13 +1,3 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:sizzle_starter/src/core/utils/logger.dart'; | ||
import 'package:sizzle_starter/src/feature/initialization/logic/app_runner.dart'; | ||
|
||
void main() { | ||
final logger = DeveloperLogger(); | ||
|
||
runZonedGuarded( | ||
() => AppRunner(logger).initializeAndRun(), | ||
logger.logZoneError, | ||
); | ||
} | ||
void main() => AppRunner.startup(); |
20 changes: 10 additions & 10 deletions
20
lib/src/core/constant/config.dart → ...src/core/constant/application_config.dart
This file contains 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 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 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 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 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,78 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:sizzle_starter/src/core/utils/logger/logger.dart'; | ||
|
||
/// {@template error_reporter} | ||
/// An interface for reporting errors. | ||
/// | ||
/// Implementations should report errors to a service like Sentry/Crashlytics. | ||
/// {@endtemplate} | ||
abstract interface class ErrorReporter { | ||
/// Returns `true` if the error reporting service is initialized | ||
/// and ready to report errors. | ||
/// | ||
/// If this returns `false`, the error reporting service should not be used. | ||
bool get isInitialized; | ||
|
||
/// Initializes the error reporting service. | ||
Future<void> initialize(); | ||
|
||
/// Closes the error reporting service. | ||
Future<void> close(); | ||
|
||
/// Capture an exception to be reported. | ||
/// | ||
/// The [throwable] is the exception that was thrown. | ||
/// The [stackTrace] is the stack trace associated with the exception. | ||
Future<void> captureException({ | ||
required Object throwable, | ||
StackTrace? stackTrace, | ||
}); | ||
} | ||
|
||
/// {@template error_reporter_log_observer} | ||
/// An observer that reports logs to the error reporter if it is active. | ||
/// {@endtemplate} | ||
final class ErrorReporterLogObserver extends LogObserver { | ||
/// {@macro error_reporter_log_observer} | ||
const ErrorReporterLogObserver(this._errorReporter); | ||
|
||
/// Error reporter used to report errors. | ||
final ErrorReporter _errorReporter; | ||
|
||
@override | ||
void onLog(LogMessage logMessage) { | ||
// If the error reporter is not initialized, do nothing | ||
if (!_errorReporter.isInitialized) return; | ||
|
||
// If the log level is error or higher, report the error | ||
if (logMessage.level.index >= LogLevel.error.index) { | ||
_errorReporter.captureException( | ||
throwable: logMessage.error ?? ReportedMessageException(logMessage.message), | ||
stackTrace: logMessage.stackTrace ?? StackTrace.current, | ||
); | ||
} | ||
} | ||
} | ||
|
||
/// An exception used for error logs without an exception, only a message. | ||
class ReportedMessageException implements Exception { | ||
/// Constructs an instance of [ReportedMessageException]. | ||
const ReportedMessageException(this.message); | ||
|
||
/// The message that was reported. | ||
final String message; | ||
|
||
@override | ||
String toString() => message; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other is ReportedMessageException && other.message == message; | ||
} | ||
|
||
@override | ||
int get hashCode => message.hashCode; | ||
} |
49 changes: 49 additions & 0 deletions
49
lib/src/core/utils/error_reporter/sentry_error_reporter.dart
This file contains 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,49 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:sentry_flutter/sentry_flutter.dart'; | ||
import 'package:sizzle_starter/src/core/utils/error_reporter/error_reporter.dart'; | ||
|
||
/// {@template sentry_error_reporter} | ||
/// An implementation of [ErrorReporter] that reports errors to Sentry. | ||
/// {@endtemplate} | ||
class SentryErrorReporter implements ErrorReporter { | ||
/// {@macro sentry_error_reporter} | ||
const SentryErrorReporter({ | ||
required this.sentryDsn, | ||
required this.environment, | ||
}); | ||
|
||
/// The Sentry DSN. | ||
final String sentryDsn; | ||
|
||
/// The Sentry environment. | ||
final String environment; | ||
|
||
@override | ||
bool get isInitialized => Sentry.isEnabled; | ||
|
||
@override | ||
Future<void> initialize() async { | ||
await SentryFlutter.init( | ||
(options) => options | ||
..dsn = sentryDsn | ||
..tracesSampleRate = 0.10 | ||
..debug = kDebugMode | ||
..environment = environment | ||
..anrEnabled = true | ||
..sendDefaultPii = true, | ||
); | ||
} | ||
|
||
@override | ||
Future<void> close() async { | ||
await Sentry.close(); | ||
} | ||
|
||
@override | ||
Future<void> captureException({ | ||
required Object throwable, | ||
StackTrace? stackTrace, | ||
}) async { | ||
await Sentry.captureException(throwable, stackTrace: stackTrace); | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
lib/src/core/utils/error_tracking_manager/error_tracking_manager.dart
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
lib/src/core/utils/error_tracking_manager/sentry_tracking_manager.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.