Skip to content

Commit 5f3c8a2

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
support trust device time configuration (#82)
1 parent ed0f7e9 commit 5f3c8a2

File tree

9 files changed

+39
-5
lines changed

9 files changed

+39
-5
lines changed

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.0
4+
- add `trustDeviceTiming` configuration option for backend to trust the device timing
45
- enable app launch time monitoring by default, other performance monitoring off
56

67
## 1.8.9

Dev/InstanaAgentExample/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3030
options.queryTrackedDomainList = queryTrackedDomainList
3131
// options.dropBeaconReporting = true
3232
// options.rateLimits = .MID_LIMITS
33+
// options.trustDeviceTiming = true
3334
// options.perfConfig = InstanaPerformanceConfig(enableAnrReport: true, anrThreshold: 5.0, enableLowMemoryReport: true)
3435
if !Instana.setup(key: InstanaKey, reportingURL: InstanaURL, options: options) {
3536
os_log("Instana setup failed", log: myLog, type: .error)

Dev/ObjectiveCAppExample/AppDelegate.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4141
debugAllScreenNames: false
4242
queryTrackedDomainList: queryTrackedDomainList
4343
dropBeaconReporting: false
44-
perfConfig: perfConfig];
44+
rateLimits: 0
45+
perfConfig: perfConfig
46+
trustDeviceTiming: false];
4547
*/
4648

