Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: pass options object into SentryTimeToDisplayTracker #3989

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 3 additions & 2 deletions Sources/Sentry/SentryTimeToDisplayTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions Sources/Sentry/SentryUIViewControllerPerformanceTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,7 +27,9 @@

@end

@implementation SentryUIViewControllerPerformanceTracker
@implementation SentryUIViewControllerPerformanceTracker {
SentryOptions *_options;
}

+ (instancetype)shared
{
Expand All @@ -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];

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion Sources/Sentry/include/SentryTimeToDisplayTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#if SENTRY_HAS_UIKIT

@class SentryOptions;
@class SentrySpan;
@class SentryTracer;
@class SentryDispatchQueueWrapper;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#if SENTRY_HAS_UIKIT

@class SentryOptions;
@class SentrySpan;
@class SentryInAppLogic;
@class UIViewController;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Tests/SentryTests/SentryHubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentrySDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading