Skip to content

Commit 6d9cc37

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
Add optional CustomMetric field to Custom Beacon
1 parent ce5d2c6 commit 6d9cc37

File tree

11 files changed

+49
-10
lines changed

11 files changed

+49
-10
lines changed

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.6.9
4+
- Support CustomMetric in reportEvent method
5+
36
## 1.6.8
47
- Add more meta data to crash beacon
58
- Add more exceptionType processing to crash beacon

Dev/ObjectiveCAppExample/AppDelegate.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3737
NSURLRequest* request = [NSURLRequest requestWithURL: url];
3838
[[[NSURLSession sharedSession] dataTaskWithRequest: request] resume];
3939

40+
[Instana reportEventWithName: @"testCustomEventName"
41+
timestamp: NSNotFound
42+
duration: NSNotFound
43+
backendTracingID: nil
44+
error: nil
45+
meta: nil
46+
viewName: nil
47+
customMetric: NAN]; //"0x7fc00000"
48+
4049
return YES;
4150
}
4251

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.6.8"
19+
s.version = "1.6.9"
2020
s.summary = "Instana iOS agent."
2121

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

Sources/InstanaAgent/Beacons/Beacons Types/CustomBeacon.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class CustomBeacon: Beacon {
1515
let backendTracingID: String?
1616
let error: Error?
1717
let metaData: MetaData?
18+
let customMetric: Double?
1819

1920
init(timestamp: Instana.Types.Milliseconds? = nil,
2021
name: String,
2122
duration: Instana.Types.Milliseconds? = nil,
2223
backendTracingID: String? = nil,
2324
error: Error? = nil,
2425
metaData: MetaData? = nil,
25-
viewName: String? = CustomBeaconDefaultViewNameID) {
26+
viewName: String? = CustomBeaconDefaultViewNameID,
27+
customMetric: Double? = nil) {
2628
self.duration = duration
2729
self.name = name
2830
self.error = error
@@ -35,6 +37,7 @@ class CustomBeacon: Beacon {
3537
if let timestamp = timestamp {
3638
start = timestamp
3739
}
40+
self.customMetric = customMetric
3841
super.init(timestamp: start, viewName: viewName)
3942
}
4043
}

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ struct CoreBeacon: Codable {
125125
*/
126126
var cen: String?
127127

128+
/**
129+
* CustomMetric
130+
*
131+
* For example: "123.4567"
132+
*/
133+
var cm: String?
134+
128135
/**
129136
* Meta for custom key/value entries
130137
*

Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeaconFactory.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ extension CoreBeacon {
167167
if let tracingID = beacon.backendTracingID {
168168
bt = tracingID
169169
}
170+
if let customMetric = beacon.customMetric {
171+
cm = String(customMetric)
172+
}
170173
}
171174

172175
private mutating func add(error: Error) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
struct VersionConfig {
2-
static let agentVersion = "1.6.8"
2+
static let agentVersion = "1.6.9"
33
}

Sources/InstanaAgent/Instana.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,19 +435,30 @@ import Foundation
435435
/// Alternatively you can leave out the parameter or send
436436
/// nil to use the current view name implicitly you did set in `setView(name: String)`
437437
@objc
438-
public static func reportEvent(name: String, timestamp: Instana.Types.Milliseconds = Instana.Types.Milliseconds(NSNotFound), duration: Instana.Types.Milliseconds = Instana.Types.Milliseconds(NSNotFound), backendTracingID: String? = nil, error: Error? = nil, meta: [String: String]? = nil, viewName: String? = nil) {
438+
public static func reportEvent(name: String,
439+
timestamp: Instana.Types.Milliseconds = Instana.Types.Milliseconds(NSNotFound),
440+
duration: Instana.Types.Milliseconds = Instana.Types.Milliseconds(NSNotFound),
441+
backendTracingID: String? = nil,
442+
error: Error? = nil,
443+
meta: [String: String]? = nil,
444+
viewName: String? = nil,
445+
customMetric: Double = Double.nan) {
439446
// As a workaround for primitive values in ObjC
440447
let timestamp = timestamp == NSNotFound ? nil : timestamp
441448
let duration = duration == NSNotFound ? nil : duration
442449
var viewName = viewName ?? CustomBeaconDefaultViewNameID
443450
viewName = !viewName.isEmpty ? viewName : CustomBeaconDefaultViewNameID
451+
452+
let customMetric: Double? = customMetric.isNaN ? nil : customMetric
453+
444454
let beacon = CustomBeacon(timestamp: timestamp,
445455
name: name,
446456
duration: duration,
447457
backendTracingID: backendTracingID,
448458
error: error,
449459
metaData: meta,
450-
viewName: viewName)
460+
viewName: viewName,
461+
customMetric: customMetric)
451462
Instana.current?.monitors.reporter.submit(beacon)
452463
}
453464

Tests/InstanaAgentTests/Beacons/Beacon Types/CustomBeaconTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class CustomBeaconTests: InstanaTestCase {
114114
let expectedCPU = InstanaSystemUtils.deviceModel
115115
let expectedErrorType = "\(type(of: customBeacon.error!))"
116116
let expectedErrorMessage = "\(customBeacon.error!)"
117-
let expected = "ab\t\(beacon.ab)\nagv\t\(beacon.agv)\nav\t\(InstanaSystemUtils.applicationVersion)\nbi\t\(beacon.bi)\nbid\t\(beacon.bid)\nbt\t\(customBeacon.backendTracingID ?? "")\ncen\t\(customBeacon.name)\ncn\tNone\nct\t\(InstanaSystemUtils.networkUtility.connectionType.description)\nd\t\(customBeacon.duration ?? 0)\ndma\tApple\ndmo\t\(expectedCPU)\nec\t1\nem\t\(expectedErrorMessage)\net\t\(expectedErrorType)\nk\tKEY\nm_\(customBeacon.metaData?.keys.first ?? "")\t\(customBeacon.metaData?.values.first ?? "")\nosn\tiOS\nosv\t\(InstanaSystemUtils.systemVersion)\np\tiOS\nro\t\(String(InstanaSystemUtils.isDeviceJailbroken))\nsid\t\(beacon.sid)\nt\tcustom\nti\t\(customBeacon.timestamp)\nuf\tc\nul\ten\nusi\t\(mockedInstanaSession.usi!.uuidString)\nv\t\(customBeacon.viewName ?? "")\nvh\t\(Int(UIScreen.main.bounds.height))\nvw\t\(Int(UIScreen.main.bounds.width))"
117+
let expected = "ab\t\(beacon.ab)\nagv\t\(beacon.agv)\nav\t\(InstanaSystemUtils.applicationVersion)\nbi\t\(beacon.bi)\nbid\t\(beacon.bid)\nbt\t\(customBeacon.backendTracingID ?? "")\ncen\t\(customBeacon.name)\ncm\t12.34567\ncn\tNone\nct\t\(InstanaSystemUtils.networkUtility.connectionType.description)\nd\t\(customBeacon.duration ?? 0)\ndma\tApple\ndmo\t\(expectedCPU)\nec\t1\nem\t\(expectedErrorMessage)\net\t\(expectedErrorType)\nk\tKEY\nm_\(customBeacon.metaData?.keys.first ?? "")\t\(customBeacon.metaData?.values.first ?? "")\nosn\tiOS\nosv\t\(InstanaSystemUtils.systemVersion)\np\tiOS\nro\t\(String(InstanaSystemUtils.isDeviceJailbroken))\nsid\t\(beacon.sid)\nt\tcustom\nti\t\(customBeacon.timestamp)\nuf\tc\nul\ten\nusi\t\(mockedInstanaSession.usi!.uuidString)\nv\t\(customBeacon.viewName ?? "")\nvh\t\(Int(UIScreen.main.bounds.height))\nvw\t\(Int(UIScreen.main.bounds.width))"
118118
AssertEqualAndNotNil(sut, expected)
119119
}
120120

@@ -212,6 +212,9 @@ class CustomBeaconTests: InstanaTestCase {
212212
let backendTracingID = "BID"
213213
let error = SomeBeaconError.something
214214
let metaData = ["Key": "SomeValue"]
215-
return CustomBeacon(timestamp: timestamp, name: name, duration: duration, backendTracingID: backendTracingID, error: error, metaData: metaData, viewName: viewName)
215+
let customMetric = 12.34567
216+
return CustomBeacon(timestamp: timestamp, name: name, duration: duration,
217+
backendTracingID: backendTracingID, error: error, metaData: metaData,
218+
viewName: viewName, customMetric: customMetric)
216219
}
217220
}

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, 47)
100+
XCTAssertEqual(values.count, 48)
101101
}
102102

103103
func testNumberOfFields_non_nil() {
@@ -119,7 +119,7 @@ class CoreBeaconTests: InstanaTestCase {
119119
let expectedKeys = ["t", "v", "bt", "k" ,"ti", "sid", "usi", "bid", "uf", "bi", "m", "ui", "un",
120120
"ue", "ul", "ab", "av", "p", "osn", "osv", "dma", "dmo", "ro", "vw", "vh",
121121
"cn", "ct", "ect", "hu", "hp", "hm", "hs", "ebs", "dbs", "trs", "d",
122-
"ec", "em", "et", "agv", "cen", "h", "ast", "cid", "cti", "dt", "st"]
122+
"ec", "em", "et", "agv", "cen", "cm", "h", "ast", "cid", "cti", "dt", "st"]
123123
// When
124124
let keys = Mirror(reflecting: sut).children.compactMap {$0.label}
125125

0 commit comments

Comments
 (0)