diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 3f38d3b94f9..f49f6d8f93f 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -712,9 +712,9 @@ 8EA9AF492665AC48002771B4 /* SentryPerformanceTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EA9AF482665AC48002771B4 /* SentryPerformanceTrackerTests.swift */; }; 8EAC7FF8265C8910005B44E5 /* SentryTracerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EAC7FF7265C8910005B44E5 /* SentryTracerTests.swift */; }; 8EAE8E5E2681768000D6958B /* URLSessionTaskMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EAE8E5D2681768000D6958B /* URLSessionTaskMock.m */; }; - 8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EAE9804261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m */; }; + 8EAE9806261E87120073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EAE9804261E87120073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.m */; }; 8EAE980B261E9F530073B6B3 /* SentryPerformanceTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EAE9809261E9F530073B6B3 /* SentryPerformanceTracker.h */; }; - 8EAE980C261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EAE980A261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h */; }; + 8EAE980C261E9F530073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EAE980A261E9F530073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.h */; }; 8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EBF870726140D37001A6853 /* SentryPerformanceTracker.m */; }; 8EC3AE7A25CA23B600E7591A /* SentrySpan.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC3AE7925CA23B600E7591A /* SentrySpan.m */; }; 8EC4CF4A25C38DAA0093DEE9 /* SentrySpanStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC4CF4725C38CAF0093DEE9 /* SentrySpanStatus.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1114,6 +1114,7 @@ FAAB2EE02E4BE97500FE8B7E /* TestSentryNSApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB2EDF2E4BE96F00FE8B7E /* TestSentryNSApplication.swift */; }; FAAB2F972E4D345800FE8B7E /* SentryUIDeviceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB2F962E4D344F00FE8B7E /* SentryUIDeviceWrapper.swift */; }; FAAB30F32E4E8F2C00FE8B7E /* SentryInAppLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB30F22E4E8F2C00FE8B7E /* SentryInAppLogic.swift */; }; + FAB007362E9EF8D3001C806A /* SentryUIViewControllerPerformanceTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */; }; FAB359982E05D7E90083D5E3 /* SentryEventSwiftHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */; }; FAB3599A2E05D8080083D5E3 /* SentryEventSwiftHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */; }; FAB7BBA92E2577A6007301E1 /* SentryModels+Serializable.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */; }; @@ -2053,9 +2054,9 @@ 8EAC7FF7265C8910005B44E5 /* SentryTracerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTracerTests.swift; sourceTree = ""; }; 8EAE8E5C2681768000D6958B /* URLSessionTaskMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = URLSessionTaskMock.h; sourceTree = ""; }; 8EAE8E5D2681768000D6958B /* URLSessionTaskMock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = URLSessionTaskMock.m; sourceTree = ""; }; - 8EAE9804261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUIViewControllerPerformanceTracker.m; sourceTree = ""; }; + 8EAE9804261E87120073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDefaultUIViewControllerPerformanceTracker.m; sourceTree = ""; }; 8EAE9809261E9F530073B6B3 /* SentryPerformanceTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryPerformanceTracker.h; path = include/SentryPerformanceTracker.h; sourceTree = ""; }; - 8EAE980A261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryUIViewControllerPerformanceTracker.h; path = include/SentryUIViewControllerPerformanceTracker.h; sourceTree = ""; }; + 8EAE980A261E9F530073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDefaultUIViewControllerPerformanceTracker.h; path = include/SentryDefaultUIViewControllerPerformanceTracker.h; sourceTree = ""; }; 8EBF870726140D37001A6853 /* SentryPerformanceTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryPerformanceTracker.m; sourceTree = ""; }; 8EC3AE7925CA23B600E7591A /* SentrySpan.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySpan.m; sourceTree = ""; }; 8EC4CF4725C38CAF0093DEE9 /* SentrySpanStatus.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySpanStatus.h; path = Public/SentrySpanStatus.h; sourceTree = ""; }; @@ -2476,6 +2477,7 @@ FAAB2EDF2E4BE96F00FE8B7E /* TestSentryNSApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryNSApplication.swift; sourceTree = ""; }; FAAB2F962E4D344F00FE8B7E /* SentryUIDeviceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIDeviceWrapper.swift; sourceTree = ""; }; FAAB30F22E4E8F2C00FE8B7E /* SentryInAppLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryInAppLogic.swift; sourceTree = ""; }; + FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIViewControllerPerformanceTracker.swift; sourceTree = ""; }; FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEventSwiftHelper.h; path = include/SentryEventSwiftHelper.h; sourceTree = ""; }; FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEventSwiftHelper.m; sourceTree = ""; }; FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryModels+Serializable.h"; path = "include/SentryModels+Serializable.h"; sourceTree = ""; }; @@ -3740,8 +3742,8 @@ children = ( 8EA1ED0C2669028C00E62B98 /* SentryUIViewControllerSwizzling.h */, 8EA1ED092668F8C400E62B98 /* SentryUIViewControllerSwizzling.m */, - 8EAE980A261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h */, - 8EAE9804261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m */, + 8EAE980A261E9F530073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.h */, + 8EAE9804261E87120073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.m */, 8EAE9809261E9F530073B6B3 /* SentryPerformanceTracker.h */, 8EBF870726140D37001A6853 /* SentryPerformanceTracker.m */, D8BFE37029A3782F002E73F3 /* SentryTimeToDisplayTracker.h */, @@ -4577,6 +4579,7 @@ D8739CF72BECFF92007D2F66 /* Performance */ = { isa = PBXGroup; children = ( + FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */, FAE57BF12E83049900B710F9 /* SentryDisplayLinkWrapper.swift */, D468C0602D36699700964230 /* IO */, ); @@ -5015,7 +5018,7 @@ D8ACE3CD2762187D00F5A213 /* SentryNSDataSwizzling.h in Headers */, 7B08A3452924CF6C0059603A /* SentryMetricKitIntegration.h in Headers */, 0A2D8DA8289BC905008720F6 /* SentryViewHierarchyProviderHelper.h in Headers */, - 8EAE980C261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h in Headers */, + 8EAE980C261E9F530073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.h in Headers */, 63FE717D20DA4C1100CDBAE8 /* SentryCrashCachedData.h in Headers */, 03BCC38A27E1BF49003232C7 /* SentryTime.h in Headers */, 925824C22CB5897700C9B20B /* SentrySessionReplayIntegration-Hybrid.h in Headers */, @@ -5996,9 +5999,10 @@ 8ECC674925C23A20000E2BF6 /* SentrySpanId.m in Sources */, 6344DDB51EC309E000D9160D /* SentryCrashReportSink.m in Sources */, D43B26D62D70964C007747FD /* SentrySpanOperation.m in Sources */, - 8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */, + 8EAE9806261E87120073B6B3 /* SentryDefaultUIViewControllerPerformanceTracker.m in Sources */, D81988C72BEC18E20020E36C /* SentryRRWebVideoEvent.swift in Sources */, 621F61F12BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift in Sources */, + FAB007362E9EF8D3001C806A /* SentryUIViewControllerPerformanceTracker.swift in Sources */, D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */, D8F67B1B2BE9728600C9197B /* SentrySRDefaultBreadcrumbConverter.swift in Sources */, 8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */, diff --git a/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h b/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h index 6a0209428aa..d756aaafb8c 100644 --- a/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h +++ b/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h @@ -8,8 +8,8 @@ #if SENTRY_HAS_UIKIT # import "SentryAppStartTracker.h" +# import "SentryDefaultUIViewControllerPerformanceTracker.h" # import "SentryFramesTracker+TestInit.h" -# import "SentryUIViewControllerPerformanceTracker.h" #endif // SENTRY_HAS_UIKIT #import "SentryProfilingConditionals.h" diff --git a/Sources/Sentry/SentryUIViewControllerPerformanceTracker.m b/Sources/Sentry/SentryDefaultUIViewControllerPerformanceTracker.m similarity index 95% rename from Sources/Sentry/SentryUIViewControllerPerformanceTracker.m rename to Sources/Sentry/SentryDefaultUIViewControllerPerformanceTracker.m index 022f17a91c8..cac70578e05 100644 --- a/Sources/Sentry/SentryUIViewControllerPerformanceTracker.m +++ b/Sources/Sentry/SentryDefaultUIViewControllerPerformanceTracker.m @@ -1,4 +1,4 @@ -#import "SentryUIViewControllerPerformanceTracker.h" +#import "SentryDefaultUIViewControllerPerformanceTracker.h" #import "SentryInternalDefines.h" #if SENTRY_HAS_UIKIT @@ -23,7 +23,10 @@ @interface SentryTimeToDisplayTracker () @end -@implementation SentrySwiftUISpanHelper +@interface SentryObjCSwiftUISpanHelper () +@end + +@implementation SentryObjCSwiftUISpanHelper - (instancetype)initWithHasSpan:(BOOL)hasSpan initialDisplayReporting:(id)initialDisplayReporting @@ -63,7 +66,7 @@ - (instancetype)initWithHasSpan:(BOOL)hasSpan // remove any entries with weak keys that have been deallocated. This will ensure that we don't // keep any references to deallocated objects in the map tables and have a memory leak. -@interface SentryUIViewControllerPerformanceTracker () +@interface SentryDefaultUIViewControllerPerformanceTracker () @property (nonatomic, strong) SentryPerformanceTracker *tracker; @property (nullable, nonatomic, weak) SentryTimeToDisplayTracker *currentTTDTracker; @@ -79,7 +82,7 @@ @interface SentryUIViewControllerPerformanceTracker () @end -@implementation SentryUIViewControllerPerformanceTracker +@implementation SentryDefaultUIViewControllerPerformanceTracker - (instancetype)initWithTracker:(SentryPerformanceTracker *)tracker dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper @@ -276,7 +279,7 @@ - (SentrySwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)scre { id span = [SentryPerformanceTracker.shared getSpan:transactionId]; if (span != nil && [span isKindOfClass:[SentryTracer class]]) { - id displayReporting = + SentryTimeToDisplayTracker *displayReporting = [self startTimeToDisplayTrackerForScreen:screenName waitForFullDisplay:waitforFullDisplay tracer:(SentryTracer *)span]; @@ -286,6 +289,20 @@ - (SentrySwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)scre return [[SentrySwiftUISpanHelper alloc] initWithHasSpan:NO initialDisplayReporting:nil]; } ++ (SentryObjCSwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)screenName + waitForFullDisplay:(BOOL)waitforFullDisplay + transactionId:(SentrySpanId *)transactionId; +{ + id vcTracker + = SentryDependencyContainer.sharedInstance.uiViewControllerPerformanceTracker; + SentrySwiftUISpanHelper *result = + [vcTracker startTimeToDisplayTrackerForScreen:screenName + waitForFullDisplay:waitforFullDisplay + transactionId:transactionId]; + return [[SentryObjCSwiftUISpanHelper alloc] initWithHasSpan:result.hasSpan + initialDisplayReporting:result.initialDisplayReporting]; +} + - (void)viewControllerViewWillAppear:(UIViewController *)controller callbackToOrigin:(void (^)(void))callbackToOrigin { diff --git a/Sources/Sentry/SentryDependencyContainer.m b/Sources/Sentry/SentryDependencyContainer.m index 56095a12dd9..d130df2c0ec 100644 --- a/Sources/Sentry/SentryDependencyContainer.m +++ b/Sources/Sentry/SentryDependencyContainer.m @@ -13,13 +13,13 @@ #import #import #import +#import #import #import #import #import #import #import -#import #import #if SENTRY_HAS_UIKIT @@ -65,6 +65,12 @@ @interface SentryFileManager () @interface SentryDefaultAppStateManager () @end +#if SENTRY_HAS_UIKIT +@interface SentryDefaultUIViewControllerPerformanceTracker () < + SentryUIViewControllerPerformanceTracker> +@end +#endif + @interface SentryDependencyContainer () @property (nonatomic, strong) id anrTracker; @@ -315,12 +321,12 @@ - (SentryViewHierarchyProvider *)viewHierarchyProvider SENTRY_THREAD_SANITIZER_D # endif // SENTRY_HAS_UIKIT } -- (SentryUIViewControllerPerformanceTracker *) +- (id) uiViewControllerPerformanceTracker SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK { # if SENTRY_HAS_UIKIT SENTRY_LAZY_INIT(_uiViewControllerPerformanceTracker, - [[SentryUIViewControllerPerformanceTracker alloc] + [[SentryDefaultUIViewControllerPerformanceTracker alloc] initWithTracker:SentryPerformanceTracker.shared dispatchQueueWrapper:[self dispatchQueueWrapper]]); # else diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index cbbe36472a2..1ac628f15d6 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -24,10 +24,6 @@ #import "SentryTransaction.h" #import "SentryTransactionContext+Private.h" -#if SENTRY_HAS_UIKIT -# import "SentryUIViewControllerPerformanceTracker.h" -#endif // SENTRY_HAS_UIKIT - NS_ASSUME_NONNULL_BEGIN @interface SentryHub () diff --git a/Sources/Sentry/SentryPerformanceTrackingIntegration.m b/Sources/Sentry/SentryPerformanceTrackingIntegration.m index efe06dd04dd..2f71118408a 100644 --- a/Sources/Sentry/SentryPerformanceTrackingIntegration.m +++ b/Sources/Sentry/SentryPerformanceTrackingIntegration.m @@ -7,7 +7,6 @@ # import "SentryOptions.h" # import "SentrySubClassFinder.h" # import "SentrySwift.h" -# import "SentryUIViewControllerPerformanceTracker.h" # import "SentryUIViewControllerSwizzling.h" @interface SentryPerformanceTrackingIntegration () @@ -44,7 +43,7 @@ - (BOOL)installWithOptions:(SentryOptions *)options binaryImageCache:[SentryDependencyContainer.sharedInstance binaryImageCache]]; [self.swizzling start]; - SentryUIViewControllerPerformanceTracker *performanceTracker = + id performanceTracker = [SentryDependencyContainer.sharedInstance uiViewControllerPerformanceTracker]; performanceTracker.alwaysWaitForFullDisplay = options.enableTimeToFullDisplayTracing; diff --git a/Sources/Sentry/SentrySDKInternal.m b/Sources/Sentry/SentrySDKInternal.m index b3af6c77359..47a08121f8b 100644 --- a/Sources/Sentry/SentrySDKInternal.m +++ b/Sources/Sentry/SentrySDKInternal.m @@ -28,7 +28,6 @@ #endif // TARGET_OS_MAC #if SENTRY_HAS_UIKIT -# import "SentryUIViewControllerPerformanceTracker.h" # if TARGET_OS_IOS # import "SentryFeedbackAPI.h" # endif // TARGET_OS_IOS diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 1ade9384c32..745f1497920 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -36,7 +36,6 @@ # import "SentryAppStartMeasurement.h" # import "SentryBuildAppStartSpans.h" # import "SentryFramesTracker.h" -# import "SentryUIViewControllerPerformanceTracker.h" #endif // SENTRY_HAS_UIKIT NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/SentryUIViewControllerSwizzling.m b/Sources/Sentry/SentryUIViewControllerSwizzling.m index 93d3623a8de..29819bb2e89 100644 --- a/Sources/Sentry/SentryUIViewControllerSwizzling.m +++ b/Sources/Sentry/SentryUIViewControllerSwizzling.m @@ -8,7 +8,6 @@ # import "SentrySubClassFinder.h" # import "SentrySwift.h" # import "SentrySwizzle.h" -# import "SentryUIViewControllerPerformanceTracker.h" # import # import # import @@ -111,7 +110,7 @@ - (void)start } [self swizzleUIViewController]; - SentryUIViewControllerPerformanceTracker *performanceTracker = + id performanceTracker = [SentryDependencyContainer.sharedInstance uiViewControllerPerformanceTracker]; performanceTracker.inAppLogic = self.inAppLogic; } diff --git a/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h b/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h index 28cc2cd2dcc..9a272e8bc01 100644 --- a/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h +++ b/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h @@ -46,9 +46,10 @@ @class SentryFramesTracker; @class SentryScreenshotSource; @class SentryViewHierarchyProvider; -@class SentryUIViewControllerPerformanceTracker; @class SentryWatchdogTerminationAttributesProcessor; + @protocol SentryScopeObserver; +@protocol SentryUIViewControllerPerformanceTracker; #endif // SENTRY_UIKIT_AVAILABLE #if SENTRY_HAS_UIKIT @@ -128,8 +129,8 @@ SENTRY_NO_INIT #if SENTRY_UIKIT_AVAILABLE @property (nonatomic, strong) SentryFramesTracker *framesTracker; @property (nonatomic, strong) SentryViewHierarchyProvider *viewHierarchyProvider; -@property (nonatomic, strong) - SentryUIViewControllerPerformanceTracker *uiViewControllerPerformanceTracker; +@property (nonatomic, strong) id + uiViewControllerPerformanceTracker; #endif // SENTRY_UIKIT_AVAILABLE #if SENTRY_TARGET_REPLAY_SUPPORTED diff --git a/Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h b/Sources/Sentry/include/SentryDefaultUIViewControllerPerformanceTracker.h similarity index 89% rename from Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h rename to Sources/Sentry/include/SentryDefaultUIViewControllerPerformanceTracker.h index aff53257fbd..42dd70abb2d 100644 --- a/Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h +++ b/Sources/Sentry/include/SentryDefaultUIViewControllerPerformanceTracker.h @@ -9,15 +9,11 @@ @class SentryPerformanceTracker; @class SentryDispatchQueueWrapper; -NS_ASSUME_NONNULL_BEGIN - -@protocol SentryInitialDisplayReporting - -- (void)reportInitialDisplay; +@protocol SentryInitialDisplayReporting; -@end +NS_ASSUME_NONNULL_BEGIN -@interface SentrySwiftUISpanHelper : NSObject +@interface SentryObjCSwiftUISpanHelper : NSObject @property (nonatomic, readonly) BOOL hasSpan; @@ -30,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN * Class responsible to track UI performance. * This class is intended to be used in a swizzled context. */ -@interface SentryUIViewControllerPerformanceTracker : NSObject +@interface SentryDefaultUIViewControllerPerformanceTracker : NSObject @property (nonatomic, strong) SentryInAppLogic *inAppLogic; @@ -110,9 +106,9 @@ SENTRY_NO_INIT - (void)reportFullyDisplayed; -- (SentrySwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)screenName - waitForFullDisplay:(BOOL)waitforFullDisplay - transactionId:(SentrySpanId *)transactionId; ++ (SentryObjCSwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)screenName + waitForFullDisplay:(BOOL)waitforFullDisplay + transactionId:(SentrySpanId *)transactionId; @end diff --git a/Sources/SentrySwiftUI/SentryInternal/SentryInternal.h b/Sources/SentrySwiftUI/SentryInternal/SentryInternal.h index 5c02fc46c18..c490316331e 100644 --- a/Sources/SentrySwiftUI/SentryInternal/SentryInternal.h +++ b/Sources/SentrySwiftUI/SentryInternal/SentryInternal.h @@ -80,10 +80,6 @@ typedef NS_ENUM(NSUInteger, SentrySpanStatus); @end -@protocol SentryInitialDisplayReporting -- (void)reportInitialDisplay; -@end - @interface SentryTimeToDisplayTracker : NSObject - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; @@ -110,22 +106,22 @@ typedef NS_ENUM(NSUInteger, SentrySpanStatus); @end -@interface SentrySwiftUISpanHelper : NSObject +@interface SentryObjCSwiftUISpanHelper : NSObject @property (nonatomic, readonly) BOOL hasSpan; -@property (nonatomic, strong, readonly, nullable) id - initialDisplayReporting; +@property (nonatomic, strong, readonly, nullable) + SentryTimeToDisplayTracker *initialDisplayReporting; @end -@interface SentryUIViewControllerPerformanceTracker : NSObject +@interface SentryDefaultUIViewControllerPerformanceTracker : NSObject - (void)reportFullyDisplayed; -- (SentrySwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)screenName - waitForFullDisplay:(BOOL)waitforFullDisplay - transactionId:(SentrySpanId *)transactionId; ++ (SentryObjCSwiftUISpanHelper *)startTimeToDisplayTrackerForScreen:(NSString *)screenName + waitForFullDisplay:(BOOL)waitforFullDisplay + transactionId:(SentrySpanId *)transactionId; @end diff --git a/Sources/SentrySwiftUI/SentryTracedView.swift b/Sources/SentrySwiftUI/SentryTracedView.swift index b0a0e2763aa..2dfe23be901 100644 --- a/Sources/SentrySwiftUI/SentryTracedView.swift +++ b/Sources/SentrySwiftUI/SentryTracedView.swift @@ -11,7 +11,7 @@ import SwiftUI class SentryTraceViewModel { private var transactionId: SpanId? private var viewAppeared: Bool = false - private var tracker: SentryInitialDisplayReporting? + private var tracker: SentryTimeToDisplayTracker? let name: String let nameSource: SentryTransactionNameSource @@ -44,8 +44,7 @@ class SentryTraceViewModel { SentryPerformanceTracker.shared.pushActiveSpan(transactionId) self.transactionId = transactionId #if canImport(SwiftUI) && canImport(UIKit) && os(iOS) || os(tvOS) - let uiViewControllerPerformanceTracker = SentryDependencyContainer.sharedInstance().uiViewControllerPerformanceTracker - let swiftUITraceHelper = uiViewControllerPerformanceTracker.startTimeToDisplay(forScreen: name, waitForFullDisplay: waitForFullDisplay, transactionId: transactionId) + let swiftUITraceHelper = SentryDefaultUIViewControllerPerformanceTracker.startTimeToDisplay(forScreen: name, waitForFullDisplay: waitForFullDisplay, transactionId: transactionId) self.tracker = swiftUITraceHelper.initialDisplayReporting return swiftUITraceHelper.hasSpan #else diff --git a/Sources/Swift/Integrations/Performance/SentryUIViewControllerPerformanceTracker.swift b/Sources/Swift/Integrations/Performance/SentryUIViewControllerPerformanceTracker.swift new file mode 100644 index 00000000000..463bd0558d4 --- /dev/null +++ b/Sources/Swift/Integrations/Performance/SentryUIViewControllerPerformanceTracker.swift @@ -0,0 +1,47 @@ +#if (os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))) && !SENTRY_NO_UIKIT + +import UIKit + +@_spi(Private) @objc public protocol SentryInitialDisplayReporting { + func reportInitialDisplay() +} + +@_spi(Private) @objc public class SentrySwiftUISpanHelper: NSObject { + @objc public let hasSpan: Bool + @objc public let initialDisplayReporting: SentryInitialDisplayReporting? + + @objc public init(hasSpan: Bool, initialDisplayReporting: SentryInitialDisplayReporting?) { + self.hasSpan = hasSpan + self.initialDisplayReporting = initialDisplayReporting + } +} + +@_spi(Private) @objc public protocol SentryUIViewControllerPerformanceTracker { + + var inAppLogic: SentryInAppLogic { get set } + + var alwaysWaitForFullDisplay: Bool { get set } + + func viewControllerLoadView(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func viewControllerViewDidLoad(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func viewControllerViewWillAppear(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func viewControllerViewWillDisappear(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func viewControllerViewDidAppear(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func viewControllerViewWillLayoutSubViews(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func viewControllerViewDidLayoutSubViews(_ controller: UIViewController, callbackToOrigin callback: @escaping () -> Void) + + func reportFullyDisplayed() + + func startTimeToDisplayTracker( + forScreen screenName: String, + waitForFullDisplay: Bool, + transactionId: SpanId) -> SentrySwiftUISpanHelper +} + +#endif diff --git a/Tests/SentrySwiftUITests/SentryTests-Bridging-Header.h b/Tests/SentrySwiftUITests/SentryTests-Bridging-Header.h index b6b4af873a2..f8ea1378ab1 100644 --- a/Tests/SentrySwiftUITests/SentryTests-Bridging-Header.h +++ b/Tests/SentrySwiftUITests/SentryTests-Bridging-Header.h @@ -1,14 +1,10 @@ +#import "SentryDefaultUIViewControllerPerformanceTracker.h" #import "SentryHub+Private.h" #import "SentryPerformanceTracker.h" #import "SentryTracer.h" -#import "SentryUIViewControllerPerformanceTracker.h" @class SentryTimeToDisplayTracker; @interface SentryPerformanceTracker () - (void)clear; @end - -@interface SentryUIViewControllerPerformanceTracker () -@property (nullable, nonatomic, weak) SentryTimeToDisplayTracker *currentTTDTracker; -@end diff --git a/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackingIntegrationTests.swift b/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackingIntegrationTests.swift index 74905d8800d..f77535dfd05 100644 --- a/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackingIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackingIntegrationTests.swift @@ -1,3 +1,4 @@ +@_spi(Private) import Sentry import SentryTestUtils import XCTest diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index 4d8d622b8b4..b9a61f03b86 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -6,13 +6,13 @@ #if SENTRY_HAS_UIKIT # import "MockUIScene.h" +# import "SentryDefaultUIViewControllerPerformanceTracker.h" # import "SentryFramesTracker+TestInit.h" # import "SentrySessionReplayIntegration+Private.h" # import "SentrySessionReplayIntegration+Test.h" # import "SentryUIEventTracker.h" # import "SentryUIEventTrackerTransactionMode.h" # import "SentryUIEventTrackingIntegration.h" -# import "SentryUIViewControllerPerformanceTracker.h" # import "SentryUIViewControllerSwizzling+Test.h" # import "SentryUIViewControllerSwizzling.h" # import "UIViewController+Sentry.h"