4749
(void)[Instana setupWithKey: @"INSTANA_REPORTING_KEY"

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ struct CoreBeacon: Codable {
457457
*/
458458
var umb: String?
459459

460+
/**
461+
* Trust Device Timing
462+
*
463+
* Helps the backend determine whether to trust the device's time.
464+
* 1 means trust, nil means not trust.
465+
* nil is the default value.
466+
*
467+
* For example: 1
468+
*/
469+
var tdt: String?
470+
460471
/**
461472
* Crash Timestamp
462473
*

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeaconFactory.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CoreBeaconFactory {
4242
timestamp: beacon.timestamp,
4343
sid: session.id, usi: session.usi,
4444
id: beacon.id, mobileFeatures: mobileFeatures,
45+
trustDeviceTiming: conf.trustDeviceTiming,
4546
hybridAgentId: conf.hybridAgentId,
4647
hybridAgentVersion: conf.hybridAgentVersion)
4748
cbeacon.append(properties)
@@ -280,6 +281,7 @@ extension CoreBeacon {
280281
usi: UUID?,
281282
id: String,
282283
mobileFeatures: String?,
284+
trustDeviceTiming: Bool? = nil,
283285
hybridAgentId: String?,
284286
hybridAgentVersion: String?,
285287
connection: NetworkUtility.ConnectionType = InstanaSystemUtils.networkUtility.connectionType,
@@ -307,6 +309,7 @@ extension CoreBeacon {
307309
vh: String(Int(InstanaSystemUtils.screenSize.height)),
308310
cn: connection.cellular.carrierName,
309311
ct: connection.description,
310-
ect: ect?.description ?? connection.cellular.description)
312+
ect: ect?.description ?? connection.cellular.description,
313+
tdt: trustDeviceTiming.map { $0 ? "1" : nil } ?? nil)
311314
}
312315
}

Sources/InstanaAgent/Configuration/InstanaConfiguraton.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class InstanaConfiguration {
7373
var slowSendInterval: Instana.Types.Seconds
7474
var usiRefreshTimeIntervalInHrs: Double
7575
var anrThreshold: Double?
76+
var trustDeviceTiming: Bool?
7677
var reporterSendDebounce: Instana.Types.Seconds
7778
var reporterSendLowBatteryDebounce: Instana.Types.Seconds
7879
var maxRetries: Int
@@ -92,6 +93,7 @@ class InstanaConfiguration {
9293
usiRefreshTimeIntervalInHrs: Double,
9394
rateLimits: RateLimits?,
9495
perfConfig: InstanaPerformanceConfig? = nil,
96+
trustDeviceTiming: Bool? = nil,
9597
hybridAgentId: String?,
9698
hybridAgentVersion: String?) {
9799
self.reportingURL = reportingURL
@@ -127,6 +129,7 @@ class InstanaConfiguration {
127129
preQueueUsageTime = Defaults.preQueueUsageTime
128130
reporterRateLimits = Defaults.reporterRateLimits
129131
configRateLimit(rateLimits)
132+
self.trustDeviceTiming = trustDeviceTiming
130133
}
131134

132135
/**
@@ -167,6 +170,7 @@ class InstanaConfiguration {
167170
usiRefreshTimeIntervalInHrs: Double = defaultUsiRefreshTimeIntervalInHrs,
168171
rateLimits: RateLimits? = nil,
169172
perfConfig: InstanaPerformanceConfig? = nil,
173+
trustDeviceTiming: Bool? = nil,
170174
hybridAgentId: String? = nil,
171175
hybridAgentVersion: String? = nil)
172176
-> InstanaConfiguration {
@@ -177,6 +181,7 @@ class InstanaConfiguration {
177181
usiRefreshTimeIntervalInHrs: usiRefreshTimeIntervalInHrs,
178182
rateLimits: rateLimits,
179183
perfConfig: perfConfig,
184+
trustDeviceTiming: trustDeviceTiming,
180185
hybridAgentId: hybridAgentId,
181186
hybridAgentVersion: hybridAgentVersion)
182187
}

Sources/InstanaAgent/Instana.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import Foundation
102102
var dropBeaconReporting: Bool = false
103103
var rateLimits: RateLimits?
104104
var perfConfig: InstanaPerformanceConfig?
105+
var trustDeviceTiming: Bool?
105106

106107
if let options = options {
107108
httpCaptureConfig = options.httpCaptureConfig
@@ -132,6 +133,7 @@ import Foundation
132133
dropBeaconReporting = options.dropBeaconReporting
133134
rateLimits = options.rateLimits
134135
perfConfig = options.perfConfig
136+
trustDeviceTiming = options.trustDeviceTiming
135137
}
136138

137139
var hybridAgentId: String?
@@ -149,6 +151,7 @@ import Foundation
149151
usiRefreshTimeIntervalInHrs: usiRefreshTimeIntervalInHrs,
150152
rateLimits: rateLimits,
151153
perfConfig: perfConfig,
154+
trustDeviceTiming: trustDeviceTiming,
152155
hybridAgentId: hybridAgentId,
153156
hybridAgentVersion: hybridAgentVersion)
154157
let session = InstanaSession(configuration: config, propertyHandler: InstanaPropertyHandler(),

Sources/InstanaAgent/InstanaSetupOptions.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ import Foundation
2727

2828
@objc public var perfConfig: InstanaPerformanceConfig?
2929

30+
/**
31+
* When enabled, the backend will consider the device's (beacon creation) time as the actual time, rather than updating it to the ingestion time
32+
* (the time the beacon arrived at the server). If the beacon is received after 30 minutes, the ingestion time will be used instead.
33+
*/
34+
@objc public var trustDeviceTiming: Bool = false
35+
3036
/// Instana custom configuration for setup.
3137
///
3238
/// - Parameters:
@@ -47,7 +53,8 @@ import Foundation
4753
queryTrackedDomainList: [NSRegularExpression]? = nil,
4854
dropBeaconReporting: Bool = false,
4955
rateLimits: RateLimits = .DEFAULT_LIMITS,
50-
perfConfig: InstanaPerformanceConfig? = nil) {
56+
perfConfig: InstanaPerformanceConfig? = nil,
57+
trustDeviceTiming: Bool = false) {
5158
self.httpCaptureConfig = httpCaptureConfig
5259
self.collectionEnabled = collectionEnabled
5360
self.enableCrashReporting = enableCrashReporting
@@ -61,6 +68,7 @@ import Foundation
6168
self.dropBeaconReporting = dropBeaconReporting
6269
self.rateLimits = rateLimits
6370
self.perfConfig = perfConfig
71+
self.trustDeviceTiming = trustDeviceTiming
6472
super.init()
6573
}
6674

Tests/InstanaAgentTests/Beacons/CoreBeacon/CoreBeaconTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CoreBeaconTests: InstanaTestCase {
9797
let values = Mirror(reflecting: sut).children
9898

9999
// Then
100-
XCTAssertEqual(values.count, 56)
100+
XCTAssertEqual(values.count, 57)
101101
}
102102

103103
func testNumberOfFields_non_nil() {
@@ -120,7 +120,7 @@ class CoreBeaconTests: InstanaTestCase {
120120
"ue", "ul", "ab", "av", "p", "osn", "osv", "dma", "dmo", "ro", "vw", "vh",
121121
"im", "cn", "ct", "ect", "hu", "hp", "hm", "hs", "ebs", "dbs", "trs", "d",
122122
"ec", "em", "et", "agv", "cen", "cm", "h", "ast", "cid", "pst", "acs", "aws",
123-
"ahs", "mmb", "amb", "umb", "cti", "dt", "st"]
123+
"ahs", "mmb", "amb", "umb", "tdt", "cti", "dt", "st"]
124124
// When
125125
let keys = Mirror(reflecting: sut).children.compactMap {$0.label}
126126

0 commit comments

Comments
 (0)