Skip to content

Commit

Permalink
Clean up sentry + adjust app hanging detection
Browse files Browse the repository at this point in the history
Lower app hanging error level and increase timeout for x86
  • Loading branch information
pakerwreah committed Aug 15, 2024
1 parent 27c6372 commit 0e27b3a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 19 deletions.
22 changes: 19 additions & 3 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
34B5A09325B0CE6F00F7F7ED /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B5A09225B0CE6F00F7F7ED /* SettingsViewController.swift */; };
34B5A09725B0F8A500F7F7ED /* NSButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B5A09625B0F8A500F7F7ED /* NSButton.swift */; };
34B5A09D25B118EC00F7F7ED /* CalendarPickerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B5A09C25B118EC00F7F7ED /* CalendarPickerViewModel.swift */; };
34C1D41E2C6E567100295E5E /* ProcessInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C1D41D2C6E567100295E5E /* ProcessInfo.swift */; };
34C1D4212C6E632F00295E5E /* Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C1D4202C6E632F00295E5E /* Sentry.swift */; };
34C2CF9125C2070400FC2CFF /* EventViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C2CF9025C2070400FC2CFF /* EventViewModelTests.swift */; };
34C4599C25DEFFDA00561C29 /* BuildConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C4599B25DEFFDA00561C29 /* BuildConfig.m */; };
34C459A425DF030000561C29 /* BuildConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C459A325DF030000561C29 /* BuildConfig.swift */; };
Expand Down Expand Up @@ -314,6 +316,8 @@
34B5A09225B0CE6F00F7F7ED /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
34B5A09625B0F8A500F7F7ED /* NSButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSButton.swift; sourceTree = "<group>"; };
34B5A09C25B118EC00F7F7ED /* CalendarPickerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarPickerViewModel.swift; sourceTree = "<group>"; };
34C1D41D2C6E567100295E5E /* ProcessInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcessInfo.swift; sourceTree = "<group>"; };
34C1D4202C6E632F00295E5E /* Sentry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sentry.swift; sourceTree = "<group>"; };
34C2CF9025C2070400FC2CFF /* EventViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventViewModelTests.swift; sourceTree = "<group>"; };
34C4599A25DEFFDA00561C29 /* Calendr-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Calendr-Bridging-Header.h"; sourceTree = "<group>"; };
34C4599B25DEFFDA00561C29 /* BuildConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BuildConfig.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -528,6 +532,7 @@
347E6D4125AA28FA009A6716 /* Providers */,
34D5601D25F197F1007F5C81 /* Schedulers */,
34F88A8425B0CDA3005C9BA6 /* Settings */,
34C1D41F2C6E631700295E5E /* Utils */,
);
path = Calendr;
sourceTree = "<group>";
Expand Down Expand Up @@ -613,11 +618,11 @@
347D0FE6259544B4002451EC /* NSView+Layout.swift */,
3477F3E325FD5285008EA888 /* NSView+Rx.swift */,
3477F3E725FD52AA008EA888 /* NSViewController+Rx.swift */,
34C1D41D2C6E567100295E5E /* ProcessInfo.swift */,
34F2F7352BB739A500666507 /* Range.swift */,
34305BCA25992A4E00AB381D /* Rx+Helpers.swift */,
34D55FE225F06669007F5C81 /* Sequence.swift */,
34651F5925E2F08500518C5A /* String.swift */,
3438AEED2C6192A9002BE3E1 /* XCTest.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -728,6 +733,15 @@
path = Events;
sourceTree = "<group>";
};
34C1D41F2C6E631700295E5E /* Utils */ = {
isa = PBXGroup;
children = (
34C1D4202C6E632F00295E5E /* Sentry.swift */,
3438AEED2C6192A9002BE3E1 /* XCTest.swift */,
);
path = Utils;
sourceTree = "<group>";
};
34CC383425B64432006CBD99 /* MenuBar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -992,6 +1006,7 @@
3421DA122693E70E00056837 /* MockPopoverSettings.swift in Sources */,
3477F3E825FD52AA008EA888 /* NSViewController+Rx.swift in Sources */,
34B5A09325B0CE6F00F7F7ED /* SettingsViewController.swift in Sources */,
34C1D41E2C6E567100295E5E /* ProcessInfo.swift in Sources */,
3421930827999FB7002BCD36 /* TimeZone+Factory.swift in Sources */,
3417A40A2A702643005C77E4 /* StatusItemIconFactory.swift in Sources */,
34EDE71B2AC46515007C5854 /* Error.swift in Sources */,
Expand Down Expand Up @@ -1065,6 +1080,7 @@
34F4C47B2A6C54A900397C80 /* StatusItemPreview.swift in Sources */,
346C5A4A2BC2D6F60007106C /* NextEventPreview.swift in Sources */,
34B2C59E279FFF0600B52BF3 /* NSGestureRecognizer+Rx.swift in Sources */,
34C1D4212C6E632F00295E5E /* Sentry.swift in Sources */,
34E004A725B61D5200241419 /* StatusItemViewModel.swift in Sources */,
34D19FC0262299D300B2732C /* NSEdgeInsets.swift in Sources */,
34702168259E761100827AE7 /* Calendar.swift in Sources */,
Expand Down Expand Up @@ -1336,7 +1352,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 32973VC289;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -1364,7 +1380,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 32973VC289;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down
28 changes: 28 additions & 0 deletions Calendr/Extensions/ProcessInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ProcessInfo.swift
// Calendr
//
// Created by Paker on 15/08/2024.
//

