Skip to content

Commit 40acb74

Browse files
committed
Setup the new RustSDK sentry integration
1 parent 4bcdf58 commit 40acb74

File tree

11 files changed

+67
-40
lines changed

11 files changed

+67
-40
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8708,7 +8708,7 @@
87088708
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
87098709
requirement = {
87108710
kind = exactVersion;
8711-
version = 25.05.21;
8711+
version = 25.05.23;
87128712
};
87138713
};
87148714
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {

ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElementX/Sources/Application/AppCoordinator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
7272

7373
let appSettings = appHooks.appSettingsHook.configure(AppSettings())
7474

75-
Target.mainApp.configure(logLevel: appSettings.logLevel, traceLogPacks: appSettings.traceLogPacks)
75+
Target.mainApp.configure(logLevel: appSettings.logLevel,
76+
traceLogPacks: appSettings.traceLogPacks,
77+
sentryURL: appSettings.bugReportSentryURL)
7678

7779
let appName = InfoPlistReader.main.bundleDisplayName
7880
let appVersion = InfoPlistReader.main.bundleShortVersionString

ElementX/Sources/Application/TargetConfiguration.swift

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Please see LICENSE files in the repository root for full details.
66
//
77

8+
import Foundation
89
import MatrixRustSDK
910

1011
@MainActor
@@ -16,38 +17,50 @@ enum Target: String {
1617

1718
private static var isConfigured = false
1819

19-
func configure(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>) {
20+
func configure(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>, sentryURL: URL?) {
2021
guard !Self.isConfigured else {
2122
return
2223
}
2324

24-
switch self {
25-
case .mainApp:
26-
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
27-
traceLogPacks: traceLogPacks,
28-
currentTarget: rawValue,
29-
filePrefix: nil)
30-
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
31-
case .nse:
32-
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
33-
traceLogPacks: traceLogPacks,
34-
currentTarget: rawValue,
35-
filePrefix: rawValue)
36-
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
37-
case .shareExtension:
38-
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
39-
traceLogPacks: traceLogPacks,
40-
currentTarget: rawValue,
41-
filePrefix: rawValue)
42-
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
43-
case .tests:
44-
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
45-
traceLogPacks: traceLogPacks,
46-
currentTarget: rawValue,
47-
filePrefix: rawValue)
48-
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
25+
do {
26+
switch self {
27+
case .mainApp:
28+
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
29+
traceLogPacks: traceLogPacks,
30+
currentTarget: rawValue,
31+
filePrefix: nil,
32+
sentryURL: sentryURL)
33+
try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
34+
case .nse:
35+
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
36+
traceLogPacks: traceLogPacks,
37+
currentTarget: rawValue,
38+
filePrefix: rawValue,
39+
sentryURL: sentryURL)
40+
try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
41+
case .shareExtension:
42+
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
43+
traceLogPacks: traceLogPacks,
44+
currentTarget: rawValue,
45+
filePrefix: rawValue,
46+
sentryURL: sentryURL)
47+
try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
48+
case .tests:
49+
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
50+
traceLogPacks: traceLogPacks,
51+
currentTarget: rawValue,
52+
filePrefix: rawValue,
53+
sentryURL: sentryURL)
54+
try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
55+
}
56+
} catch {
57+
fatalError("Failed configuring target \(self) with error: \(error)")
4958
}
5059

60+
// Setup sentry above but disable it by default. It will be started
61+
// later together with the analytics service if the user consents.
62+
enableSentryLogging(enabled: false)
63+
5164
MXLog.configure(currentTarget: rawValue)
5265

5366
Self.isConfigured = true

ElementX/Sources/Other/Logging/Tracing.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ enum Tracing {
2323

2424
static let fileExtension = "log"
2525

26-
static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>, currentTarget: String, filePrefix: String?) -> TracingConfiguration {
26+
static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>,
27+
currentTarget: String,
28+
filePrefix: String?,
29+
sentryURL: URL?) -> TracingConfiguration {
2730
let fileName = if let filePrefix {
2831
"\(Tracing.filePrefix)-\(filePrefix)"
2932
} else {
@@ -45,7 +48,8 @@ enum Tracing {
4548
writeToFiles: .init(path: logsDirectory.path(percentEncoded: false),
4649
filePrefix: fileName,
4750
fileSuffix: fileExtension,
48-
maxFiles: maxFiles))
51+
maxFiles: maxFiles),
52+
sentryDsn: sentryURL?.absoluteString)
4953
}
5054

