Skip to content

Commit f63b9a9

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
make Current App State configurable and default to true (#90)
1 parent 0de994e commit f63b9a9

7 files changed

Lines changed: 59 additions & 30 deletions

File tree

.swiftpm/xcode/xcshareddata/xcschemes/InstanaAgent.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
3031
<Testables>
3132
<TestableReference
3233
skipped = "NO">

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## 1.9.2
4+
- enableAppStateDetection for performance configuration is default to true
45
- send screen rendering time along with viewChange beacon if autoCaptureScreenNames is set to true
56

67
## 1.9.1

Dev/InstanaAgentExample/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3131
// options.dropBeaconReporting = true
3232
// options.rateLimits = .MID_LIMITS
3333
// options.trustDeviceTiming = true
34-
// options.perfConfig = InstanaPerformanceConfig(enableAnrReport: true, anrThreshold: 5.0, enableLowMemoryReport: true)
34+
// options.perfConfig = InstanaPerformanceConfig(enableAppStartTimeReport: false, enableAnrReport: true, anrThreshold: 5.0, enableLowMemoryReport: true, enableAppStateDetection: false)
3535
// options.enableW3CHeaders = true
3636
if !Instana.setup(key: InstanaKey, reportingURL: InstanaURL, options: options) {
3737
os_log("Instana setup failed", log: myLog, type: .error)

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeaconFactory.swift

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class CoreBeaconFactory {
4747
id: beacon.id, mobileFeatures: mobileFeatures,
4848
trustDeviceTiming: conf.trustDeviceTiming,
4949
hybridAgentId: conf.hybridAgentId,
50-
hybridAgentVersion: conf.hybridAgentVersion)
50+
hybridAgentVersion: conf.hybridAgentVersion,
51+
enableAppStateDetection: conf.enableAppStateDetection)
5152
cbeacon.append(properties)
5253
switch beacon {
5354
case let item as HTTPBeacon:
@@ -292,32 +293,34 @@ extension CoreBeacon {
292293
hybridAgentId: String?,
293294
hybridAgentVersion: String?,
294295
connection: NetworkUtility.ConnectionType = InstanaSystemUtils.networkUtility.connectionType,
295-
ect: NetworkUtility.CellularType? = nil)
296+
ect: NetworkUtility.CellularType? = nil,
297+
enableAppStateDetection: Bool? = nil)
296298
-> CoreBeacon {
297-
CoreBeacon(v: viewName,
298-
k: key,
299-
ti: String(timestamp),
300-
sid: sid.uuidString,
301-
usi: usi?.uuidString,
302-
bid: id,
303-
uf: mobileFeatures,
304-
bi: InstanaSystemUtils.applicationBundleIdentifier,
305-
ul: Locale.current.languageCode,
306-
ab: InstanaSystemUtils.applicationBuildNumber,
307-
av: InstanaSystemUtils.applicationVersion,
308-
p: InstanaSystemUtils.systemName,
309-
osn: InstanaSystemUtils.systemName,
310-
osv: InstanaSystemUtils.systemVersion,
311-
dmo: InstanaSystemUtils.deviceModel,
312-
agv: CoreBeacon.getInstanaAgentVersion(hybridAgentId: hybridAgentId,
313-
hybridAgentVersion: hybridAgentVersion),
314-
ro: String(InstanaSystemUtils.isDeviceJailbroken),
315-
vw: String(Int(InstanaSystemUtils.screenSize.width)),
316-
vh: String(Int(InstanaSystemUtils.screenSize.height)),
317-
cn: connection.cellular.carrierName,
318-
ct: connection.description,
319-
ect: ect?.description ?? connection.cellular.description,
320-
tdt: trustDeviceTiming.map { $0 ? "1" : nil } ?? nil,
321-
cas: InstanaApplicationStateHandler.shared.getAppStateForBeacon())
299+
let cas = (enableAppStateDetection != false) ? InstanaApplicationStateHandler.shared.getAppStateForBeacon() : nil
300+
return CoreBeacon(v: viewName,
301+
k: key,
302+
ti: String(timestamp),
303+
sid: sid.uuidString,
304+
usi: usi?.uuidString,
305+
bid: id,
306+
uf: mobileFeatures,
307+
bi: InstanaSystemUtils.applicationBundleIdentifier,
308+
ul: Locale.current.languageCode,
309+
ab: InstanaSystemUtils.applicationBuildNumber,
310+
av: InstanaSystemUtils.applicationVersion,
311+
p: InstanaSystemUtils.systemName,
312+
osn: InstanaSystemUtils.systemName,
313+
osv: InstanaSystemUtils.systemVersion,
314+
dmo: InstanaSystemUtils.deviceModel,
315+
agv: CoreBeacon.getInstanaAgentVersion(hybridAgentId: hybridAgentId,
316+
hybridAgentVersion: hybridAgentVersion),
317+
ro: String(InstanaSystemUtils.isDeviceJailbroken),
318+
vw: String(Int(InstanaSystemUtils.screenSize.width)),
319+
vh: String(Int(InstanaSystemUtils.screenSize.height)),
320+
cn: connection.cellular.carrierName,
321+
ct: connection.description,
322+
ect: ect?.description ?? connection.cellular.description,
323+
tdt: trustDeviceTiming.map { $0 ? "1" : nil } ?? nil,
324+
cas: cas)
322325
}
323326
}