import Foundation

extension ProcessInfo {

enum Architecture: String {
case x86_64
case arm64
}

var architecture: Architecture? { _architecture }
}

/// Equivalent to running `uname -m` in shell
private var _architecture: ProcessInfo.Architecture? = {
var sysinfo = utsname()
let result = uname(&sysinfo)
guard result == EXIT_SUCCESS else { return nil }
let data = Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN))
guard let identifier = String(bytes: data, encoding: .ascii) else { return nil }
return .init(rawValue: identifier.trimmingCharacters(in: .controlCharacters))
}()
18 changes: 2 additions & 16 deletions Calendr/Main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Cocoa
import Sentry

class AppDelegate: NSObject, NSApplicationDelegate {

Expand All @@ -22,15 +21,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return
}
#else
var transaction: Span?
defer { transaction?.finish() }

if let dsn = Environment.SENTRY_DSN {
SentrySDK.start { options in
options.dsn = dsn
}
transaction = SentrySDK.startTransaction(transactionContext: .init(name: "app", operation: "launch", sampled: .yes))
}
let appLaunch = startSentry()
defer { appLaunch?.finish() }
#endif

let userDefaults = UserDefaults.standard
Expand All @@ -55,9 +47,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
setUpResignFocus()
}
}

func blocking<T>(operation: () -> T) -> T {
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
return operation()
}
40 changes: 40 additions & 0 deletions Calendr/Utils/Sentry.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Sentry.swift
// Calendr
//
// Created by Paker on 15/08/2024.
//

import Sentry

func startSentry() -> Span? {
guard let dsn = Environment.SENTRY_DSN else { return nil }
SentrySDK.start { configureSentry(dsn, $0) }
return SentrySDK.startTransaction(transactionContext: .appLaunch)
}

private func configureSentry(_ dsn: String, _ options: Options) {
options.dsn = dsn

if ProcessInfo.processInfo.architecture == .x86_64 {
options.appHangTimeoutInterval += 1
}

options.beforeSend = { event in
if (event.exceptions?.first?.type == "App Hanging") {
event.level = .debug
}
return event
}
}

/// Prevents reporting false hangings for known blocking operations (i.e. context menus)
func blocking<T>(operation: () -> T) -> T {
SentrySDK.pauseAppHangTracking()
defer { SentrySDK.resumeAppHangTracking() }
return operation()
}

extension TransactionContext {
static let appLaunch = TransactionContext(name: "app", operation: "launch", sampled: .yes)
}
File renamed without changes.

0 comments on commit 0e27b3a

Please sign in to comment.