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())
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")
}

View File

@@ -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.

View File

@@ -5,6 +5,7 @@
// Please see LICENSE files in the repository root for full details.
//
import Foundation
import MatrixRustSDK
@MainActor
@@ -16,37 +17,49 @@ enum Target: String {
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 {
return
}
do {
switch self {
case .mainApp:
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
traceLogPacks: traceLogPacks,
currentTarget: rawValue,
filePrefix: nil)
try? initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
filePrefix: nil,
sentryURL: sentryURL)
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)
filePrefix: rawValue,
sentryURL: sentryURL)
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)
filePrefix: rawValue,
sentryURL: sentryURL)
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)
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)

View File

@@ -23,7 +23,10 @@ enum Tracing {
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 {
"\(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

View File

@@ -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) #########################################")

View File

@@ -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"

View File

@@ -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)

View File

@@ -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)