mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Setup Sentry instrumentation on top of the existing Signposter (#2985)
* Move Sentry setup outside of the BugReportService * Setup Sentry SwiftUI tracing for the homeScreen and roomScreen roots * Setup Sentry instrumentation on top of the existing Signposter * Various tweaks
This commit is contained in:
@@ -19,6 +19,7 @@ import BackgroundTasks
|
||||
import Combine
|
||||
import Intents
|
||||
import MatrixRustSDK
|
||||
import Sentry
|
||||
import SwiftUI
|
||||
import Version
|
||||
|
||||
@@ -96,17 +97,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
|
||||
Self.setupServiceLocator(appSettings: appSettings)
|
||||
|
||||
ServiceLocator.shared.analytics.isRunningPublisher
|
||||
.removeDuplicates()
|
||||
.sink { isRunning in
|
||||
if isRunning {
|
||||
ServiceLocator.shared.bugReportService.start()
|
||||
} else {
|
||||
ServiceLocator.shared.bugReportService.stop()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
ServiceLocator.shared.analytics.startIfEnabled()
|
||||
|
||||
stateMachine = AppCoordinatorStateMachine()
|
||||
@@ -150,6 +140,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
|
||||
registerBackgroundAppRefresh()
|
||||
|
||||
ServiceLocator.shared.analytics.isRunningPublisher
|
||||
.removeDuplicates()
|
||||
.sink { [weak self] isRunning in
|
||||
if isRunning {
|
||||
self?.setupSentry()
|
||||
} else {
|
||||
self?.teardownSentry()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
elementCallService.actions
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] action in
|
||||
@@ -344,7 +345,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
ServiceLocator.shared.register(appSettings: appSettings)
|
||||
ServiceLocator.shared.register(networkMonitor: NetworkMonitor())
|
||||
ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: appSettings.bugReportServiceBaseURL,
|
||||
sentryURL: appSettings.bugReportSentryURL,
|
||||
applicationId: appSettings.bugReportApplicationId,
|
||||
sdkGitSHA: sdkGitSha(),
|
||||
maxUploadSize: appSettings.bugReportMaxUploadSize))
|
||||
@@ -733,6 +733,62 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
}
|
||||
}
|
||||
|
||||
private func setupSentry() {
|
||||
SentrySDK.start { [weak self] options in
|
||||
#if DEBUG
|
||||
options.enabled = false
|
||||
#endif
|
||||
|
||||
options.dsn = self?.appSettings.bugReportSentryURL.absoluteString
|
||||
|
||||
// Sentry swizzling shows up quite often as the heaviest stack trace when profiling
|
||||
// We don't need any of the features it powers (see docs)
|
||||
options.enableSwizzling = false
|
||||
|
||||
// WatchdogTermination is currently the top issue but we've had zero complaints
|
||||
// so it might very well just all be false positives
|
||||
options.enableWatchdogTerminationTracking = false
|
||||
|
||||
// Disabled as it seems to report a lot of false positives
|
||||
options.enableAppHangTracking = false
|
||||
|
||||
// Most of the network requests are made Rust side, this is useless
|
||||
options.enableNetworkBreadcrumbs = false
|
||||
|
||||
// Doesn't seem to work at all well with SwiftUI
|
||||
options.enableAutoBreadcrumbTracking = false
|
||||
|
||||
// Experimental. Stitches stack traces of asynchronous code together
|
||||
options.swiftAsyncStacktraces = true
|
||||
|
||||
// Uniform sample rate: 1.0 captures 100% of transactions
|
||||
// In Production you will probably want a smaller number such as 0.5 for 50%
|
||||
if AppSettings.isDevelopmentBuild {
|
||||
options.sampleRate = 1.0
|
||||
options.tracesSampleRate = 1.0
|
||||
options.profilesSampleRate = 1.0
|
||||
} else {
|
||||
options.sampleRate = 0.5
|
||||
options.tracesSampleRate = 0.5
|
||||
options.profilesSampleRate = 0.5
|
||||
}
|
||||
|
||||
// This callback is only executed once during the entire run of the program to avoid
|
||||
// multiple callbacks if there are multiple crash events to send (see method documentation)
|
||||
options.onCrashedLastRun = { event in
|
||||
MXLog.error("Sentry detected a crash in the previous run: \(event.eventId.sentryIdString)")
|
||||
ServiceLocator.shared.bugReportService.lastCrashEventID = event.eventId.sentryIdString
|
||||
}
|
||||
|
||||
MXLog.info("SentrySDK started")
|
||||
}
|
||||
}
|
||||
|
||||
private func teardownSentry() {
|
||||
SentrySDK.close()
|
||||
MXLog.info("SentrySDK stopped")
|
||||
}
|
||||
|
||||
// MARK: Toasts and loading indicators
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(AppCoordinator.self)-Loading"
|
||||
@@ -762,7 +818,10 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
private func startSync() {
|
||||
guard let userSession else { return }
|
||||
|
||||
ServiceLocator.shared.analytics.signpost.beginFirstSync()
|
||||
// FIXME: replace this with `user_id_server_name` from https://github.com/matrix-org/matrix-rust-sdk/pull/3617
|
||||
let serverName = String(userSession.clientProxy.userID.split(separator: ":").last ?? "Unknown")
|
||||
|
||||
ServiceLocator.shared.analytics.signpost.beginFirstSync(serverName: serverName)
|
||||
userSession.clientProxy.startSync()
|
||||
|
||||
guard clientProxyObserver == nil else {
|
||||
|
||||
Reference in New Issue
Block a user