Skip to content

Commit d792c1e

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
Increase beacon flush timeout interval to 2 minutes and also configurable (#101)
1 parent 018d094 commit d792c1e

22 files changed

Lines changed: 114 additions & 47 deletions

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.9.6
4+
- increase timeoutInterval for beacon flushing URLRequest to 2 minutes and also configurable
5+
36
## 1.9.5
47
- check network/battery condition before beacon flush to avoid beacon accidentally get deleted
58

Dev/InstanaAgentExample/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3333
// options.trustDeviceTiming = true
3434
// options.perfConfig = InstanaPerformanceConfig(enableAppStartTimeReport: false, enableAnrReport: true, anrThreshold: 5.0, enableLowMemoryReport: true, enableAppStateDetection: false)
3535
// options.enableW3CHeaders = true
36+
// options.timeoutInterval = 60.0
3637
if !Instana.setup(key: InstanaKey, reportingURL: InstanaURL, options: options) {
3738
os_log("Instana setup failed", log: myLog, type: .error)
3839
}
3940

4041
let headerFilterReg = try! NSRegularExpression(pattern: "Content-Type", options: .caseInsensitive)
4142
Instana.setCaptureHeaders(matching: [headerFilterReg])
4243

44+
Instana.setUser(id: "testUserId1", email: "test1@ibm.com", name:"testUserName1")
4345
return true
4446
}
4547

