Simplify how we setup Sentry to make sure it's configured before any spans get created - they don't get reported otherwise

This commit is contained in:
Stefan Ceriu
2024-07-17 14:47:51 +03:00
committed by Stefan Ceriu
parent 95d53f1edf
commit 65dd6f3496
4 changed files with 73 additions and 81 deletions
@@ -38,19 +38,11 @@ class AnalyticsService {
/// A signpost client for performance testing the app. This client doesn't respect the
/// `isRunning` state or behave any differently when `start`/`reset` are called.
let signpost = Signposter(isDevelopmentBuild: AppSettings.isDevelopmentBuild)
let signpost = Signposter()
/// Whether or not the object is enabled and sending events to the server.
private let isRunningSubject: CurrentValueSubject<Bool, Never> = .init(false)
var isRunningPublisher: CurrentValuePublisher<Bool, Never> {
isRunningSubject.asCurrentValuePublisher()
}
init(client: AnalyticsClientProtocol, appSettings: AppSettings) {
self.client = client
self.appSettings = appSettings
isRunningSubject.send(client.isRunning)
}
/// Whether to show the user the analytics opt in prompt.
@@ -76,21 +68,19 @@ class AnalyticsService {
// The order is important here. PostHog ignores the reset if stopped.
reset()
client.stop()
isRunningSubject.send(false)
MXLog.info("Stopped.")
}
/// Starts the analytics client if the user has opted in, otherwise does nothing.
func startIfEnabled() {
guard isEnabled, !isRunningPublisher.value else { return }
guard isEnabled, !client.isRunning else { return }
client.start(analyticsConfiguration: appSettings.analyticsConfiguration)
// Sanity check in case something went wrong.
guard client.isRunning else { return }
isRunningSubject.send(true)
MXLog.info("Started.")
}
@@ -35,7 +35,6 @@ class Signposter {
static let appStarted = "AppStarted"
static let homeserver = "homeserver"
static let isDevelopmentBuild = "isDevelopmentBuild"
}
static let subsystem = "ElementX"
@@ -43,9 +42,8 @@ class Signposter {
private var appStartupSpan: Span
init(isDevelopmentBuild: Bool) {
init() {
appStartupSpan = SentrySDK.startTransaction(name: Name.appStartup, operation: Name.appStarted)
appStartupSpan.setData(value: isDevelopmentBuild, key: Name.isDevelopmentBuild)
}
// MARK: - Login
@@ -55,7 +53,7 @@ class Signposter {
func beginLogin() {
loginState = signposter.beginInterval(Name.login)
loginSpan = appStartupSpan.startChild(operation: "\(Name.login)")
loginSpan = appStartupSpan.startChild(operation: "\(Name.login)", description: "\(Name.login)")
}
func endLogin() {
@@ -80,7 +78,7 @@ class Signposter {
appStartupSpan.setTag(value: serverName, key: Name.homeserver)
firstSyncState = signposter.beginInterval(Name.firstSync)
firstSyncSpan = appStartupSpan.startChild(operation: "\(Name.firstSync)")
firstSyncSpan = appStartupSpan.startChild(operation: "\(Name.firstSync)", description: "\(Name.firstSync)")
}
func endFirstSync() {
@@ -100,7 +98,7 @@ class Signposter {
func beginFirstRooms() {
firstRoomsState = signposter.beginInterval(Name.firstRooms)
firstRoomsSpan = appStartupSpan.startChild(operation: "\(Name.firstRooms)")
firstRoomsSpan = appStartupSpan.startChild(operation: "\(Name.firstRooms)", description: "\(Name.firstRooms)")
}
func endFirstRooms() {