Skip to content

Commit e0e5391

Browse files
chore: Remove hang tracker sdk v9 checks (#6334)
* chore: Remove hang tracker sdk v9 checks * build failure * fix on macos * fixes * fix frames tracker tests * fix enabled features buider tests * update option * fix failing test * remove outdated comment * fix tests * improve assertions for testGoToForeground_SetsIsActive * fix test --------- Co-authored-by: Philipp Hofmann <[email protected]>
1 parent ec3fc3a commit e0e5391

23 files changed

+149
-314
lines changed

Samples/SentrySampleShared/SentrySampleShared/SentrySDKOverrides.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public enum SentrySDKOverrides: String, CaseIterable {
8383

8484
public enum Performance: String, SentrySDKOverride {
8585
case disableTimeToFullDisplayTracing = "--io.sentry.performance.disable-time-to-full-display-tracing"
86-
case disableAppHangTrackingV2 = "--io.sentry.performance.disable-app-hang-tracking-v2"
8786
case disableSessionTracking = "--io.sentry.performance.disable-automatic-session-tracking"
8887
case disableFileIOTracing = "--io.sentry.performance.disable-file-io-tracing"
8988
case disableUIVCTracing = "--io.sentry.performance.disable-uiviewcontroller-tracing"
@@ -316,7 +315,7 @@ extension SentrySDKOverrides.Other {
316315
extension SentrySDKOverrides.Performance {
317316
public var overrideType: OverrideType {
318317
switch self {
319-
case .disableTimeToFullDisplayTracing, .disableAppHangTrackingV2, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return .boolean
318+
case .disableTimeToFullDisplayTracing, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return .boolean
320319
case .sessionTrackingIntervalMillis: return .string
321320
}
322321
}
@@ -403,7 +402,7 @@ extension SentrySDKOverrides.Other {
403402
extension SentrySDKOverrides.Performance {
404403
public var ignoresDisableEverything: Bool {
405404
switch self {
406-
case .disableTimeToFullDisplayTracing, .disableAppHangTrackingV2, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return false
405+
case .disableTimeToFullDisplayTracing, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return false
407406
case .sessionTrackingIntervalMillis: return true
408407
}
409408
}

Samples/SentrySampleShared/SentrySampleShared/SentrySDKWrapper.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ public struct SentrySDKWrapper {
112112
options.screenshot.maskAllText = !SentrySDKOverrides.Screenshot.disableMaskAllText.boolValue
113113

114114
options.attachViewHierarchy = !SentrySDKOverrides.Other.disableAttachViewHierarchy.boolValue
115-
#if !SDK_V9
116-
options.enableAppHangTrackingV2 = !SentrySDKOverrides.Performance.disableAppHangTrackingV2.boolValue
117-
#endif // SDK_V9
118115
#endif // !os(macOS) && !os(watchOS)
119116

120117
// disable during benchmarks because we run CPU for 15 seconds at full throttle which can trigger ANRs

Samples/iOS-Swift/iOS-Swift-UITests/ViewLifecycleUITests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ViewLifecycleUITests: BaseUITest {
1111
super.setUp()
1212
launchApp(args: [
1313
SentrySDKOverrides.Performance.disableTimeToFullDisplayTracing.rawValue,
14-
SentrySDKOverrides.Performance.disableAppHangTrackingV2.rawValue
14+
SentrySDKOverrides.Performance.disableANRTracking.rawValue
1515
])
1616
}
1717

Sources/Sentry/Public/SentryOptions.h

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -623,18 +623,11 @@ typedef void (^SentryProfilingConfigurationBlock)(SentryProfileOptions *_Nonnull
623623

624624
/**
625625
* When enabled, the SDK tracks when the application stops responding for a specific amount of
626-
* time defined by the @c appHangsTimeoutInterval option.
627-
* @note The default is @c YES
628-
* @note ANR tracking is automatically disabled if a debugger is attached.
629-
*/
630-
@property (nonatomic, assign) BOOL enableAppHangTracking;
631-
632-
#if SENTRY_UIKIT_AVAILABLE
633-
634-
# if !SDK_V9
635-
/**
636-
* AppHangTrackingV2 can differentiate between fully-blocking and non-fully blocking app hangs.
637-
* fully-blocking app hang is when the main thread is stuck completely, and the app can't render a
626+
* time defined by the @c appHangTimeoutInterval option.
627+
*
628+
* On iOS, tvOS and visionOS, the SDK can differentiate between fully-blocking and non-fully
629+
blocking app hangs.
630+
* A fully-blocking app hang is when the main thread is stuck completely, and the app can't render a
638631
* single frame. A non-fully-blocking app hang is when the app appears stuck to the user but can
639632
still
640633
* render a few frames. Fully-blocking app hangs are more actionable because the stacktrace shows
@@ -645,20 +638,18 @@ typedef void (^SentryProfilingConfigurationBlock)(SentryProfileOptions *_Nonnull
645638
*
646639
* You can use @c enableReportNonFullyBlockingAppHangs to ignore non-fully-blocking app hangs.
647640
*
648-
* @note This flag wins over enableAppHangTracking. When enabling both enableAppHangTracking and
649-
enableAppHangTrackingV2, the SDK only enables enableAppHangTrackingV2 and disables
650-
enableAppHangTracking.
641+
* @note The default is @c YES
642+
* @note App Hang tracking is automatically disabled if a debugger is attached.
651643
*/
652-
@property (nonatomic, assign) BOOL enableAppHangTrackingV2;
644+
@property (nonatomic, assign) BOOL enableAppHangTracking;
653645

654-
# endif // !SDK_V9
646+
#if SENTRY_UIKIT_AVAILABLE
655647

656648
/**
657649
* When enabled the SDK reports non-fully-blocking app hangs. A non-fully-blocking app hang is when
658-
* the app appears stuck to the user but can still render a few frames. For more information see @c
659-
* enableAppHangTrackingV2.
650+
* the app appears stuck to the user but can still render a few frames.
660651
*
661-
* @note The default is @c YES. This feature only works when @c enableAppHangTrackingV2 is enabled.
652+
* @note The default is @c YES.
662653
*/
663654
@property (nonatomic, assign) BOOL enableReportNonFullyBlockingAppHangs;
664655

Sources/Sentry/SentryANRTrackingIntegration.m

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options
4545
}
4646

4747
#if SENTRY_HAS_UIKIT
48-
# if SDK_V9
49-
BOOL isV2Enabled = YES;
50-
# else
51-
BOOL isV2Enabled = options.enableAppHangTrackingV2;
52-
# endif // SDK_V9
5348
self.tracker =
54-
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval
55-
isV2Enabled:isV2Enabled];
49+
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
5650
#else
5751
self.tracker =
5852
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
@@ -157,48 +151,29 @@ - (void)anrDetectedWithType:(enum SentryANRType)type
157151
getDebugImagesFromCacheForThreads:SENTRY_UNWRAP_NULLABLE(NSArray, event.threads)];
158152

159153
#if SENTRY_HAS_UIKIT
160-
# if SDK_V9
161-
BOOL isV2Enabled = YES;
162-
# else
163-
BOOL isV2Enabled = self.options.enableAppHangTrackingV2;
164-
# endif // SDK_V9
165-
166-
// We only measure app hang duration for V2.
167-
// For V1, we directly capture the app hang event.
168-
if (isV2Enabled) {
169-
// We only temporarily store the app hang duration info, so we can change the error message
170-
// when either sending a normal or fatal app hang event. Otherwise, we would have to rely on
171-
// string parsing to retrieve the app hang duration info from the error message.
172-
mechanism.data = @{ SentryANRMechanismDataAppHangDuration : appHangDurationInfo };
173-
174-
// We need to apply the scope now because if the app hang turns into a fatal one,
175-
// we would lose the scope. Furthermore, we want to know in which state the app was when the
176-
// app hang started.
177-
SentryScope *scope = [SentrySDKInternal currentHub].scope;
178-
SentryOptions *options = SentrySDKInternal.options;
179-
if (scope != nil && options != nil) {
180-
[scope applyToEvent:event maxBreadcrumb:options.maxBreadcrumbs];
181-
}
182-
183-
[self.fileManager storeAppHangEvent:event];
184-
} else {
185-
#endif // SENTRY_HAS_UIKIT
186-
[SentrySDK captureEvent:event];
187-
#if SENTRY_HAS_UIKIT
154+
// We only temporarily store the app hang duration info, so we can change the error message
155+
// when either sending a normal or fatal app hang event. Otherwise, we would have to rely on
156+
// string parsing to retrieve the app hang duration info from the error message.
157+
mechanism.data = @{ SentryANRMechanismDataAppHangDuration : appHangDurationInfo };
158+
159+
// We need to apply the scope now because if the app hang turns into a fatal one,
160+
// we would lose the scope. Furthermore, we want to know in which state the app was when the
161+
// app hang started.
162+
SentryScope *scope = [SentrySDKInternal currentHub].scope;
163+
SentryOptions *options = SentrySDKInternal.options;
164+
if (scope != nil && options != nil) {
165+
[scope applyToEvent:event maxBreadcrumb:options.maxBreadcrumbs];
188166
}
189-
#endif // SENTRY_UIKIT_AVAILABLE
167+
168+
[self.fileManager storeAppHangEvent:event];
169+
#else
170+
[SentrySDK captureEvent:event];
171+
#endif
190172
}
191173

192174
- (void)anrStoppedWithResult:(SentryANRStoppedResult *_Nullable)result
193175
{
194176
#if SENTRY_HAS_UIKIT
195-
// We only measure app hang duration for V2, and therefore ignore V1.
196-
# if !SDK_V9
197-
if (!self.options.enableAppHangTrackingV2) {
198-
return;
199-
}
200-
# endif // !SDK_V9
201-
202177
if (result == nil) {
203178
SENTRY_LOG_WARN(@"ANR stopped for V2 but result was nil.")
204179
return;

Sources/Sentry/SentryBaseIntegration.m

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,10 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options
7777

7878
if (integrationOptions & kIntegrationOptionEnableAppHangTracking) {
7979
#if SENTRY_HAS_UIKIT
80-
# if SDK_V9
8180
if (!options.enableAppHangTracking) {
8281
[self logWithOptionName:@"enableAppHangTracking"];
8382
return NO;
8483
}
85-
# else
86-
if (!options.enableAppHangTracking && !options.enableAppHangTrackingV2) {
87-
[self logWithOptionName:@"enableAppHangTracking && enableAppHangTrackingV2"];
88-
return NO;
89-
}
90-
# endif
9184
#else
9285
if (!options.enableAppHangTracking) {
9386
[self logWithOptionName:@"enableAppHangTracking"];
@@ -176,26 +169,20 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options
176169
}
177170
#endif
178171

179-
// The frames tracker runs when tracing is enabled or AppHangsV2. We have to use an extra option
180-
// for this.
181172
if (integrationOptions & kIntegrationOptionStartFramesTracker) {
182173

183174
#if SENTRY_HAS_UIKIT
184175
BOOL performanceDisabled
185176
= !options.enableAutoPerformanceTracing || !options.isTracingEnabled;
186-
BOOL appHangsV2Disabled = options.isAppHangTrackingV2Disabled;
187-
# if SDK_V9
188-
// The V9 watchdog tracker uses the frames tracker, so frame tracking
177+
BOOL appHangsDisabled = options.isAppHangTrackingDisabled;
178+
179+
// The watchdog tracker uses the frames tracker, so frame tracking
189180
// must be enabled if watchdog tracking is enabled.
190181
BOOL watchdogDisabled = !options.enableWatchdogTerminationTracking;
191-
# else
192-
// Before V9 this should have no effect so set it to YES
193-
BOOL watchdogDisabled = YES;
194-
# endif // SDK_V9
195-
196-
if (performanceDisabled && appHangsV2Disabled && watchdogDisabled) {
197-
if (appHangsV2Disabled) {
198-
SENTRY_LOG_DEBUG(@"Not going to enable %@ because enableAppHangTrackingV2 is "
182+
183+
if (performanceDisabled && appHangsDisabled && watchdogDisabled) {
184+
if (appHangsDisabled) {
185+
SENTRY_LOG_DEBUG(@"Not going to enable %@ because enableAppHangTracking is "
199186
@"disabled or the appHangTimeoutInterval is 0.",
200187
self.integrationName);
201188
}
@@ -206,14 +193,12 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options
206193
self.integrationName);
207194
}
208195

209-
# if SDK_V9
210196
if (watchdogDisabled) {
211197
SENTRY_LOG_DEBUG(
212198
@"Not going to enable %@ because enableWatchdogTerminationTracking "
213199
@"is disabled.",
214200
self.integrationName);
215201
}
216-
# endif // SKD_V9
217202

218203
return NO;
219204
}

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,34 +244,27 @@ - (SentryCrashSwift *)crashReporter SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
244244
- (SentryANRTracker *)getANRTracker:(NSTimeInterval)timeout
245245
SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
246246
{
247+
#if SENTRY_HAS_UIKIT
248+
SENTRY_LAZY_INIT(_anrTracker,
249+
[[SentryANRTracker alloc]
250+
initWithHelper:[[SentryANRTrackerV2 alloc]
251+
initWithTimeoutInterval:timeout
252+
crashWrapper:self.crashWrapper
253+
dispatchQueueWrapper:self.dispatchQueueWrapper
254+
threadWrapper:self.threadWrapper
255+
framesTracker:self.framesTracker]]);
256+
#else
247257
SENTRY_LAZY_INIT(_anrTracker,
248258
[[SentryANRTracker alloc]
249259
initWithHelper:[[SentryANRTrackerV1 alloc]
250260
initWithTimeoutInterval:timeout
251261
crashWrapper:self.crashWrapper
252262
dispatchQueueWrapper:self.dispatchQueueWrapper
253263
threadWrapper:self.threadWrapper]]);
264+
;
265+
#endif
254266
}
255267

256-
#if SENTRY_HAS_UIKIT
257-
- (SentryANRTracker *)getANRTracker:(NSTimeInterval)timeout
258-
isV2Enabled:(BOOL)isV2Enabled SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
259-
{
260-
if (isV2Enabled) {
261-
SENTRY_LAZY_INIT(_anrTracker,
262-
[[SentryANRTracker alloc]
263-
initWithHelper:[[SentryANRTrackerV2 alloc]
264-
initWithTimeoutInterval:timeout
265-
crashWrapper:self.crashWrapper
266-
dispatchQueueWrapper:self.dispatchQueueWrapper
267-
threadWrapper:self.threadWrapper
268-
framesTracker:self.framesTracker]]);
269-
} else {
270-
return [self getANRTracker:timeout];
271-
}
272-
}
273-
#endif // SENTRY_HAS_UIKIT
274-
275268
#if SENTRY_TARGET_REPLAY_SUPPORTED
276269
- (nonnull SentryScreenshotSource *)screenshotSource SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
277270
{

Sources/Sentry/SentryOptions.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ - (instancetype)init
101101
self.enableUserInteractionTracing = YES;
102102
self.idleTimeout = SentryTracerDefaultTimeout;
103103
self.enablePreWarmedAppStartTracing = NO;
104-
# if !SDK_V9
105-
self.enableAppHangTrackingV2 = NO;
106-
# endif // !SDK_V9
107104
self.enableReportNonFullyBlockingAppHangs = YES;
108105
#endif // SENTRY_HAS_UIKIT
109106

@@ -458,14 +455,9 @@ - (void)setEnableSpotlight:(BOOL)value
458455
}
459456

460457
#if SENTRY_HAS_UIKIT
461-
- (BOOL)isAppHangTrackingV2Disabled
458+
- (BOOL)isAppHangTrackingDisabled
462459
{
463-
# if SDK_V9
464-
BOOL isV2Enabled = self.enableAppHangTracking;
465-
# else
466-
BOOL isV2Enabled = self.enableAppHangTrackingV2;
467-
# endif // SDK_V9
468-
return !isV2Enabled || self.appHangTimeoutInterval <= 0;
460+
return !self.enableAppHangTracking || self.appHangTimeoutInterval <= 0;
469461
}
470462
#endif // SENTRY_HAS_UIKIT
471463

Sources/Sentry/SentryProfiler.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ - (void)stopForReason:(SentryProfilerTruncationReason)reason
247247

248248
BOOL autoPerformanceTracingDisabled
249249
= ![[[[SentrySDKInternal currentHub] getClient] options] enableAutoPerformanceTracing];
250-
BOOL appHangsV2Disabled =
251-
[[[[SentrySDKInternal currentHub] getClient] options] isAppHangTrackingV2Disabled];
250+
BOOL appHangsDisabled =
251+
[[[[SentrySDKInternal currentHub] getClient] options] isAppHangTrackingDisabled];
252252

253-
if (autoPerformanceTracingDisabled && appHangsV2Disabled) {
253+
if (autoPerformanceTracingDisabled && appHangsDisabled) {
254254
sentry_stopFramesTracker();
255255
}
256256
# endif // SENTRY_HAS_UIKIT

Sources/Sentry/SentryWatchdogTerminationTrackingIntegration.m

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options
7474

7575
[self.tracker start];
7676

77-
# if SDK_V9
78-
BOOL isV2Enabled = YES;
79-
# else
80-
BOOL isV2Enabled = options.enableAppHangTrackingV2;
81-
# endif // SDK_V9
82-
8377
self.anrTracker =
84-
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval
85-
isV2Enabled:isV2Enabled];
78+
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
8679
[self.anrTracker addListener:self];
8780

8881
self.appStateManager = appStateManager;

0 commit comments

Comments
 (0)