Dev/InstanaAgentExample/JSONViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class JSONViewController: UIViewController {
2727
override func viewDidAppear(_ animated: Bool) {
2828
super.viewDidAppear(animated)
2929
// Instana.setView(name: "JSONView")
30-
searchTextField.text = "https://www.ibm.com/de-de?abc=123&password=ps"
30+
// searchTextField.text = "https://www.ibm.com/de-de?abc=123&password=ps"
31+
searchTextField.text = "https://www.example.com"
3132
}
3233

3334
@IBAction func loadJSON() {

Dev/InstanaAgentExample/TopRatedViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TopRatedViewController: UITableViewController {
2323
}
2424

2525
override func viewWillAppear(_ animated: Bool) {
26+
super.viewWillAppear(animated)
2627
tableView.reloadData()
2728
}
2829

Dev/ObjectiveCAppExample/AppDelegate.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2929
[perfConfig setAnrThreshold: 5.0];
3030
[perfConfig setEnableAnrReport: true];
3131
32+
// note: explicitly get user permission before setting enableCrashReporting to true
33+
34+
// example 2
35+
options = [[InstanaSetupOptions alloc] init];
36+
options.enableCrashReporting = true;
37+
options.queryTrackedDomainList = queryTrackedDomainList;
38+
options.perfConfig = perfConfig;
3239
options.trustDeviceTiming = true;
3340
options.enableW3CHeaders = true;
3441
35-
// note: explicitly get user permission before setting enableCrashReporting to true
42+
// example 3
3643
options = [[InstanaSetupOptions alloc] initWithHttpCaptureConfig: 0
3744
collectionEnabled: true
3845
enableCrashReporting: true
@@ -47,7 +54,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4754
rateLimits: 0
4855
perfConfig: perfConfig
4956
trustDeviceTiming: false
50-
enableW3CHeaders: true];
57+
enableW3CHeaders: true
58+
deleteOldBeacons: false
59+
maxBeaconResendTries: 0 // no retry beacon send on failure
60+
timeoutInterval: 60.0
61+
];
5162
*/
5263

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

InstanaAgent.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "InstanaAgent"
19-
s.version = "1.9.5"
19+
s.version = "1.9.6"
2020
s.summary = "Instana iOS agent."
2121

2222
# This description is used to generate tags and improve search results.

Sources/InstanaAgent/Beacons/BeaconFlusher.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ class BeaconFlusher {
152152
return retryStep < config.maxRetries
153153
}
154154

155-
private func retry() {
156-
retryStep += 1
157-
queue.asyncAfter(deadline: .now() + .milliseconds(retryDelayMilliseconds(for: retryStep)), execute: flush)
158-
}
155+
// private func retry() {
156+
// retryStep += 1
157+
// queue.asyncAfter(deadline: .now() + .milliseconds(retryDelayMilliseconds(for: retryStep)), execute: flush)
158+
// }
159159

160160
private func complete() {
161161
if !errors.isEmpty, !sentBeacons.isEmpty {
@@ -213,6 +213,10 @@ class BeaconFlusher {
213213
urlRequest.httpMethod = "POST"
214214
urlRequest.addValue("text/plain", forHTTPHeaderField: "Content-Type")
215215

216+
// Default timeout interval 1 minute from URLRequest is too short for some networks.
217+
// Increase the interval to 2 minutes by default and also make it configurable to the app.
218+
urlRequest.timeoutInterval = config.timeoutInterval
219+
216220
let data = beacons.data(using: .utf8)
217221

218222
if config.gzipReport, let gzippedData = try? data?.gzipped(level: .bestCompression) {

Sources/InstanaAgent/Beacons/Reporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public class Reporter {
189189
return true
190190
}
191191

192-
let maxFlushingTimeAllowed = 100.0 // in seconds
192+
let maxFlushingTimeAllowed = session.configuration.timeoutInterval + 100.0 // in seconds
193193

194194
let diff = Date().timeIntervalSince1970 - lastFlushStartTime!
195195
if diff > maxFlushingTimeAllowed {

Sources/InstanaAgent/Configuration/Defines.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import Foundation
66

7+
// Default network timeout interval for posting beacons to Instana backend
8+
public let defaultTimeoutInterval = 120.0 // default to 2 minutes
9+
10+
// Default beacon send failure retry times
11+
public let defaultMaxBeaconResendTries = 2
12+
713
// Default user_session_id refresh time interval as negative number means never refresh
814
// ie. keep the same user_session_id forever
915
public let defaultUsiRefreshTimeIntervalInHrs: Double = -1.0

Sources/InstanaAgent/Configuration/InstanaConfiguraton.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class InstanaConfiguration {
7676
var trustDeviceTiming: Bool?
7777
var enableW3CHeaders: Bool?
7878
var deleteOldBeacons: Bool
79-
var maxBeaconResendTries: Int = 3
79+
var maxBeaconResendTries: Int
80+
var timeoutInterval: TimeInterval
8081
var enableAppStateDetection: Bool?
8182
var reporterSendDebounce: Instana.Types.Seconds
8283
var reporterSendLowBatteryDebounce: Instana.Types.Seconds
@@ -101,6 +102,7 @@ class InstanaConfiguration {
101102
enableW3CHeaders: Bool? = nil,
102103
deleteOldBeacons: Bool,
103104
maxBeaconResendTries: Int,
105+
timeoutInterval: TimeInterval,
104106
hybridAgentId: String?,
105107
hybridAgentVersion: String?) {
106108
self.reportingURL = reportingURL
@@ -142,6 +144,7 @@ class InstanaConfiguration {
142144
self.enableW3CHeaders = enableW3CHeaders
143145
self.deleteOldBeacons = deleteOldBeacons
144146
self.maxBeaconResendTries = maxBeaconResendTries
147+
self.timeoutInterval = timeoutInterval
145148
configRateLimit(rateLimits)
146149
}
147150

@@ -187,6 +190,7 @@ class InstanaConfiguration {
187190
enableW3CHeaders: Bool? = nil,
188191
deleteOldBeacons: Bool,
189192
maxBeaconResendTries: Int,
193+
timeoutInterval: TimeInterval,
190194
hybridAgentId: String? = nil,
191195
hybridAgentVersion: String? = nil)
192196
-> InstanaConfiguration {
@@ -201,6 +205,7 @@ class InstanaConfiguration {
201205
enableW3CHeaders: enableW3CHeaders,
202206
deleteOldBeacons: deleteOldBeacons,
203207
maxBeaconResendTries: maxBeaconResendTries,
208+
timeoutInterval: timeoutInterval,
204209
hybridAgentId: hybridAgentId,
205210
hybridAgentVersion: hybridAgentVersion)
206211
}

0 commit comments

Comments
 (0)