5155
/// A list of all log file URLs, sorted chronologically. This is only public for testing purposes, within

ElementX/Sources/Services/Analytics/AnalyticsService.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import AnalyticsEvents
99
import Combine
10+
import MatrixRustSDK
1011
import PostHog
1112

1213
/// A class responsible for managing a variety of analytics clients
@@ -59,6 +60,8 @@ class AnalyticsService {
5960
// The order is important here. PostHog ignores the reset if stopped.
6061
reset()
6162
client.stop()
63+
64+
enableSentryLogging(enabled: false)
6265

6366
MXLog.info("Stopped.")
6467
}
@@ -68,6 +71,8 @@ class AnalyticsService {
6871
guard isEnabled, !client.isRunning, let configuration = appSettings.analyticsConfiguration else { return }
6972

7073
client.start(analyticsConfiguration: configuration)
74+
75+
enableSentryLogging(enabled: true)
7176

7277
// Sanity check in case something went wrong.
7378
guard client.isRunning else { return }

NSE/Sources/NotificationServiceExtension.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
6464
}
6565

6666
Task {
67-
await Target.nse.configure(logLevel: settings.logLevel, traceLogPacks: settings.traceLogPacks)
67+
await Target.nse.configure(logLevel: settings.logLevel,
68+
traceLogPacks: settings.traceLogPacks,
69+
sentryURL: nil)
6870

6971
MXLog.info("\(tag) #########################################")
7072

Secrets/Secrets.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
enum Secrets {
2-
static let sentryDSN: String? = "https://sentry.localhost"
2+
static let sentryDSN: String? = "https://username@sentry.localhost/project_id"
33
static let postHogHost: String? = "https://posthog.localhost"
44
static let postHogAPIKey: String? = "your_key"
55
static let rageshakeServerURL: String? = "https://rageshake.localhost"
66
static let mapLibreAPIKey: String? = "your_key"
7-
8-
}
7+
}

ShareExtension/Sources/ShareExtensionViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class ShareExtensionViewController: UIViewController {
1515
override func viewDidLoad() {
1616
super.viewDidLoad()
1717

18-
Target.shareExtension.configure(logLevel: appSettings.logLevel, traceLogPacks: appSettings.traceLogPacks)
18+
Target.shareExtension.configure(logLevel: appSettings.logLevel,
19+
traceLogPacks: appSettings.traceLogPacks,
20+
sentryURL: nil)
1921

2022
addChild(hostingController)
2123
view.addMatchedSubview(hostingController.view)

UnitTests/Sources/LoggingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LoggingTests: XCTestCase {
2222
let target = "tests"
2323
XCTAssertTrue(Tracing.logFiles.isEmpty)
2424

25-
await Target.tests.configure(logLevel: .info, traceLogPacks: [])
25+
await Target.tests.configure(logLevel: .info, traceLogPacks: [], sentryURL: nil)
2626

2727
// There is something weird with Rust logging where the file writing handle doesn't
2828
// notice that the file it is writing to was deleted, so we can't run these checks
@@ -174,7 +174,7 @@ class LoggingTests: XCTestCase {
174174
contentType: nil))
175175

176176
// When logging that value
177-
await Target.tests.configure(logLevel: .info, traceLogPacks: [])
177+
await Target.tests.configure(logLevel: .info, traceLogPacks: [], sentryURL: nil)
178178

179179
MXLog.info(textMessage)
180180
MXLog.info(noticeMessage)

project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ packages:
6565
# Element/Matrix dependencies
6666
MatrixRustSDK:
6767
url: https://github.com/element-hq/matrix-rust-components-swift
68-
exactVersion: 25.05.21
68+
exactVersion: 25.05.23
6969
# path: ../matrix-rust-sdk
7070
Compound:
7171
url: https://github.com/element-hq/compound-ios

0 commit comments

Comments
 (0)