mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Log Sentry crash events through MXLog
Mirror crashes into our own logs via Sentry's beforeSend hook so the full crash log ships with rageshakes. Adds a SentryEvent extension to extract the formatted crash log from the event.
This commit is contained in:
@@ -1019,6 +1019,14 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
bugReportService.lastCrashEventID = event.eventId.sentryIdString
|
||||
}
|
||||
|
||||
// Mirror every crash into our own logs (which ship with rageshakes) before it's sent to Sentry.
|
||||
options.beforeSend = { event in
|
||||
if let crashLog = event.crashLog {
|
||||
MXLog.error("Sentry crash event \(event.eventId.sentryIdString):\n\(crashLog)")
|
||||
}
|
||||
return event
|
||||
}
|
||||
|
||||
// Any ongoing transactions will no longer be valid after calling SentrySDK.start so lets
|
||||
// remove them and start over, otherwise the app will crash if finishTransaction is used.
|
||||
analytics.signpost.resetTransactions()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import MatrixRustSDK
|
||||
import Sentry
|
||||
import UIKit
|
||||
|
||||
extension Event {
|
||||
/// A human readable crash log matching the format used by the legacy app.
|
||||
/// `nil` for non-crash events (handled errors, transactions, etc.).
|
||||
var crashLog: String? {
|
||||
guard let exceptions,
|
||||
exceptions.contains(where: { $0.mechanism?.handled?.boolValue == false }) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let reason = exceptions.map { "\($0.type ?? "Unknown"): \($0.value ?? "")" }.joined(separator: "\n")
|
||||
let infoPlist = InfoPlistReader.main
|
||||
let device = UIDevice.current
|
||||
|
||||
return """
|
||||
\(reason)
|
||||
Application: \(infoPlist.bundleExecutable) (\(infoPlist.bundleIdentifier))
|
||||
Application version: \(infoPlist.bundleShortVersionString) (\(infoPlist.bundleVersion))
|
||||
Matrix SDK version: \(sdkGitSha())
|
||||
\(device.model) \(device.systemVersion)
|
||||
"""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user