Setup the new RustSDK sentry integration

This commit is contained in:
Stefan Ceriu
2025-05-23 11:42:26 +03:00
committed by Stefan Ceriu
parent e84af69e00
commit 3dd98adeeb
9 changed files with 61 additions and 35 deletions

View File

@@ -72,7 +72,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
let appSettings = appHooks.appSettingsHook.configure(AppSettings()) 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 appName = InfoPlistReader.main.bundleDisplayName
let appVersion = InfoPlistReader.main.bundleShortVersionString let appVersion = InfoPlistReader.main.bundleShortVersionString
@@ -906,6 +908,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
SentrySDK.start(options: options) SentrySDK.start(options: options)
enableSentryLogging(enabled: appSettings.analyticsConsentState == .optedIn)
MXLog.info("SentrySDK started") MXLog.info("SentrySDK started")
} }

View File

@@ -253,6 +253,7 @@ final class AppSettings {
let bugReportServiceBaseURL: URL? = Secrets.rageshakeServerURL.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping 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 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 /// The name allocated by the bug report server
private(set) var bugReportApplicationID = "element-x-ios" private(set) var bugReportApplicationID = "element-x-ios"
/// The maximum size of the upload request. Default value is just below CloudFlare's max request size. /// The maximum size of the upload request. Default value is just below CloudFlare's max request size.

View File

@@ -5,6 +5,7 @@
// Please see LICENSE files in the repository root for full details. // Please see LICENSE files in the repository root for full details.
// //
import Foundation
import MatrixRustSDK import MatrixRustSDK
@MainActor @MainActor
@@ -16,38 +17,50 @@ enum Target: String {
private static var isConfigured = false private static var isConfigured = false
func configure(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>) { func configure(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>, sentryURL: URL?) {
guard !Self.isConfigured else { guard !Self.isConfigured else {
return return
} }
switch self { do {
case .mainApp: switch self {
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, case .mainApp:
traceLogPacks: traceLogPacks, let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
currentTarget: rawValue, traceLogPacks: traceLogPacks,
filePrefix: nil) currentTarget: rawValue,
try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false) filePrefix: nil,
case .nse: sentryURL: sentryURL)
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
traceLogPacks: traceLogPacks, case .nse:
currentTarget: rawValue, let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
filePrefix: rawValue) traceLogPacks: traceLogPacks,
try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true) currentTarget: rawValue,
case .shareExtension: filePrefix: rawValue,
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, sentryURL: sentryURL)
traceLogPacks: traceLogPacks, try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
currentTarget: rawValue, case .shareExtension:
filePrefix: rawValue) let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true) traceLogPacks: traceLogPacks,
case .tests: currentTarget: rawValue,
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, filePrefix: rawValue,
traceLogPacks: traceLogPacks, sentryURL: sentryURL)
currentTarget: rawValue, try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
filePrefix: rawValue) case .tests:
try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false) 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) MXLog.configure(currentTarget: rawValue)
Self.isConfigured = true Self.isConfigured = true

View File

@@ -23,7 +23,10 @@ enum Tracing {
static let fileExtension = "log" static let fileExtension = "log"
static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>, currentTarget: String, filePrefix: String?) -> TracingConfiguration { static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>,
currentTarget: String,
filePrefix: String?,
sentryURL: URL?) -> TracingConfiguration {
let fileName = if let filePrefix { let fileName = if let filePrefix {
"\(Tracing.filePrefix)-\(filePrefix)" "\(Tracing.filePrefix)-\(filePrefix)"
} else { } else {
@@ -46,7 +49,7 @@ enum Tracing {
filePrefix: fileName, filePrefix: fileName,
fileSuffix: fileExtension, fileSuffix: fileExtension,
maxFiles: maxFiles), maxFiles: maxFiles),
sentryDsn: nil) sentryDsn: sentryURL?.absoluteString)
} }
/// A list of all log file URLs, sorted chronologically. This is only public for testing purposes, within /// A list of all log file URLs, sorted chronologically. This is only public for testing purposes, within

View File

@@ -64,7 +64,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
} }
Task { 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) #########################################") MXLog.info("\(tag) #########################################")

View File

@@ -1,5 +1,6 @@
enum Secrets { 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 postHogHost: String? = "https://posthog.localhost"
static let postHogAPIKey: String? = "your_key" static let postHogAPIKey: String? = "your_key"
static let rageshakeServerURL: String? = "https://rageshake.localhost" static let rageshakeServerURL: String? = "https://rageshake.localhost"

View File

@@ -15,7 +15,9 @@ class ShareExtensionViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.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) addChild(hostingController)
view.addMatchedSubview(hostingController.view) view.addMatchedSubview(hostingController.view)

View File

@@ -22,7 +22,7 @@ class LoggingTests: XCTestCase {
let target = "tests" let target = "tests"
XCTAssertTrue(Tracing.logFiles.isEmpty) 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 // 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 // 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)) contentType: nil))
// When logging that value // 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(textMessage)
MXLog.info(noticeMessage) MXLog.info(noticeMessage)