From 1c50ee4d7b0a3576c30c24e6942ce28cb3c69bd9 Mon Sep 17 00:00:00 2001 From: Hongyan Jiang Date: Mon, 8 Apr 2024 19:37:48 -0700 Subject: [PATCH] add debugAllScreenNames property to assist developers tune up view names when autoCaptureScreenNames is set to true --- Changelog.md | 2 +- Dev/InstanaAgentExample/AppDelegate.swift | 4 +- .../PrivacyInfo_crash.xcprivacy | 46 ++++++++++++++++ .../PrivacyInfo_default.xcprivacy | 31 +++++++++++ Dev/ObjectiveCAppExample/AppDelegate.m | 30 +++++------ Dev/ObjectiveCAppExample/ViewController.m | 2 +- .../Beacons/Beacons Types/ViewChange.swift | 11 +++- .../Beacons/CoreBeacon/CoreBeacon.swift | 6 +-- .../Configuration/InstanaSession.swift | 26 ++++++++- Sources/InstanaAgent/Instana.swift | 31 ++++------- .../InstanaAgent/InstanaSetupOptions.swift | 25 ++++----- .../Extensions/UI.swift} | 54 ++++++++++++++----- .../Beacon Types/ViewChangeBeaconTests.swift | 50 ++++++++++------- Tests/InstanaAgentTests/InstanaTests.swift | 2 +- 14 files changed, 225 insertions(+), 95 deletions(-) create mode 100644 Dev/InstanaAgentExample/PrivacyInfo_crash.xcprivacy create mode 100644 Dev/InstanaAgentExample/PrivacyInfo_default.xcprivacy rename Sources/InstanaAgent/{Utils.swift => Utils/Extensions/UI.swift} (57%) diff --git a/Changelog.md b/Changelog.md index 553d79c..3498471 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,7 @@ # Changelog ## 1.7.0 -- introduce `autoCaptureScreenNames` and `autoViewCaptureAllowedClasses` for InstanaSetupOptions to auto capture view names +- introduce `autoCaptureScreenNames` to auto capture view names and `debugAllScreenNames` to debug all screen names ## 1.6.9 - Support CustomMetric field in reportEvent method diff --git a/Dev/InstanaAgentExample/AppDelegate.swift b/Dev/InstanaAgentExample/AppDelegate.swift index ae911f4..91d485c 100644 --- a/Dev/InstanaAgentExample/AppDelegate.swift +++ b/Dev/InstanaAgentExample/AppDelegate.swift @@ -21,8 +21,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let options = InstanaSetupOptions(enableCrashReporting: userYes) // options.slowSendInterval = 60.0 - options.autoCaptureScreenNames = AutoCaptureScreenNames.interestedUIViewControllers - options.autoViewCaptureAllowedClasses = ["ViewController", "TopRatedViewController", "WebViewController", "DetailViewController"] + options.autoCaptureScreenNames = true +// options.debugAllScreenNames = true if !Instana.setup(key: InstanaKey, reportingURL: InstanaURL, options: options) { os_log("Instana setup failed", log: myLog, type: .error) } diff --git a/Dev/InstanaAgentExample/PrivacyInfo_crash.xcprivacy b/Dev/InstanaAgentExample/PrivacyInfo_crash.xcprivacy new file mode 100644 index 0000000..864a07a --- /dev/null +++ b/Dev/InstanaAgentExample/PrivacyInfo_crash.xcprivacy @@ -0,0 +1,46 @@ + + + + + NSPrivacyTracking + + NSPrivacyTrackingDomains + + placeholder domain of INSTANA_REPORTING_URL + + NSPrivacyCollectedDataTypes + + + NSPrivacyCollectedDataType + NSPrivacyCollectedDataTypeCrashData + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAnalytics + + + + NSPrivacyAccessedAPITypes + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPITypeReasons + + DDA9.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryUserDefaults + NSPrivacyAccessedAPITypeReasons + + CA92.1 + + + + + diff --git a/Dev/InstanaAgentExample/PrivacyInfo_default.xcprivacy b/Dev/InstanaAgentExample/PrivacyInfo_default.xcprivacy new file mode 100644 index 0000000..c7f2668 --- /dev/null +++ b/Dev/InstanaAgentExample/PrivacyInfo_default.xcprivacy @@ -0,0 +1,31 @@ + + + + + NSPrivacyTracking + + NSPrivacyTrackingDomains + + placeholder domain of INSTANA_REPORTING_URL + + NSPrivacyAccessedAPITypes + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPITypeReasons + + DDA9.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryUserDefaults + NSPrivacyAccessedAPITypeReasons + + CA92.1 + + + + + diff --git a/Dev/ObjectiveCAppExample/AppDelegate.m b/Dev/ObjectiveCAppExample/AppDelegate.m index fc5d0c8..ef0804f 100644 --- a/Dev/ObjectiveCAppExample/AppDelegate.m +++ b/Dev/ObjectiveCAppExample/AppDelegate.m @@ -17,24 +17,22 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + InstanaSetupOptions* options = nil; + + //note: explicitly get user permission before setting enableCrashReporting to true +// options = [[InstanaSetupOptions alloc] initWithHttpCaptureConfig: 0 +// collectionEnabled: true +// enableCrashReporting: true +// suspendReportingOnLowBattery: true +// suspendReportingOnCellular: false +// slowSendInterval: 0.0 +// usiRefreshTimeIntervalInHrs: -1 +// autoCaptureScreenNames: true +// debugAllScreenNames: false]; + (void)[Instana setupWithKey: @"INSTANA_REPORTING_KEY" reportingURL: [NSURL URLWithString: @"INSTANA_REPORTING_URL"] - options: nil]; - -// NSArray *viewControllerClasses = @[@"ViewController"]; -// //note: explicitly get user permission before setting enableCrashReporting to true -// InstanaSetupOptions* options = [[InstanaSetupOptions alloc] initWithHttpCaptureConfig: 0 -// collectionEnabled: true -// enableCrashReporting: true -// suspendReportingOnLowBattery: true -// suspendReportingOnCellular: false -// slowSendInterval: 0.0 -// usiRefreshTimeIntervalInHrs: -1 -// autoCaptureScreenNames: 2 -// autoViewCaptureAllowedClasses: viewControllerClasses]; -// (void)[Instana setupWithKey: @"INSTANA_REPORTING_KEY" -// reportingURL: [NSURL URLWithString: @"INSTANA_REPORTING_URL"] -// options: options]; + options: options]; NSURL* url = [NSURL URLWithString: @"https://www.ibm.com/jp-ja"]; NSURLRequest* request = [NSURLRequest requestWithURL: url]; diff --git a/Dev/ObjectiveCAppExample/ViewController.m b/Dev/ObjectiveCAppExample/ViewController.m index dded6b6..f68d6b9 100644 --- a/Dev/ObjectiveCAppExample/ViewController.m +++ b/Dev/ObjectiveCAppExample/ViewController.m @@ -20,7 +20,7 @@ - (void)viewDidLoad { } -- (void)viewWillAppear:(BOOL)animated { +- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // [Instana setViewWithName:@"Objetive-C app View 1"]; } diff --git a/Sources/InstanaAgent/Beacons/Beacons Types/ViewChange.swift b/Sources/InstanaAgent/Beacons/Beacons Types/ViewChange.swift index f081320..c202a77 100644 --- a/Sources/InstanaAgent/Beacons/Beacons Types/ViewChange.swift +++ b/Sources/InstanaAgent/Beacons/Beacons Types/ViewChange.swift @@ -11,7 +11,8 @@ class ViewChange: Beacon { init(timestamp: Instana.Types.Milliseconds = Date().millisecondsSince1970, viewName: String? = nil, accessibilityLabel: String? = nil, - navigationItemTitle: String? = nil, className: String? = nil) { + navigationItemTitle: String? = nil, + className: String? = nil, isSwiftUI: Bool = false) { var canonicalName: String? = viewName var prefix = "" if accessibilityLabel != nil, !accessibilityLabel!.isEmpty { @@ -23,7 +24,13 @@ class ViewChange: Beacon { } self.className = className if self.className != nil { - canonicalName = prefix + "@" + self.className! + let debugAll = Instana.current?.session.debugAllScreenNames ?? false + if !isSwiftUI || debugAll { + canonicalName = prefix + "@" + self.className! + } else { + // SwiftUI class name is overwhelming, hide it if there is a prefix. + canonicalName = prefix.isEmpty ? "@\(self.className!)" : prefix + } } super.init(timestamp: timestamp, viewName: canonicalName) } diff --git a/Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift b/Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift index 9ff997e..ff16184 100644 --- a/Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift +++ b/Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift @@ -158,9 +158,9 @@ struct CoreBeacon: Codable { * Internal meta data key/value entries * * Will be converted at transmission to separated string prefixed by `im_` - * For example: `im_view.accessibilityLabel someLabel` - * For example: `im_view.navigationItemTitle someTitle` - * For example: `im_view.className JSONViewController` + * For example: `im_view.accLabel someLabel` + * For example: `im_view.navItemTitle someNavTitle` + * For example: `im_view.clsName JSONViewController` * * optional * max size 128, max key length 64, max value length 1024 diff --git a/Sources/InstanaAgent/Configuration/InstanaSession.swift b/Sources/InstanaAgent/Configuration/InstanaSession.swift index 5675c48..f2da972 100644 --- a/Sources/InstanaAgent/Configuration/InstanaSession.swift +++ b/Sources/InstanaAgent/Configuration/InstanaSession.swift @@ -3,6 +3,7 @@ // import Foundation +import UIKit class InstanaSession { /// The current Instana configuration @@ -34,19 +35,40 @@ class InstanaSession { let logger = InstanaLogger() /// Collecting and reporting can be disabled or enabled at any time - @Atomic var collectionEnabled: Bool + @Atomic var collectionEnabled: Bool { + didSet { + Self.processAutoCaptureScreenNames(collectionEnabled: collectionEnabled, acsn: autoCaptureScreenNames) + } + } - init(configuration: InstanaConfiguration, propertyHandler: InstanaPropertyHandler, sessionID: UUID = UUID(), collectionEnabled: Bool) { + @Atomic var autoCaptureScreenNames: Bool + @Atomic var debugAllScreenNames: Bool + + init(configuration: InstanaConfiguration, propertyHandler: InstanaPropertyHandler, sessionID: UUID = UUID(), + collectionEnabled: Bool, autoCaptureScreenNames: Bool = false, debugAllScreenNames: Bool = false) { self.configuration = configuration self.propertyHandler = propertyHandler self.collectionEnabled = collectionEnabled + self.autoCaptureScreenNames = autoCaptureScreenNames + self.debugAllScreenNames = debugAllScreenNames + Self.processAutoCaptureScreenNames(collectionEnabled: collectionEnabled, acsn: autoCaptureScreenNames) + previousSession = PreviousSession.readInPreviousSessionData() id = sessionID (userSessionID, usiStartTime) = InstanaSession.usiRetrieve(configuration) PreviousSession.persistSessionID(sid: sessionID) } + private static func processAutoCaptureScreenNames(collectionEnabled: Bool, acsn: Bool) { + if collectionEnabled && acsn { + // Automatically setView for Instana with current View Controller's + // class name (or accessibilityLabel / navigation title if they are set) + // when viewDidAppear method is called. + UIViewController.instanaSetViewAutomatically() + } + } + private func isSessionValid() -> Bool { // Do now allow user_session_id tracking if configuration.usiRefreshTimeIntervalInHrs == usiTrackingNotAllowed { diff --git a/Sources/InstanaAgent/Instana.swift b/Sources/InstanaAgent/Instana.swift index 2a3d70c..7cd5c07 100644 --- a/Sources/InstanaAgent/Instana.swift +++ b/Sources/InstanaAgent/Instana.swift @@ -3,9 +3,6 @@ // import Foundation -import UIKit - -// swiftlint:disable line_length /// Root object for the Instana agent. /// @@ -100,7 +97,9 @@ import UIKit var suspendReporting = InstanaConfiguration.SuspendReporting.defaults var slowSendInterval = 0.0 var usiRefreshTimeIntervalInHrs = defaultUsiRefreshTimeIntervalInHrs - var autoCaptureScreenNames: AutoCaptureScreenNames = .none + var autoCaptureScreenNames: Bool = false + var debugAllScreenNames: Bool = false + if let options = options { httpCaptureConfig = options.httpCaptureConfig collectionEnabled = options.collectionEnabled @@ -126,6 +125,7 @@ import UIKit usiRefreshTimeIntervalInHrs = options.usiRefreshTimeIntervalInHrs autoCaptureScreenNames = options.autoCaptureScreenNames + debugAllScreenNames = options.debugAllScreenNames } var hybridAgentId: String? @@ -144,21 +144,10 @@ import UIKit hybridAgentId: hybridAgentId, hybridAgentVersion: hybridAgentVersion) let session = InstanaSession(configuration: config, propertyHandler: InstanaPropertyHandler(), - collectionEnabled: collectionEnabled) + collectionEnabled: collectionEnabled, + autoCaptureScreenNames: autoCaptureScreenNames, + debugAllScreenNames: debugAllScreenNames) Instana.current = Instana(session: session) - - if autoCaptureScreenNames != AutoCaptureScreenNames.none { - typeAutoCaptureScreenNames = autoCaptureScreenNames - if autoCaptureScreenNames != AutoCaptureScreenNames.allUIViewControllers { - autoViewCaptureAllowedClasses = options!.autoViewCaptureAllowedClasses - } - // Automatically setView for Instana with current View Controller's - // class name (or accessibilityLabel / navigation title if they are set) - // when viewDidAppear method is called. - // Remove Instana.setView calls from all View Controllers that inherit from UIViewController - // otherwise the old approach interferes with this new approach. - UIViewController.instanaSetViewAutomatically() - } return true } @@ -426,7 +415,8 @@ import UIKit public func setViewInternal(name: String?, accessibilityLabel: String? = nil, navigationItemTitle: String? = nil, - className: String? = nil) { + className: String? = nil, + isSwiftUI: Bool = false) { guard let propertyHandler = Instana.current?.session.propertyHandler else { return } let isIdentical = propertyHandler.properties.view?.isSame(name: name, accessibilityLabel: accessibilityLabel, @@ -436,7 +426,8 @@ import UIKit let view = ViewChange(viewName: name, accessibilityLabel: accessibilityLabel, navigationItemTitle: navigationItemTitle, - className: className) + className: className, + isSwiftUI: isSwiftUI) propertyHandler.properties.view = view guard view.viewName != nil else { return } diff --git a/Sources/InstanaAgent/InstanaSetupOptions.swift b/Sources/InstanaAgent/InstanaSetupOptions.swift index 91a9483..d6de370 100644 --- a/Sources/InstanaAgent/InstanaSetupOptions.swift +++ b/Sources/InstanaAgent/InstanaSetupOptions.swift @@ -4,16 +4,6 @@ import Foundation -@objc public enum AutoCaptureScreenNames: Int { - /// Don't automatically capture any screen names - case none - /// Any class that derives from UIViewController with accessibilityLabel or navigationItem.title set is automatically captured. - /// If a UIViewController class name is passed through autoViewCaptureAllowedClasses array, it's also captured. - case interestedUIViewControllers - /// Any class that derives from UIViewController is automatically captured - case allUIViewControllers -} - @objc public class InstanaSetupOptions: NSObject { public var httpCaptureConfig: HTTPCaptureConfig public var collectionEnabled: Bool @@ -22,8 +12,13 @@ import Foundation public var suspendReportingOnCellular: Bool public var slowSendInterval: Instana.Types.Seconds public var usiRefreshTimeIntervalInHrs: Double - public var autoCaptureScreenNames: AutoCaptureScreenNames - public var autoViewCaptureAllowedClasses: [String] = [] + + // If autoCaptureScreenNames is set to true, we could leverage + // certain classes' properties and set active view name automatically. + // The class needs to derive from UIViewController directly or indirectly. + // Instana.setView is triggered on the instance's viewDidAppear call. + public var autoCaptureScreenNames: Bool + public var debugAllScreenNames: Bool /// Instana custom configuration for setup. /// @@ -40,8 +35,8 @@ import Foundation suspendReportingOnCellular: Bool = false, slowSendInterval: Instana.Types.Seconds = 0.0, usiRefreshTimeIntervalInHrs: Double = defaultUsiRefreshTimeIntervalInHrs, - autoCaptureScreenNames: AutoCaptureScreenNames = .none, - autoViewCaptureAllowedClasses: [String] = []) { + autoCaptureScreenNames: Bool = false, + debugAllScreenNames: Bool = false) { self.httpCaptureConfig = httpCaptureConfig self.collectionEnabled = collectionEnabled self.enableCrashReporting = enableCrashReporting @@ -50,7 +45,7 @@ import Foundation self.slowSendInterval = slowSendInterval self.usiRefreshTimeIntervalInHrs = usiRefreshTimeIntervalInHrs self.autoCaptureScreenNames = autoCaptureScreenNames - self.autoViewCaptureAllowedClasses = autoViewCaptureAllowedClasses + self.debugAllScreenNames = debugAllScreenNames } } diff --git a/Sources/InstanaAgent/Utils.swift b/Sources/InstanaAgent/Utils/Extensions/UI.swift similarity index 57% rename from Sources/InstanaAgent/Utils.swift rename to Sources/InstanaAgent/Utils/Extensions/UI.swift index c3066f3..e9f31fb 100644 --- a/Sources/InstanaAgent/Utils.swift +++ b/Sources/InstanaAgent/Utils/Extensions/UI.swift @@ -2,36 +2,53 @@ // Copyright © 2024 IBM Corp. All rights reserved. // -import Foundation import UIKit -var typeAutoCaptureScreenNames: AutoCaptureScreenNames = .none -var autoViewCaptureAllowedClasses: [String] = [] - extension UIViewController { @objc func instanaViewDidAppear(_ animated: Bool) { - let className = String(describing: type(of: self)) + let classType = type(of: self) + // If `class` belongs to SwiftUI framework + let isSwiftUI = Bundle(for: classType).isSwiftUI if allowCapture(accessibilityLabel: accessibilityLabel, navigationItemTitle: navigationItem.title, - className: className) { + class: classType, + isSwiftUI: isSwiftUI) { Instana.current?.setViewInternal(name: nil, accessibilityLabel: accessibilityLabel, navigationItemTitle: navigationItem.title, - className: className) + className: String(describing: classType), + isSwiftUI: isSwiftUI) } instanaViewDidAppear(animated) } - func allowCapture(accessibilityLabel: String?, navigationItemTitle: String?, className: String) -> Bool { - if typeAutoCaptureScreenNames == .none { return false } - if typeAutoCaptureScreenNames == .allUIViewControllers { return true } + func allowCapture(accessibilityLabel: String?, navigationItemTitle: String?, + class: AnyClass, isSwiftUI: Bool) -> Bool { + let localAcsn = Instana.current?.session.autoCaptureScreenNames + if localAcsn == nil || !localAcsn! { + // Auto view capture feature is disabled + return false + } + + if Instana.current!.session.debugAllScreenNames { + // Debug mode capture all + return true + } if accessibilityLabel != nil && !accessibilityLabel!.isEmpty || - navigationItemTitle != nil && !navigationItemTitle!.isEmpty { return true } - for allowedClass in autoViewCaptureAllowedClasses where allowedClass == className { + navigationItemTitle != nil && !navigationItemTitle!.isEmpty { return true } - return false + + guard !Bundle(for: `class`).isSystemBundle else { + // UIViewController not subclassed is deemed as system class and is not auto captured + return false + } + + // When no visible view name available, + // for SwiftUI, not capture; + // for UIKit, allow capture. + return !isSwiftUI } /// setView name for Instana with current UIViewController's class name when viewDidAppear method is called. @@ -56,3 +73,14 @@ extension UIViewController { } } } + +internal extension Bundle { + var isSystemBundle: Bool { + return bundleURL.lastPathComponent == "UIKitCore.framework" // iOS 12+ + || bundleURL.lastPathComponent == "UIKit.framework" // iOS 11 + } + + var isSwiftUI: Bool { + return bundleURL.lastPathComponent == "SwiftUI.framework" + } +} diff --git a/Tests/InstanaAgentTests/Beacons/Beacon Types/ViewChangeBeaconTests.swift b/Tests/InstanaAgentTests/Beacons/Beacon Types/ViewChangeBeaconTests.swift index acdd0a3..1010a37 100644 --- a/Tests/InstanaAgentTests/Beacons/Beacon Types/ViewChangeBeaconTests.swift +++ b/Tests/InstanaAgentTests/Beacons/Beacon Types/ViewChangeBeaconTests.swift @@ -6,6 +6,7 @@ class ViewChangeBeaconTests: InstanaTestCase { } let testVC = TestUIViewController() + let testClassType = type(of: TestUIViewController.self) let testClassName = String(describing: type(of: TestUIViewController.self)) let testTimestamp: Instana.Types.Milliseconds = Date.distantPast.millisecondsSince1970 @@ -15,8 +16,6 @@ class ViewChangeBeaconTests: InstanaTestCase { override func setUp() { super.setUp() - typeAutoCaptureScreenNames = .none - autoViewCaptureAllowedClasses = [] } func test_init_accessibilityLabel() { @@ -35,64 +34,77 @@ class ViewChangeBeaconTests: InstanaTestCase { XCTAssertEqual(vcBeacon.viewName!, "\(testNavItemTitle) @\(testClassName)") } - func test_allowCapture_none() { + func test_allowCapture_false() { // Given - typeAutoCaptureScreenNames = .none + Instana.current?.session.autoCaptureScreenNames = false + Instana.current?.session.debugAllScreenNames = false // When - let allowed = testVC.allowCapture(accessibilityLabel: testAcsbLabel, navigationItemTitle: testNavItemTitle, className: testClassName) + let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: nil, + class: TestUIViewController.self, isSwiftUI: false) // Then XCTAssertFalse(allowed) } func test_allowCapture_all() { // Given - typeAutoCaptureScreenNames = .allUIViewControllers + Instana.current?.session.autoCaptureScreenNames = true + Instana.current?.session.debugAllScreenNames = false // When - let allowed = testVC.allowCapture(accessibilityLabel: testAcsbLabel, navigationItemTitle: testNavItemTitle, className: "AnyClassName") + let allowed = testVC.allowCapture(accessibilityLabel: testAcsbLabel, + navigationItemTitle: testNavItemTitle, + class: TestUIViewController.self, + isSwiftUI: false) // Then XCTAssertTrue(allowed) } func test_allowCapture_accessibilityLabel() { // Given - typeAutoCaptureScreenNames = .interestedUIViewControllers + Instana.current?.session.autoCaptureScreenNames = true + Instana.current?.session.debugAllScreenNames = false // When - let allowed = testVC.allowCapture(accessibilityLabel: testAcsbLabel, navigationItemTitle: nil, className: "NotUsedClassName") + let allowed = testVC.allowCapture(accessibilityLabel: testAcsbLabel, navigationItemTitle: nil, + class: TestUIViewController.self, isSwiftUI: false) // Then XCTAssertTrue(allowed) } func test_allowCapture_navigationItemTitle() { // Given - typeAutoCaptureScreenNames = .interestedUIViewControllers + Instana.current?.session.autoCaptureScreenNames = true + Instana.current?.session.debugAllScreenNames = false // When - let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: testNavItemTitle, className: "NotUsedClassName") + let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: testNavItemTitle, + class: TestUIViewController.self, isSwiftUI: false) // Then XCTAssertTrue(allowed) } - func test_allowCapture_interestedUIViewControllers() { + func test_allowCapture_testClassUIViewControllers_debugAll() { // Given - typeAutoCaptureScreenNames = .interestedUIViewControllers - autoViewCaptureAllowedClasses = [testClassName] + Instana.current?.session.autoCaptureScreenNames = true + Instana.current?.session.debugAllScreenNames = true // When - let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: nil, className: testClassName) + let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: nil, + class: TestUIViewController.self, isSwiftUI: false) // Then XCTAssertTrue(allowed) } - func test_allowCapture_interestedUIViewControllers_negative() { + func test_allowCapture_testClassUIViewControllers_swiftUI() { // Given - typeAutoCaptureScreenNames = .interestedUIViewControllers + Instana.current?.session.autoCaptureScreenNames = true + Instana.current?.session.debugAllScreenNames = false // When - let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: nil, className: "NotUsedClassName") + let allowed = testVC.allowCapture(accessibilityLabel: nil, navigationItemTitle: nil, + class: TestUIViewController.self, /* not used */ + isSwiftUI: true) // Then XCTAssertFalse(allowed) } func test_instanaSetViewAutomatically() { // Given - typeAutoCaptureScreenNames = .allUIViewControllers UIViewController.instanaSetViewAutomatically() // When diff --git a/Tests/InstanaAgentTests/InstanaTests.swift b/Tests/InstanaAgentTests/InstanaTests.swift index 7170616..490f3a9 100644 --- a/Tests/InstanaAgentTests/InstanaTests.swift +++ b/Tests/InstanaAgentTests/InstanaTests.swift @@ -48,7 +48,7 @@ class InstanaTests: InstanaTestCase { options.suspendReportingOnLowBattery = true options.suspendReportingOnCellular = true options.slowSendInterval = 20.0 - options.autoCaptureScreenNames = AutoCaptureScreenNames.allUIViewControllers + options.autoCaptureScreenNames = false let ret = Instana.setup(key: key, reportingURL: reportingURL, options: options) // Then