Sources/InstanaAgent/Configuration/InstanaConfiguraton.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class InstanaConfiguration {
7575
var anrThreshold: Double?
7676
var trustDeviceTiming: Bool?
7777
var enableW3CHeaders: Bool?
78+
var enableAppStateDetection: Bool?
7879
var reporterSendDebounce: Instana.Types.Seconds
7980
var reporterSendLowBatteryDebounce: Instana.Types.Seconds
8081
var maxRetries: Int
@@ -113,6 +114,9 @@ class InstanaConfiguration {
113114
anrThreshold = perfConfig!.anrThreshold
114115
monitorTypes.insert(.alertApplicationNotResponding(threshold: anrThreshold!))
115116
}
117+
if perfConfig?.enableAppStateDetection != nil {
118+
enableAppStateDetection = perfConfig!.enableAppStateDetection
119+
}
116120

117121
if enableCrashReporting {
118122
monitorTypes.insert(.crash)

Sources/InstanaAgent/InstanaSetupOptions.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ import Foundation
8787
var enableAnrReport: Bool = false
8888
var anrThreshold: Double = 3.0 // in seconds
8989
var enableLowMemoryReport: Bool = false
90+
var enableAppStateDetection: Bool = true
9091

9192
@objc public
9293
init(enableAppStartTimeReport: Bool = true, enableAnrReport: Bool = true,
93-
anrThreshold: Double = 3.0, enableLowMemoryReport: Bool = false) {
94+
anrThreshold: Double = 3.0, enableLowMemoryReport: Bool = false,
95+
enableAppStateDetection: Bool = true) {
9496
self.enableAppStartTimeReport = enableAppStartTimeReport
9597
self.enableAnrReport = enableAnrReport
9698
self.anrThreshold = anrThreshold
9799
self.enableLowMemoryReport = enableLowMemoryReport
100+
self.enableAppStateDetection = enableAppStateDetection
98101
super.init()
99102
}
100103

@@ -120,6 +123,11 @@ import Foundation
120123
func setEnableLowMemoryReport(_ enableLowMemoryReport: Bool) {
121124
self.enableLowMemoryReport = enableLowMemoryReport
122125
}
126+
127+
@objc public
128+
func setEnableAppStateDetection(_ enableAppStateDetection: Bool) {
129+
self.enableAppStateDetection = enableAppStateDetection
130+
}
123131
}
124132

125133
// Hybrid Agent options for setup

Tests/InstanaAgentTests/InstanaSetupOptionsTest.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ class InstanaPerformanceConfigTests: XCTestCase {
6565
AssertFalse(pfConfig.enableLowMemoryReport)
6666
}
6767

68+
func test_setEnableAppStateDetection() {
69+
// Given
70+
let pfConfig = InstanaPerformanceConfig()
71+
AssertTrue(pfConfig.enableAppStateDetection)
72+
73+
// When
74+
pfConfig.setEnableAppStateDetection(false)
75+
76+
// Then
77+
AssertFalse(pfConfig.enableAppStateDetection)
78+
}
79+
6880
func testInit_full() {
6981
let pfConfig = InstanaPerformanceConfig(enableAppStartTimeReport: true,
7082
enableAnrReport: true, anrThreshold: 2.0,

0 commit comments

Comments
 (0)