diff --git a/Sources/Sentry/SentryTimeToDisplayTracker.m b/Sources/Sentry/SentryTimeToDisplayTracker.m index 3a2c6ac4c68..bb78e35dc2b 100644 --- a/Sources/Sentry/SentryTimeToDisplayTracker.m +++ b/Sources/Sentry/SentryTimeToDisplayTracker.m @@ -7,6 +7,7 @@ # import "SentryFramesTracker.h" # import "SentryLog.h" # import "SentryMeasurementValue.h" +# import "SentryOptions.h" # import "SentryProfilingConditionals.h" # import "SentrySpan.h" # import "SentrySpanContext.h" @@ -39,12 +40,12 @@ @implementation SentryTimeToDisplayTracker { } - (instancetype)initForController:(UIViewController *)controller - waitForFullDisplay:(BOOL)waitForFullDisplay + options:(nonnull SentryOptions *)options dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper { if (self = [super init]) { _controllerName = [SwiftDescriptor getObjectClassName:controller]; - _waitForFullDisplay = waitForFullDisplay; + _waitForFullDisplay = options.enableTimeToFullDisplayTracing; _dispatchQueueWrapper = dispatchQueueWrapper; _initialDisplayReported = NO; _fullyDisplayedReported = NO; diff --git a/Sources/Sentry/SentryUIViewControllerPerformanceTracker.m b/Sources/Sentry/SentryUIViewControllerPerformanceTracker.m index e8e23a45eda..9cef1a68866 100644 --- a/Sources/Sentry/SentryUIViewControllerPerformanceTracker.m +++ b/Sources/Sentry/SentryUIViewControllerPerformanceTracker.m @@ -7,7 +7,6 @@ # import "SentryLog.h" # import "SentryOptions.h" # import "SentryPerformanceTracker.h" -# import "SentrySDK+Private.h" # import "SentryScope.h" # import "SentrySpanId.h" # import "SentrySwift.h" @@ -28,7 +27,9 @@ @end -@implementation SentryUIViewControllerPerformanceTracker +@implementation SentryUIViewControllerPerformanceTracker { + SentryOptions *_options; +} + (instancetype)shared { @@ -38,12 +39,11 @@ + (instancetype)shared return instance; } -- (instancetype)init +- (instancetype)initWithOptions:(SentryOptions *)options { if (self = [super init]) { + _options = options; self.tracker = SentryPerformanceTracker.shared; - - SentryOptions *options = [SentrySDK options]; self.inAppLogic = [[SentryInAppLogic alloc] initWithInAppIncludes:options.inAppIncludes inAppExcludes:options.inAppExcludes]; @@ -145,7 +145,7 @@ - (void)createTimeToDisplay:(UIViewController *)controller SentryTimeToDisplayTracker *ttdTracker = [[SentryTimeToDisplayTracker alloc] initForController:controller - waitForFullDisplay:self.enableWaitForFullDisplay + options:_options dispatchQueueWrapper:_dispatchQueueWrapper]; objc_setAssociatedObject(controller, &SENTRY_UI_PERFORMANCE_TRACKER_TTD_TRACKER, ttdTracker, diff --git a/Sources/Sentry/include/SentryTimeToDisplayTracker.h b/Sources/Sentry/include/SentryTimeToDisplayTracker.h index c297edbda5f..261e90bad70 100644 --- a/Sources/Sentry/include/SentryTimeToDisplayTracker.h +++ b/Sources/Sentry/include/SentryTimeToDisplayTracker.h @@ -2,6 +2,7 @@ #if SENTRY_HAS_UIKIT +@class SentryOptions; @class SentrySpan; @class SentryTracer; @class SentryDispatchQueueWrapper; @@ -26,7 +27,7 @@ SENTRY_NO_INIT @property (nonatomic, readonly) BOOL waitForFullDisplay; - (instancetype)initForController:(UIViewController *)controller - waitForFullDisplay:(BOOL)waitForFullDisplay + options:(SentryOptions *)options dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper; - (void)startForTracer:(SentryTracer *)tracer; diff --git a/Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h b/Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h index ed520b34f52..639c0dc14f3 100644 --- a/Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h +++ b/Sources/Sentry/include/SentryUIViewControllerPerformanceTracker.h @@ -2,6 +2,7 @@ #if SENTRY_HAS_UIKIT +@class SentryOptions; @class SentrySpan; @class SentryInAppLogic; @class UIViewController; @@ -26,6 +27,10 @@ static NSString *const SENTRY_UI_PERFORMANCE_TRACKER_TTD_TRACKER */ @interface SentryUIViewControllerPerformanceTracker : NSObject +SENTRY_NO_INIT + +- (instancetype)initWithOptions:(SentryOptions *)options; + @property (nonatomic, readonly, class) SentryUIViewControllerPerformanceTracker *shared; @property (nonatomic, strong) SentryInAppLogic *inAppLogic; diff --git a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryTimeToDisplayTrackerTest.swift b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryTimeToDisplayTrackerTest.swift index e83110f9e08..712491382fc 100644 --- a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryTimeToDisplayTrackerTest.swift +++ b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryTimeToDisplayTrackerTest.swift @@ -11,6 +11,7 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { private class Fixture { let dateProvider: TestCurrentDateProvider = TestCurrentDateProvider() let timerFactory = TestSentryNSTimerFactory() + let options = Options() var displayLinkWrapper = TestDisplayLinkWrapper() var framesTracker: SentryFramesTracker @@ -22,12 +23,11 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { framesTracker.start() } - func getSut(for controller: UIViewController, waitForFullDisplay: Bool) -> SentryTimeToDisplayTracker { - return SentryTimeToDisplayTracker(for: controller, waitForFullDisplay: waitForFullDisplay, dispatchQueueWrapper: SentryDispatchQueueWrapper()) + func getSut(for controller: UIViewController) -> SentryTimeToDisplayTracker { + return SentryTimeToDisplayTracker(for: controller, options: options, dispatchQueueWrapper: SentryDispatchQueueWrapper()) } func getTracer() throws -> SentryTracer { - let options = Options() let hub = TestHub(client: SentryClient(options: options, fileManager: try TestFileManager(options: options), deleteOldEnvelopeItems: false), andScope: nil) return SentryTracer(transactionContext: TransactionContext(operation: "ui.load"), hub: hub, configuration: SentryTracerConfiguration(block: { $0.waitForChildren = true @@ -50,7 +50,7 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { } func testReportInitialDisplay_notWaitingForFullDisplay() throws { - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: false) + let sut = fixture.getSut(for: UIViewController()) fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 7)) let tracer = try fixture.getTracer() @@ -84,7 +84,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { func testReportInitialDisplay_waitForFullDisplay() throws { fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 7)) - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: true) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) @@ -113,7 +114,7 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { } func testReportFullDisplay_notWaitingForFullDisplay() throws { - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: false) + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) @@ -133,7 +134,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { func testReportFullDisplay_waitingForFullDisplay() throws { fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 9)) - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: true) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) @@ -167,7 +169,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { func testWaitingForFullDisplay_ReportFullDisplayBeforeInitialDisplay() throws { fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 9)) - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: true) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) @@ -205,7 +208,7 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { } func testTracerFinishesBeforeReportInitialDisplay_FinishesInitialDisplaySpan() throws { - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: false) + let sut = fixture.getSut(for: UIViewController()) fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 7)) let tracer = try fixture.getTracer() @@ -235,7 +238,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 9)) fixture.dateProvider.driftTimeForEveryRead = true - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: true) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) @@ -250,7 +254,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { let tracer = try fixture.getTracer() - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: true) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = fixture.getSut(for: UIViewController()) sut.start(for: tracer) @@ -286,7 +291,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { func testReportFullyDisplayed_GetsDispatchedOnMainQueue() { let dispatchQueueWrapper = TestSentryDispatchQueueWrapper() - let sut = SentryTimeToDisplayTracker(for: UIViewController(), waitForFullDisplay: true, dispatchQueueWrapper: dispatchQueueWrapper) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = SentryTimeToDisplayTracker(for: UIViewController(), options: fixture.options, dispatchQueueWrapper: dispatchQueueWrapper) let invocationsBefore = dispatchQueueWrapper.blockOnMainInvocations.count sut.reportFullyDisplayed() @@ -300,7 +306,7 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { let tracer = try fixture.getTracer() - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: false) + let sut = fixture.getSut(for: UIViewController()) sut.start(for: tracer) @@ -332,7 +338,7 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 7)) - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: false) + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) @@ -365,7 +371,8 @@ class SentryTimeToDisplayTrackerTest: XCTestCase { fixture.dateProvider.setDate(date: Date(timeIntervalSince1970: 7)) - let sut = fixture.getSut(for: UIViewController(), waitForFullDisplay: true) + fixture.options.enableTimeToFullDisplayTracing = true + let sut = fixture.getSut(for: UIViewController()) let tracer = try fixture.getTracer() sut.start(for: tracer) diff --git a/Tests/SentryTests/SentryHubTests.swift b/Tests/SentryTests/SentryHubTests.swift index ec2a6a90b1c..8a9f3c62035 100644 --- a/Tests/SentryTests/SentryHubTests.swift +++ b/Tests/SentryTests/SentryHubTests.swift @@ -833,7 +833,7 @@ class SentryHubTests: XCTestCase { fixture.options.enableTimeToFullDisplayTracing = true let sut = fixture.getSut(fixture.options) - let testTTDTracker = TestTimeToDisplayTracker() + let testTTDTracker = TestTimeToDisplayTracker(options: fixture.options) Dynamic(SentryUIViewControllerPerformanceTracker.shared).currentTTDTracker = testTTDTracker @@ -847,7 +847,7 @@ class SentryHubTests: XCTestCase { fixture.options.enableTimeToFullDisplayTracing = false let sut = fixture.getSut(fixture.options) - let testTTDTracker = TestTimeToDisplayTracker() + let testTTDTracker = TestTimeToDisplayTracker(options: fixture.options) Dynamic(SentryUIViewControllerPerformanceTracker.shared).currentTTDTracker = testTTDTracker @@ -1232,8 +1232,8 @@ class SentryHubTests: XCTestCase { #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) class TestTimeToDisplayTracker: SentryTimeToDisplayTracker { - init() { - super.init(for: UIViewController(), waitForFullDisplay: false, dispatchQueueWrapper: SentryDispatchQueueWrapper()) + init(options: Options) { + super.init(for: UIViewController(), options: options, dispatchQueueWrapper: SentryDispatchQueueWrapper()) } var registerFullDisplayCalled = false diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index d9f5a6a68c1..99e9e8b9217 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -622,7 +622,7 @@ class SentrySDKTests: XCTestCase { SentrySDK.start(options: fixture.options) - let testTTDTracker = TestTimeToDisplayTracker() + let testTTDTracker = TestTimeToDisplayTracker(options: fixture.options) Dynamic(SentryUIViewControllerPerformanceTracker.shared).currentTTDTracker = testTTDTracker