Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public enum SentrySDKOverrides: String, CaseIterable {
public enum Performance: String, SentrySDKOverride {
case disableTimeToFullDisplayTracing = "--io.sentry.performance.disable-time-to-full-display-tracing"
case disablePerformanceV2 = "--io.sentry.performance.disable-performance-v2"
case disableAppHangTrackingV2 = "--io.sentry.performance.disable-app-hang-tracking-v2"
case disableSessionTracking = "--io.sentry.performance.disable-automatic-session-tracking"
case disableFileIOTracing = "--io.sentry.performance.disable-file-io-tracing"
case disableUIVCTracing = "--io.sentry.performance.disable-uiviewcontroller-tracing"
Expand Down Expand Up @@ -315,7 +314,7 @@ extension SentrySDKOverrides.Other {
extension SentrySDKOverrides.Performance {
public var overrideType: OverrideType {
switch self {
case .disableTimeToFullDisplayTracing, .disablePerformanceV2, .disableAppHangTrackingV2, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return .boolean
case .disableTimeToFullDisplayTracing, .disablePerformanceV2, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return .boolean
case .sessionTrackingIntervalMillis: return .string
}
}
Expand Down Expand Up @@ -402,7 +401,7 @@ extension SentrySDKOverrides.Other {
extension SentrySDKOverrides.Performance {
public var ignoresDisableEverything: Bool {
switch self {
case .disableTimeToFullDisplayTracing, .disablePerformanceV2, .disableAppHangTrackingV2, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return false
case .disableTimeToFullDisplayTracing, .disablePerformanceV2, .disableSessionTracking, .disableFileIOTracing, .disableUIVCTracing, .disableCoreDataTracing, .disableANRTracking, .disableWatchdogTracking, .disableUITracing, .disablePrewarmedAppStartTracing, .disablePerformanceTracing: return false
case .sessionTrackingIntervalMillis: return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ public struct SentrySDKWrapper {
options.screenshot.maskAllText = !SentrySDKOverrides.Screenshot.disableMaskAllText.boolValue

options.attachViewHierarchy = !SentrySDKOverrides.Other.disableAttachViewHierarchy.boolValue
#if !SDK_V9
options.enableAppHangTrackingV2 = !SentrySDKOverrides.Performance.disableAppHangTrackingV2.boolValue
#endif // SDK_V9
#endif // !os(macOS) && !os(watchOS)

// disable during benchmarks because we run CPU for 15 seconds at full throttle which can trigger ANRs
Expand Down
27 changes: 2 additions & 25 deletions Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,34 +662,11 @@ typedef void (^SentryProfilingConfigurationBlock)(SentryProfileOptions *_Nonnull

#if SENTRY_UIKIT_AVAILABLE

# if !SDK_V9
/**
* AppHangTrackingV2 can differentiate between fully-blocking and non-fully blocking app hangs.
* fully-blocking app hang is when the main thread is stuck completely, and the app can't render a
* single frame. A non-fully-blocking app hang is when the app appears stuck to the user but can
still
* render a few frames. Fully-blocking app hangs are more actionable because the stacktrace shows
the
* exact blocking location on the main thread. As the main thread isn't completely blocked,
* non-fully-blocking app hangs can have a stacktrace that doesn't highlight the exact blocking
* location.
*
* You can use @c enableReportNonFullyBlockingAppHangs to ignore non-fully-blocking app hangs.
*
* @note This flag wins over enableAppHangTracking. When enabling both enableAppHangTracking and
enableAppHangTrackingV2, the SDK only enables enableAppHangTrackingV2 and disables
enableAppHangTracking.
*/
Comment on lines -665 to -682
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h: We must migrate this info to the enableAppHangTracking option. Now macOS uses V1 and iOS/tvOS V2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this you mean the comment right? I can update that

@property (nonatomic, assign) BOOL enableAppHangTrackingV2;

# endif // !SDK_V9

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

Expand Down
61 changes: 18 additions & 43 deletions Sources/Sentry/SentryANRTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options
}

#if SENTRY_HAS_UIKIT
# if SDK_V9
BOOL isV2Enabled = YES;
# else
BOOL isV2Enabled = options.enableAppHangTrackingV2;
# endif // SDK_V9
self.tracker =
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval
isV2Enabled:isV2Enabled];
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
#else
self.tracker =
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
Expand Down Expand Up @@ -158,48 +152,29 @@ - (void)anrDetectedWithType:(enum SentryANRType)type
getDebugImagesFromCacheForThreads:SENTRY_UNWRAP_NULLABLE(NSArray, event.threads)];

#if SENTRY_HAS_UIKIT
# if SDK_V9
BOOL isV2Enabled = YES;
# else
BOOL isV2Enabled = self.options.enableAppHangTrackingV2;
# endif // SDK_V9

// We only measure app hang duration for V2.
// For V1, we directly capture the app hang event.
if (isV2Enabled) {
// We only temporarily store the app hang duration info, so we can change the error message
// when either sending a normal or fatal app hang event. Otherwise, we would have to rely on
// string parsing to retrieve the app hang duration info from the error message.
mechanism.data = @{ SentryANRMechanismDataAppHangDuration : appHangDurationInfo };

// We need to apply the scope now because if the app hang turns into a fatal one,
// we would lose the scope. Furthermore, we want to know in which state the app was when the
// app hang started.
SentryScope *scope = [SentrySDKInternal currentHub].scope;
SentryOptions *options = SentrySDKInternal.options;
if (scope != nil && options != nil) {
[scope applyToEvent:event maxBreadcrumb:options.maxBreadcrumbs];
}

[self.fileManager storeAppHangEvent:event];
} else {
#endif // SENTRY_HAS_UIKIT
[SentrySDK captureEvent:event];
#if SENTRY_HAS_UIKIT
// We only temporarily store the app hang duration info, so we can change the error message
// when either sending a normal or fatal app hang event. Otherwise, we would have to rely on
// string parsing to retrieve the app hang duration info from the error message.
mechanism.data = @{ SentryANRMechanismDataAppHangDuration : appHangDurationInfo };

// We need to apply the scope now because if the app hang turns into a fatal one,
// we would lose the scope. Furthermore, we want to know in which state the app was when the
// app hang started.
SentryScope *scope = [SentrySDKInternal currentHub].scope;
SentryOptions *options = SentrySDKInternal.options;
if (scope != nil && options != nil) {
[scope applyToEvent:event maxBreadcrumb:options.maxBreadcrumbs];
}
#endif // SENTRY_UIKIT_AVAILABLE

[self.fileManager storeAppHangEvent:event];
#else
[SentrySDK captureEvent:event];
#endif
}

- (void)anrStoppedWithResult:(SentryANRStoppedResult *_Nullable)result
{
#if SENTRY_HAS_UIKIT
// We only measure app hang duration for V2, and therefore ignore V1.
# if !SDK_V9
if (!self.options.enableAppHangTrackingV2) {
return;
}
# endif // !SDK_V9

if (result == nil) {
SENTRY_LOG_WARN(@"ANR stopped for V2 but result was nil.")
return;
Expand Down
12 changes: 0 additions & 12 deletions Sources/Sentry/SentryBaseIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,10 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options

if (integrationOptions & kIntegrationOptionEnableAppHangTracking) {
#if SENTRY_HAS_UIKIT
# if SDK_V9
if (!options.enableAppHangTracking) {
[self logWithOptionName:@"enableAppHangTracking"];
return NO;
}
# else
if (!options.enableAppHangTracking && !options.enableAppHangTrackingV2) {
[self logWithOptionName:@"enableAppHangTracking && enableAppHangTrackingV2"];
return NO;
}
# endif
#else
if (!options.enableAppHangTracking) {
[self logWithOptionName:@"enableAppHangTracking"];
Expand Down Expand Up @@ -186,14 +179,9 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options
BOOL performanceDisabled
= !options.enableAutoPerformanceTracing || !options.isTracingEnabled;
BOOL appHangsV2Disabled = options.isAppHangTrackingV2Disabled;
# if SDK_V9
// The V9 watchdog tracker uses the frames tracker, so frame tracking
// must be enabled if watchdog tracking is enabled.
BOOL watchdogDisabled = !options.enableWatchdogTerminationTracking;
# else
// Before V9 this should have no effect so set it to YES
BOOL watchdogDisabled = YES;
# endif // SDK_V9

if (performanceDisabled && appHangsV2Disabled && watchdogDisabled) {
if (appHangsV2Disabled) {
Expand Down
26 changes: 9 additions & 17 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,30 +257,22 @@ - (SentryCrash *)crashReporter SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout
SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
{
#if SENTRY_HAS_UIKIT
SENTRY_LAZY_INIT(_anrTracker,
[[[SentryANRTrackerV2 alloc] initWithTimeoutInterval:timeout
crashWrapper:self.crashWrapper
dispatchQueueWrapper:self.dispatchQueueWrapper
threadWrapper:self.threadWrapper
framesTracker:self.framesTracker] asProtocol]);
#else
SENTRY_LAZY_INIT(_anrTracker,
[[[SentryANRTrackerV1 alloc] initWithTimeoutInterval:timeout
crashWrapper:self.crashWrapper
dispatchQueueWrapper:self.dispatchQueueWrapper
threadWrapper:self.threadWrapper] asProtocol]);
#endif
}

#if SENTRY_HAS_UIKIT
- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout
isV2Enabled:(BOOL)isV2Enabled SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
{
if (isV2Enabled) {
SENTRY_LAZY_INIT(_anrTracker,
[[[SentryANRTrackerV2 alloc] initWithTimeoutInterval:timeout
crashWrapper:self.crashWrapper
dispatchQueueWrapper:self.dispatchQueueWrapper
threadWrapper:self.threadWrapper
framesTracker:self.framesTracker] asProtocol]);
} else {
return [self getANRTracker:timeout];
}
}
#endif // SENTRY_HAS_UIKIT

#if SENTRY_TARGET_REPLAY_SUPPORTED
- (nonnull SentryScreenshotSource *)screenshotSource SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
{
Expand Down
10 changes: 1 addition & 9 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ - (instancetype)init
self.enableUserInteractionTracing = YES;
self.idleTimeout = SentryTracerDefaultTimeout;
self.enablePreWarmedAppStartTracing = NO;
# if !SDK_V9
self.enableAppHangTrackingV2 = NO;
# endif // !SDK_V9
self.enableReportNonFullyBlockingAppHangs = YES;
#endif // SENTRY_HAS_UIKIT

Expand Down Expand Up @@ -501,12 +498,7 @@ - (void)setEnableSpotlight:(BOOL)value
#if SENTRY_HAS_UIKIT
- (BOOL)isAppHangTrackingV2Disabled
{
# if SDK_V9
BOOL isV2Enabled = self.enableAppHangTracking;
# else
BOOL isV2Enabled = self.enableAppHangTrackingV2;
# endif // SDK_V9
return !isV2Enabled || self.appHangTimeoutInterval <= 0;
return !self.enableAppHangTracking || self.appHangTimeoutInterval <= 0;
}
#endif // SENTRY_HAS_UIKIT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options

[self.tracker start];

# if SDK_V9
BOOL isV2Enabled = YES;
# else
BOOL isV2Enabled = options.enableAppHangTrackingV2;
# endif // SDK_V9

self.anrTracker =
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval
isV2Enabled:isV2Enabled];
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
[self.anrTracker addListener:self];

self.appStateManager = appStateManager;
Expand Down
5 changes: 0 additions & 5 deletions Sources/Sentry/SentyOptionsInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ + (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
[self setBool:options[@"enablePreWarmedAppStartTracing"]
block:^(BOOL value) { sentryOptions.enablePreWarmedAppStartTracing = value; }];

# if !SDK_V9
[self setBool:options[@"enableAppHangTrackingV2"]
block:^(BOOL value) { sentryOptions.enableAppHangTrackingV2 = value; }];
# endif // !SDK_V9

[self setBool:options[@"enableReportNonFullyBlockingAppHangs"]
block:^(BOOL value) { sentryOptions.enableReportNonFullyBlockingAppHangs = value; }];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ SENTRY_NO_INIT
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;

- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout;
#if SENTRY_HAS_UIKIT
- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout isV2Enabled:(BOOL)isV2Enabled;
#endif // SENTRY_HAS_UIKIT

- (nullable id<SentryApplication>)application;

Expand Down
8 changes: 0 additions & 8 deletions Sources/Swift/Helper/SentryEnabledFeaturesBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ import Foundation
if options.swiftAsyncStacktraces {
features.append("swiftAsyncStacktraces")
}

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if !SDK_V9
if options.enableAppHangTrackingV2 {
features.append("appHangTrackingV2")
}
#endif // !SDK_V9
#endif //os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

if options.enablePersistingTracesWhenCrashing {
features.append("persistingTracesWhenCrashing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,7 @@ final class SentryContinuousProfilerTests: XCTestCase {

#if !os(macOS)

func testStopsFramesTracker_WhenAutoPerformanceAndAppHangsV2Disabled() throws {
fixture.options.enableAutoPerformanceTracing = false
try performContinuousProfilingTest()

XCTAssertFalse(SentryDependencyContainer.sharedInstance().framesTracker.isRunning)
}

func testDoesNotStopFramesTracker_WhenAppHangsV2Enabled() throws {
fixture.options.enableAppHangTrackingV2 = true
try performContinuousProfilingTest()

XCTAssertTrue(SentryDependencyContainer.sharedInstance().framesTracker.isRunning)
Expand Down
36 changes: 4 additions & 32 deletions Tests/SentryTests/Helper/SentryDependencyContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,21 @@ final class SentryDependencyContainerTests: XCTestCase {
}

func testGetANRTrackerV2() {
let instance = SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: true)
let instance = SentryDependencyContainer.sharedInstance().getANRTracker(2.0)
XCTAssertTrue(instance is SentryANRTrackerV2)

SentryDependencyContainer.reset()

}

func testGetANRTrackerV1() {
let instance = SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: false)
XCTAssertTrue(instance is SentryANRTrackerV1)

SentryDependencyContainer.reset()
}

func testGetANRTrackerV2AndThenV1_FirstCalledVersionStaysTheSame() {
let instance1 = SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: true)
XCTAssertTrue(instance1 is SentryANRTrackerV2)

let instance2 = SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: false)
XCTAssertTrue(instance2 is SentryANRTrackerV2)

SentryDependencyContainer.reset()
}

func testGetANRTrackerV1AndThenV2_FirstCalledVersionStaysTheSame() {
let instance1 = SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: false)
XCTAssertTrue(instance1 is SentryANRTrackerV1)

let instance2 = SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: true)
XCTAssertTrue(instance2 is SentryANRTrackerV1)

SentryDependencyContainer.reset()
}

#endif

#else
func testGetANRTracker_ReturnsV1() {

let instance = SentryDependencyContainer.sharedInstance().getANRTracker(2.0)
XCTAssertTrue(instance is SentryANRTrackerV1)

SentryDependencyContainer.reset()
}
#endif

/**
* This test helps to find threading issues. If you run it once it detects obvious threading issues. Some rare edge cases
Expand Down Expand Up @@ -121,7 +93,7 @@ final class SentryDependencyContainerTests: XCTestCase {
XCTAssertNotNil(SentryDependencyContainer.sharedInstance().getANRTracker(2.0))

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
XCTAssertNotNil(SentryDependencyContainer.sharedInstance().getANRTracker(2.0, isV2Enabled: true))
XCTAssertNotNil(SentryDependencyContainer.sharedInstance().getANRTracker(2.0))
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@_spi(Private) @testable import Sentry

Check failure on line 1 in Tests/SentryTests/Helper/SentryEnabledFeaturesBuilderTests.swift

View workflow job for this annotation

GitHub Actions / JUnit Test Report

SentryEnabledFeaturesBuilderTests.testEnableAllFeatures

/Users/runner/work/sentry-cocoa/sentry-cocoa/Tests/SentryTests/Helper/SentryEnabledFeaturesBuilderTests.swift:59 - XCTAssertTrue failed
import XCTest

@available(*, deprecated, message: "This is only marked as deprecated because enableAppLaunchProfiling is marked as deprecated. Once that is removed this can be removed.")
Expand Down Expand Up @@ -36,10 +36,6 @@
#endif // canImport(UIKit)
#endif // os(iOS) || os(tvOS)

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
options.enableAppHangTrackingV2 = true
#endif //os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

// -- Act --
let features = SentryEnabledFeaturesBuilder.getEnabledFeatures(options: options)

Expand Down
Loading
Loading