fix(apple): disable false-positive "App hang" reports (#9568)

As recommended by the Sentry team [0], "App hang" tracking should be
disabled before calling into certain system APIs like showing alerts to
prevent false-positives.

[0]: https://github.com/getsentry/sentry-cocoa/issues/3472
This commit is contained in:
Thomas Eizinger
2025-06-19 00:44:03 +02:00
committed by GitHub
parent bb46c59f1d
commit 47befe37f4
6 changed files with 25 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
import FirezoneKit
import SwiftUI
import Sentry
@main
struct FirezoneApp: App {
@@ -105,6 +106,8 @@ struct FirezoneApp: App {
alert.addButton(withTitle: "Open System Preferences")
alert.addButton(withTitle: "OK")
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
let response = alert.runModal()
if response == .alertFirstButtonReturn {

View File

@@ -6,6 +6,7 @@
// A thin wrapper around UserDefaults for user and admin managed app configuration.
import Foundation
import Sentry
#if os(macOS)
import ServiceManagement
@@ -142,12 +143,17 @@ public class Configuration: ObservableObject {
// so this feature only enabled for macOS 13 and higher given the tiny Firezone installbase for macOS 12.
func updateAppService() async throws {
if #available(macOS 13.0, *) {
if !startOnLogin, SMAppService.mainApp.status == .enabled {
// Getting the status initially appears to be blocking sometimes
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
let status = SMAppService.mainApp.status
if !startOnLogin, status == .enabled {
try await SMAppService.mainApp.unregister()
return
}
if startOnLogin, SMAppService.mainApp.status != .enabled {
if startOnLogin, status != .enabled {
try SMAppService.mainApp.register()
}
}

View File

@@ -6,6 +6,7 @@
import Foundation
import UserNotifications
import Sentry
#if os(macOS)
import AppKit
@@ -106,7 +107,10 @@ public class SessionNotification: NSObject {
NSApp.activate(ignoringOtherApps: true)
await withCheckedContinuation { continuation in
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
let response = alert.runModal()
if response == NSApplication.ModalResponse.alertFirstButtonReturn {
Log.log("\(#function): 'Sign In' clicked in notification")
signInHandler()

View File

@@ -7,6 +7,7 @@
import Combine
import SwiftUI
import Sentry
#if os(macOS)
import SystemExtensions
@@ -167,6 +168,8 @@ struct GrantVPNView: View {
alert.messageText = "Permission required."
alert.informativeText =
"Firezone requires permission to install VPN configurations. Without it, all functionality will be disabled."
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
_ = alert.runModal()
} else {
throw error

View File

@@ -12,6 +12,7 @@ import Foundation
import NetworkExtension
import OSLog
import SwiftUI
import Sentry
#if os(macOS)
@MainActor
@@ -748,6 +749,8 @@ import SwiftUI
let alert = NSAlert()
alert.messageText =
"Firezone requires permission to install VPN configurations. Without it, all functionality will be disabled."
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
_ = alert.runModal()
} else {
throw error

View File

@@ -9,6 +9,7 @@
import SystemExtensions
import AppKit
import NetworkExtension
import Sentry
protocol UserFriendlyError {
func userMessage() -> String?
@@ -205,6 +206,9 @@
alert.messageText = "An error occurred."
alert.informativeText = message
alert.alertStyle = .critical
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
alert.runModal()
}
}