Skip to content

Commit

Permalink
feat(performance): add missing methods (#505)
Browse files Browse the repository at this point in the history
Remove record implementation from ios.
  • Loading branch information
ebarooni committed Dec 11, 2024
1 parent a83e826 commit b6ccc1f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
20 changes: 0 additions & 20 deletions packages/performance/ios/Plugin/FirebasePerformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,4 @@ import FirebasePerformance
@objc public static func getMetric(_ trace: Trace, _ metricName: String) -> Int64 {
return trace.valueForMetric(metricName)
}

@objc public func record(_ traceName: String, _ startTime: Double, _ duration: Double, _ attributes: [String: String], _ metrics: [String: Double]) {
let trace = getTraceByName(traceName)
let currentTime = Date().timeIntervalSince1970 * 1000
let startDelay = max(0, (startTime - currentTime) / 1000)

DispatchQueue.global().asyncAfter(deadline: .now() + startDelay) {
for (key, value) in attributes {
FirebasePerformance.putAttribute(trace!, key, value)
}
for (key, value) in metrics {
FirebasePerformance.putMetric(trace!, key, value)
}
self.startTrace(traceName)

DispatchQueue.global().asyncAfter(deadline: .now() + duration / 1000) {
self.stopTrace(traceName)
}
}
}
}
23 changes: 1 addition & 22 deletions packages/performance/ios/Plugin/FirebasePerformancePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,6 @@ public class FirebasePerformancePlugin: CAPPlugin {
}

@objc func record(_ call: CAPPluginCall) {
guard let traceName = call.getString("traceName") else {
call.reject(errorTraceNameMissing)
return
}
guard let startTime = call.getDouble("startTime") else {
call.reject(errorStartTimeMissing)
return
}
guard let duration = call.getDouble("duration") else {
call.reject(errorDurationMissing)
return
}
let options = call.getObject("options")
let metrics = options?["metrics"] as? [String: Double] ?? [:]
let attributes = options?["attributes"] as? [String: String] ?? [:]
let trace = implementation?.getTraceByName(traceName)
guard trace != nil else {
call.reject(errorTraceNotFound)
return
}
implementation?.record(traceName, startTime, duration, attributes, metrics)
call.resolve()
call.unimplemented("Not implemented on iOS.")
}
}

0 comments on commit b6ccc1f

Please sign in to comment.