Skip to content

Commit

Permalink
Add optional CustomMetric field to Custom Beacon
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongyan Jiang authored and GitHub Enterprise committed Feb 19, 2024
1 parent ce5d2c6 commit 6d9cc37
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.6.9
- Support CustomMetric in reportEvent method

## 1.6.8
- Add more meta data to crash beacon
- Add more exceptionType processing to crash beacon
Expand Down
9 changes: 9 additions & 0 deletions Dev/ObjectiveCAppExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSURLRequest* request = [NSURLRequest requestWithURL: url];
[[[NSURLSession sharedSession] dataTaskWithRequest: request] resume];

[Instana reportEventWithName: @"testCustomEventName"
timestamp: NSNotFound
duration: NSNotFound
backendTracingID: nil
error: nil
meta: nil
viewName: nil
customMetric: NAN]; //"0x7fc00000"

return YES;
}

Expand Down
2 changes: 1 addition & 1 deletion InstanaAgent.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "InstanaAgent"
s.version = "1.6.8"
s.version = "1.6.9"
s.summary = "Instana iOS agent."

# This description is used to generate tags and improve search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ class CustomBeacon: Beacon {
let backendTracingID: String?
let error: Error?
let metaData: MetaData?
let customMetric: Double?

init(timestamp: Instana.Types.Milliseconds? = nil,
name: String,
duration: Instana.Types.Milliseconds? = nil,
backendTracingID: String? = nil,
error: Error? = nil,
metaData: MetaData? = nil,
viewName: String? = CustomBeaconDefaultViewNameID) {
viewName: String? = CustomBeaconDefaultViewNameID,
customMetric: Double? = nil) {
self.duration = duration
self.name = name
self.error = error
Expand All @@ -35,6 +37,7 @@ class CustomBeacon: Beacon {
if let timestamp = timestamp {
start = timestamp
}
self.customMetric = customMetric
super.init(timestamp: start, viewName: viewName)
}
}
7 changes: 7 additions & 0 deletions Sources/InstanaAgent/Beacons/CoreBeacon/CoreBeacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ struct CoreBeacon: Codable {
*/
var cen: String?

/**
* CustomMetric
*
* For example: "123.4567"
*/
var cm: String?

/**
* Meta for custom key/value entries
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ extension CoreBeacon {
if let tracingID = beacon.backendTracingID {
bt = tracingID
}
if let customMetric = beacon.customMetric {
cm = String(customMetric)
}
}

private mutating func add(error: Error) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/InstanaAgent/Configuration/VersionConfig.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
struct VersionConfig {
static let agentVersion = "1.6.8"
static let agentVersion = "1.6.9"
}
15 changes: 13 additions & 2 deletions Sources/InstanaAgent/Instana.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,30 @@ import Foundation
/// Alternatively you can leave out the parameter or send
/// nil to use the current view name implicitly you did set in `setView(name: String)`
@objc
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) {
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,
customMetric: Double = Double.nan) {
// As a workaround for primitive values in ObjC
let timestamp = timestamp == NSNotFound ? nil : timestamp
let duration = duration == NSNotFound ? nil : duration
var viewName = viewName ?? CustomBeaconDefaultViewNameID
viewName = !viewName.isEmpty ? viewName : CustomBeaconDefaultViewNameID

let customMetric: Double? = customMetric.isNaN ? nil : customMetric

let beacon = CustomBeacon(timestamp: timestamp,
name: name,
duration: duration,
backendTracingID: backendTracingID,
error: error,
metaData: meta,
viewName: viewName)
viewName: viewName,
customMetric: customMetric)
Instana.current?.monitors.reporter.submit(beacon)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CustomBeaconTests: InstanaTestCase {
let expectedCPU = InstanaSystemUtils.deviceModel
let expectedErrorType = "\(type(of: customBeacon.error!))"
let expectedErrorMessage = "\(customBeacon.error!)"
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))"
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))"
AssertEqualAndNotNil(sut, expected)
}

Expand Down Expand Up @@ -212,6 +212,9 @@ class CustomBeaconTests: InstanaTestCase {
let backendTracingID = "BID"
let error = SomeBeaconError.something
let metaData = ["Key": "SomeValue"]
return CustomBeacon(timestamp: timestamp, name: name, duration: duration, backendTracingID: backendTracingID, error: error, metaData: metaData, viewName: viewName)
let customMetric = 12.34567
return CustomBeacon(timestamp: timestamp, name: name, duration: duration,
backendTracingID: backendTracingID, error: error, metaData: metaData,
viewName: viewName, customMetric: customMetric)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CoreBeaconTests: InstanaTestCase {
let values = Mirror(reflecting: sut).children

// Then
XCTAssertEqual(values.count, 47)
XCTAssertEqual(values.count, 48)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class InstanaSystemUtilsTests: InstanaTestCase {

func test_AgentVersion() {
// Then
AssertTrue(InstanaSystemUtils.agentVersion == "1.6.8")
AssertTrue(InstanaSystemUtils.agentVersion == "1.6.9")
}

func test_systemVersion() {
Expand Down

0 comments on commit 6d9cc37

Please sign in to comment.