fatal method
Marks an error as fatal and records it to Sentry.
entry - The complete log entry containing fatal error message, level, timestamp, context, stackTrace, and event.
Implementation
@override
Future<void> fatal(LogEntry entry) async {
try {
if (shouldLog(event: entry.event)) {
// Merge context from entry.context and event.parameters
final context = <String, dynamic>{};
if (entry.context != null) {
context.addAll(entry.context!);
}
if (entry.event?.parameters != null) {
context.addAll(entry.event!.parameters!);
}
// Add context to Sentry using structured contexts
if (context.isNotEmpty) {
Sentry.configureScope((scope) {
scope.setContexts('log_context', context);
});
}
Sentry.captureException(entry.message, stackTrace: entry.stackTrace);
}
} catch (e, stack) {
developer.log(
'Error during fatal error handling in Sentry Strategy',
name: 'SentryLogStrategy',
error: e,
stackTrace: stack,
);
}
}