diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 412c51ece..c78e531eb 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -72,7 +72,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg let appSettings = appHooks.appSettingsHook.configure(AppSettings()) - Target.mainApp.configure(logLevel: appSettings.logLevel, traceLogPacks: appSettings.traceLogPacks) + Target.mainApp.configure(logLevel: appSettings.logLevel, + traceLogPacks: appSettings.traceLogPacks, + sentryURL: appSettings.bugReportSDKSentryURL) let appName = InfoPlistReader.main.bundleDisplayName let appVersion = InfoPlistReader.main.bundleShortVersionString @@ -906,6 +908,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg SentrySDK.start(options: options) + enableSentryLogging(enabled: appSettings.analyticsConsentState == .optedIn) + MXLog.info("SentrySDK started") } diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index a1cf4e19c..915ae3277 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -253,6 +253,7 @@ final class AppSettings { let bugReportServiceBaseURL: URL? = Secrets.rageshakeServerURL.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping let bugReportSentryURL: URL? = Secrets.sentryDSN.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping + let bugReportSDKSentryURL: URL? = Secrets.sentrySDKDSN.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping /// The name allocated by the bug report server private(set) var bugReportApplicationID = "element-x-ios" /// The maximum size of the upload request. Default value is just below CloudFlare's max request size. diff --git a/ElementX/Sources/Application/TargetConfiguration.swift b/ElementX/Sources/Application/TargetConfiguration.swift index 9c1fc0afa..e1a5498dc 100644 --- a/ElementX/Sources/Application/TargetConfiguration.swift +++ b/ElementX/Sources/Application/TargetConfiguration.swift @@ -5,6 +5,7 @@ // Please see LICENSE files in the repository root for full details. // +import Foundation import MatrixRustSDK @MainActor @@ -16,38 +17,50 @@ enum Target: String { private static var isConfigured = false - func configure(logLevel: LogLevel, traceLogPacks: Set) { + func configure(logLevel: LogLevel, traceLogPacks: Set, sentryURL: URL?) { guard !Self.isConfigured else { return } - switch self { - case .mainApp: - let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, - traceLogPacks: traceLogPacks, - currentTarget: rawValue, - filePrefix: nil) - try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false) - case .nse: - let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, - traceLogPacks: traceLogPacks, - currentTarget: rawValue, - filePrefix: rawValue) - try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true) - case .shareExtension: - let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, - traceLogPacks: traceLogPacks, - currentTarget: rawValue, - filePrefix: rawValue) - try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true) - case .tests: - let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, - traceLogPacks: traceLogPacks, - currentTarget: rawValue, - filePrefix: rawValue) - try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false) + do { + switch self { + case .mainApp: + let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, + traceLogPacks: traceLogPacks, + currentTarget: rawValue, + filePrefix: nil, + sentryURL: sentryURL) + try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false) + case .nse: + let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, + traceLogPacks: traceLogPacks, + currentTarget: rawValue, + filePrefix: rawValue, + sentryURL: sentryURL) + try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true) + case .shareExtension: + let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, + traceLogPacks: traceLogPacks, + currentTarget: rawValue, + filePrefix: rawValue, + sentryURL: sentryURL) + try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true) + case .tests: + let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, + traceLogPacks: traceLogPacks, + currentTarget: rawValue, + filePrefix: rawValue, + sentryURL: sentryURL) + try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false) + } + } catch { + fatalError("Failed configuring target \(self) with error: \(error)") } + // Setup sentry above but disable it by default. It will be started + // later together with the analytics service if the user consents. + enableSentryLogging(enabled: false) + MXLog.configure(currentTarget: rawValue) Self.isConfigured = true diff --git a/ElementX/Sources/Other/Logging/Tracing.swift b/ElementX/Sources/Other/Logging/Tracing.swift index ebc293dc5..63a41d15b 100644 --- a/ElementX/Sources/Other/Logging/Tracing.swift +++ b/ElementX/Sources/Other/Logging/Tracing.swift @@ -23,7 +23,10 @@ enum Tracing { static let fileExtension = "log" - static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set, currentTarget: String, filePrefix: String?) -> TracingConfiguration { + static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set, + currentTarget: String, + filePrefix: String?, + sentryURL: URL?) -> TracingConfiguration { let fileName = if let filePrefix { "\(Tracing.filePrefix)-\(filePrefix)" } else { @@ -46,7 +49,7 @@ enum Tracing { filePrefix: fileName, fileSuffix: fileExtension, maxFiles: maxFiles), - sentryDsn: nil) + sentryDsn: sentryURL?.absoluteString) } /// A list of all log file URLs, sorted chronologically. This is only public for testing purposes, within diff --git a/Enterprise b/Enterprise index e2f589c18..4db9bad5b 160000 --- a/Enterprise +++ b/Enterprise @@ -1 +1 @@ -Subproject commit e2f589c1886666774ab688b8140a924a038379bc +Subproject commit 4db9bad5b4da976fe89f9c4ceb2ec8c37658f0b2 diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index fe052e8e6..c92d3d5f6 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -64,7 +64,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension { } Task { - await Target.nse.configure(logLevel: settings.logLevel, traceLogPacks: settings.traceLogPacks) + await Target.nse.configure(logLevel: settings.logLevel, + traceLogPacks: settings.traceLogPacks, + sentryURL: nil) MXLog.info("\(tag) #########################################") diff --git a/Secrets/Secrets.swift b/Secrets/Secrets.swift index f1d802762..c6c5dece1 100644 --- a/Secrets/Secrets.swift +++ b/Secrets/Secrets.swift @@ -1,5 +1,6 @@ enum Secrets { - static let sentryDSN: String? = "https://sentry.localhost" + static let sentryDSN: String? = "https://username@sentry.localhost/project_id" + static let sentrySDKDSN: String? = "https://username@sentry.localhost/project_id" static let postHogHost: String? = "https://posthog.localhost" static let postHogAPIKey: String? = "your_key" static let rageshakeServerURL: String? = "https://rageshake.localhost" diff --git a/ShareExtension/Sources/ShareExtensionViewController.swift b/ShareExtension/Sources/ShareExtensionViewController.swift index 24de9afc4..39d5b3890 100644 --- a/ShareExtension/Sources/ShareExtensionViewController.swift +++ b/ShareExtension/Sources/ShareExtensionViewController.swift @@ -15,7 +15,9 @@ class ShareExtensionViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - Target.shareExtension.configure(logLevel: appSettings.logLevel, traceLogPacks: appSettings.traceLogPacks) + Target.shareExtension.configure(logLevel: appSettings.logLevel, + traceLogPacks: appSettings.traceLogPacks, + sentryURL: nil) addChild(hostingController) view.addMatchedSubview(hostingController.view) diff --git a/UnitTests/Sources/LoggingTests.swift b/UnitTests/Sources/LoggingTests.swift index 2e55053e7..2803e45d0 100644 --- a/UnitTests/Sources/LoggingTests.swift +++ b/UnitTests/Sources/LoggingTests.swift @@ -22,7 +22,7 @@ class LoggingTests: XCTestCase { let target = "tests" XCTAssertTrue(Tracing.logFiles.isEmpty) - await Target.tests.configure(logLevel: .info, traceLogPacks: []) + await Target.tests.configure(logLevel: .info, traceLogPacks: [], sentryURL: nil) // There is something weird with Rust logging where the file writing handle doesn't // notice that the file it is writing to was deleted, so we can't run these checks @@ -174,7 +174,7 @@ class LoggingTests: XCTestCase { contentType: nil)) // When logging that value - await Target.tests.configure(logLevel: .info, traceLogPacks: []) + await Target.tests.configure(logLevel: .info, traceLogPacks: [], sentryURL: nil) MXLog.info(textMessage) MXLog.info(noticeMessage)