diff --git a/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.kt b/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.kt new file mode 100644 index 000000000..33f22e3af --- /dev/null +++ b/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.kt @@ -0,0 +1,123 @@ +package dev.gitlive.firebase.perf.metrics + +import com.google.firebase.perf.v1.NetworkRequestMetric +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseOptions +import dev.gitlive.firebase.apps +import dev.gitlive.firebase.initialize +import dev.gitlive.firebase.perf.FirebasePerformance +import dev.gitlive.firebase.perf.context +import dev.gitlive.firebase.perf.performance +import dev.gitlive.firebase.runBlockingTest +import kotlinx.coroutines.delay +import kotlinx.coroutines.test.runTest +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.time.Duration.Companion.seconds + +class AndroidHttpMetricTest { + + private lateinit var performance: FirebasePerformance + + companion object { + const val URL = "https://example.com" + val httpMethod = NetworkRequestMetric.HttpMethod.POST.name + } + + @BeforeTest + fun initializeFirebase() { + val app = Firebase.apps(context).firstOrNull() ?: Firebase.initialize( + context, + FirebaseOptions( + applicationId = "1:846484016111:ios:dd1f6688bad7af768c841a", + apiKey = "AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0", + databaseUrl = "https://fir-kotlin-sdk.firebaseio.com", + storageBucket = "fir-kotlin-sdk.appspot.com", + projectId = "fir-kotlin-sdk", + gcmSenderId = "846484016111", + ), + ) + + performance = Firebase.performance(app) + } + + @AfterTest + fun deinitializeFirebase() = runBlockingTest { + // Performance runs installation in the background, which crashes if the app is deleted before completion + delay(5.seconds) + Firebase.apps(context).forEach { + it.delete() + } + } + + @Test + fun testGetAttributes() = runTest { + val trace = performance.newHttpMetric(URL, httpMethod) + trace.start() + val values = listOf(1, 2, 3) + + values.forEach { + trace.putAttribute("Test_Get_Attributes_$it", "Test Get Attributes Value $it") + } + + val attributes = trace.getAttributes() + + assertEquals(3, attributes.size) + + // TODO: refactor? this should check if keys are same as you have placed and if values are same as you have placed + attributes.onEachIndexed { _, entry -> + assertEquals(entry.key.last(), entry.value.last()) + } + + trace.stop() + } + + @Test + fun testGetAttribute() = runTest { + val trace = performance.newHttpMetric(URL, httpMethod) + trace.start() + trace.putAttribute("Test_Get_Attribute", "Test Get Attribute Value") + + assertEquals("Test Get Attribute Value", trace.getAttribute("Test_Get_Attribute")) + trace.stop() + } + + @Test + fun testPutAttribute() = runTest { + val trace = performance.newHttpMetric(URL, httpMethod) + trace.start() + trace.putAttribute("Test_Put_Attribute", "Test Put Attribute Value") + + assertEquals("Test Put Attribute Value", trace.getAttribute("Test_Put_Attribute")) + trace.stop() + } + + @Test + fun testRemoveAttribute() = runTest { + val trace = performance.newHttpMetric(URL, httpMethod) + trace.start() + + trace.putAttribute("Test_Put_Attribute", "Test Put Attribute Value") + assertEquals("Test Put Attribute Value", trace.getAttribute("Test_Put_Attribute")) + + trace.removeAttribute("Test_Put_Attribute") + assertEquals(null, trace.getAttribute("Test_Put_Attribute")) + + trace.stop() + } + + @Test + fun testSettingHttpMetrics() = runTest { + val trace = performance.newHttpMetric(URL, httpMethod) + trace.start() + + trace.setHttpResponseCode(1) + trace.setRequestPayloadSize(10L) + trace.setResponseContentType("application/json") + trace.setResponsePayloadSize(44L) + + trace.stop() + } +} diff --git a/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index 5db4a766f..a1e5356d2 100644 --- a/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -60,8 +60,8 @@ class AndroidTraceTest { assertEquals(3, attributes.size) + // TODO: refactor? this should check if keys are same as you have placed and if values are same as you have placed attributes.onEachIndexed { _, entry -> - assertEquals(entry.key.last(), entry.value.last()) } @@ -87,4 +87,30 @@ class AndroidTraceTest { assertEquals("Test Put Attribute Value", trace.getAttribute("Test_Put_Attribute")) trace.stop() } + + @Test + fun testLongMetric() = runTest { + val trace = performance.newTrace("testLongMetric") + trace.start() + + trace.putMetric("Test_Put_Attribute", 3L) + trace.incrementMetric("Test_Put_Attribute", 1L) + + assertEquals(4L, trace.getLongMetric("Test_Put_Attribute")) + trace.stop() + } + + @Test + fun testRemoveAttribute() = runTest { + val trace = performance.newTrace("testRemoveAttribute") + trace.start() + + trace.putAttribute("Test_Put_Attribute", "Test Put Attribute Value") + assertEquals("Test Put Attribute Value", trace.getAttribute("Test_Put_Attribute")) + + trace.removeAttribute("Test_Put_Attribute") + assertEquals(null, trace.getAttribute("Test_Put_Attribute")) + + trace.stop() + } } diff --git a/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.android.kt b/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.android.kt new file mode 100644 index 000000000..f01640186 --- /dev/null +++ b/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.android.kt @@ -0,0 +1,46 @@ +package dev.gitlive.firebase.perf.metrics + +import com.google.firebase.perf.metrics.HttpMetric as AndroidHttpMetric + +public val HttpMetric.android: AndroidHttpMetric get() = android + +public actual class HttpMetric(internal val android: AndroidHttpMetric) { + public actual fun getAttribute(attribute: String): String? = android.getAttribute(attribute) + + public actual fun getAttributes(): Map = android.attributes + + public actual fun putAttribute(attribute: String, value: String) { + android.putAttribute(attribute, value) + } + + public actual fun removeAttribute(attribute: String) { + android.removeAttribute(attribute) + } + + public actual fun setHttpResponseCode(responseCode: Int) { + android.setHttpResponseCode(responseCode) + } + + public actual fun setRequestPayloadSize(bytes: Long) { + android.setRequestPayloadSize(bytes) + } + + public actual fun setResponseContentType(contentType: String) { + android.setResponseContentType(contentType) + } + + public actual fun setResponsePayloadSize(bytes: Long) { + android.setRequestPayloadSize(bytes) + } + + public actual fun start() { + android.start() + } + + public actual fun stop() { + android.stop() + } + + // TODO: android.markRequestComplete() + // TODO: android.markRequestStart() +} \ No newline at end of file diff --git a/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index dca1211cc..375af064f 100644 --- a/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -1,7 +1,7 @@ package dev.gitlive.firebase.perf.metrics -import com.google.firebase.perf.metrics.Trace as AndroidTrace import dev.gitlive.firebase.perf.session.PerfSession +import com.google.firebase.perf.metrics.Trace as AndroidTrace public val Trace.android: AndroidTrace get() = android @@ -25,15 +25,15 @@ public actual class Trace internal constructor(internal val android: AndroidTrac android.putMetric(metricName, value) } - public fun getAttributes(): Map = android.attributes + public actual fun getAttributes(): Map = android.attributes - public fun getAttribute(attribute: String): String? = android.getAttribute(attribute) + public actual fun getAttribute(attribute: String): String? = android.getAttribute(attribute) - public fun putAttribute(attribute: String, value: String) { + public actual fun putAttribute(attribute: String, value: String) { android.putAttribute(attribute, value) } - public fun removeAttribute(attribute: String) { + public actual fun removeAttribute(attribute: String) { android.removeAttribute(attribute) } diff --git a/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/performance.kt b/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/performance.kt index a4e4d3d47..13d7019b0 100644 --- a/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/performance.kt +++ b/firebase-perf/src/androidMain/kotlin/dev/gitlive/firebase/perf/performance.kt @@ -2,26 +2,29 @@ package dev.gitlive.firebase.perf import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp -import dev.gitlive.firebase.android as publicAndroid +import dev.gitlive.firebase.perf.metrics.HttpMetric import dev.gitlive.firebase.perf.metrics.Trace +import dev.gitlive.firebase.android as publicAndroid public val FirebasePerformance.android: com.google.firebase.perf.FirebasePerformance get() = com.google.firebase.perf.FirebasePerformance.getInstance() -public actual val Firebase.performance: FirebasePerformance get() = - FirebasePerformance(com.google.firebase.perf.FirebasePerformance.getInstance()) +public actual val Firebase.performance: FirebasePerformance + get() = + FirebasePerformance(com.google.firebase.perf.FirebasePerformance.getInstance()) public actual fun Firebase.performance(app: FirebaseApp): FirebasePerformance = FirebasePerformance(app.publicAndroid.get(com.google.firebase.perf.FirebasePerformance::class.java)) public actual class FirebasePerformance(internal val android: com.google.firebase.perf.FirebasePerformance) { + public actual fun isPerformanceCollectionEnabled(): Boolean = android.isPerformanceCollectionEnabled public actual fun newTrace(traceName: String): Trace = Trace(android.newTrace(traceName)) - public actual fun isPerformanceCollectionEnabled(): Boolean = android.isPerformanceCollectionEnabled - public actual fun setPerformanceCollectionEnabled(enable: Boolean) { android.isPerformanceCollectionEnabled = enable } + + public actual fun newHttpMetric(url: String, httpMethod: String): HttpMetric = HttpMetric(android.newHttpMetric(url, httpMethod)) } public actual open class FirebasePerformanceException(message: String) : com.google.firebase.FirebaseException(message) diff --git a/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.kt b/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.kt new file mode 100644 index 000000000..d19b2d16e --- /dev/null +++ b/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.kt @@ -0,0 +1,14 @@ +package dev.gitlive.firebase.perf.metrics + +public expect class HttpMetric { + public fun getAttribute(attribute: String): String? + public fun getAttributes(): Map + public fun putAttribute(attribute: String, value: String) + public fun removeAttribute(attribute: String) + public fun setHttpResponseCode(responseCode: Int) + public fun setRequestPayloadSize(bytes: Long) + public fun setResponseContentType(contentType: String) + public fun setResponsePayloadSize(bytes: Long) + public fun start() + public fun stop() +} \ No newline at end of file diff --git a/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index 81b4ed7c1..dc3ef9d9e 100644 --- a/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -2,11 +2,9 @@ package dev.gitlive.firebase.perf.metrics /** Trace allows you to set beginning and end of a certain action in your app. */ public expect class Trace { - /** Starts this trace. */ - public fun start() + public fun getAttribute(attribute: String): String? - /** Stops this trace. */ - public fun stop() + public fun getAttributes(): Map /** * Gets the value of the metric with the given name in the current trace. If a metric with the @@ -29,6 +27,8 @@ public expect class Trace { */ public fun incrementMetric(metricName: String, incrementBy: Long) + public fun putAttribute(attribute: String, value: String) + /** * Sets the value of the metric with the given name in this trace to the value provided. If a * metric with the given name doesn't exist, a new one will be created. If the trace has not been @@ -40,4 +40,12 @@ public expect class Trace { * @param value The value to which the metric should be set to. */ public fun putMetric(metricName: String, value: Long) + + public fun removeAttribute(attribute: String) + + /** Starts this trace. */ + public fun start() + + /** Stops this trace. */ + public fun stop() } diff --git a/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt b/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt index 5cf4f45c2..3866f9c0c 100644 --- a/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt +++ b/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt @@ -3,6 +3,7 @@ package dev.gitlive.firebase.perf import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.perf.metrics.HttpMetric import dev.gitlive.firebase.perf.metrics.Trace /** Returns the [FirebasePerformance] instance of the default [FirebaseApp]. */ @@ -20,14 +21,6 @@ public expect fun Firebase.performance(app: FirebaseApp): FirebasePerformance * to the Firebase backend. To stop sending performance events, call [setPerformanceCollectionEnabled] with value [false]. */ public expect class FirebasePerformance { - /** - * Creates a Trace object with given name. - * - * @param traceName name of the trace, requires no leading or trailing whitespace, no leading - * underscore '_' character. - * @return the new Trace object. - */ - public fun newTrace(traceName: String): Trace /** * Determines whether performance monitoring is enabled or disabled. This respects the Firebase @@ -40,6 +33,17 @@ public expect class FirebasePerformance { */ public fun isPerformanceCollectionEnabled(): Boolean + public fun newHttpMetric(url: String, httpMethod: String): HttpMetric + + /** + * Creates a Trace object with given name. + * + * @param traceName name of the trace, requires no leading or trailing whitespace, no leading + * underscore '_' character. + * @return the new Trace object. + */ + public fun newTrace(traceName: String): Trace + /** * Enables or disables performance monitoring. This setting is persisted and applied on future * invocations of your application. By default, performance monitoring is enabled. If you need to diff --git a/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt b/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt index 69d44b621..d049adb0e 100644 --- a/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt +++ b/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt @@ -11,10 +11,16 @@ import dev.gitlive.firebase.initialize import dev.gitlive.firebase.runBlockingTest import dev.gitlive.firebase.runTest import kotlinx.coroutines.delay -import kotlin.test.* +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertTrue import kotlin.time.Duration.Companion.seconds expect val context: Any + expect annotation class IgnoreForAndroidUnitTest() @IgnoreForAndroidUnitTest @@ -65,4 +71,6 @@ class FirebasePerformanceTest { assertTrue(performance.isPerformanceCollectionEnabled()) } + + // TODO: add new tests } diff --git a/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.ios.kt b/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.ios.kt new file mode 100644 index 000000000..7149cdd09 --- /dev/null +++ b/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.ios.kt @@ -0,0 +1,57 @@ +package dev.gitlive.firebase.perf.metrics + +import cocoapods.FirebasePerformance.FIRHTTPMetric +import cocoapods.FirebasePerformance.FIRHTTPMethod +import platform.Foundation.NSDictionary +import platform.Foundation.NSURL + +public val HttpMetric.ios: FIRHTTPMetric? get() = ios + +public actual class HttpMetric internal constructor( + internal val ios: FIRHTTPMetric? +) { + + public actual fun start() { + ios?.start() + } + + public actual fun stop() { + ios?.stop() + } + + public actual fun getAttribute(attribute: String): String? = + ios?.valueForAttribute(attribute) + + public actual fun getAttributes(): Map { + val attributesDict = ios?.attributes + return attributesDict?.let { dict -> + dict.keys.map { key -> + key.toString() to dict[key]?.toString().orEmpty() + }.toMap() + } ?: emptyMap() + } + + public actual fun putAttribute(attribute: String, value: String) { + ios?.setValue(value, attribute) + } + + public actual fun removeAttribute(attribute: String) { + ios?.removeAttribute(attribute) + } + + public actual fun setHttpResponseCode(responseCode: Int) { + ios?.responseCode = responseCode.toLong() + } + + public actual fun setRequestPayloadSize(bytes: Long) { + ios?.requestPayloadSize = bytes + } + + public actual fun setResponseContentType(contentType: String) { + ios?.responseContentType = contentType + } + + public actual fun setResponsePayloadSize(bytes: Long) { + ios?.responsePayloadSize = bytes + } +} diff --git a/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index 8e1e564ec..660a2d5fa 100644 --- a/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -23,4 +23,25 @@ public actual class Trace internal constructor(internal val ios: FIRTrace?) { public actual fun putMetric(metricName: String, value: Long) { ios?.setIntValue(value, metricName) } + + public actual fun getAttribute(attribute: String): String? { + return ios?.valueForAttribute(attribute) + } + + public actual fun getAttributes(): Map { + val attributesDict = ios?.attributes + return attributesDict?.let { dict -> + dict.keys.map { key -> + key.toString() to dict[key]?.toString().orEmpty() + }.toMap() + } ?: emptyMap() + } + + public actual fun putAttribute(attribute: String, value: String) { + ios?.setValue(value, attribute) + } + + public actual fun removeAttribute(attribute: String) { + ios?.removeAttribute(attribute) + } } diff --git a/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/performance.kt b/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/performance.kt index 527660077..8c21ee801 100644 --- a/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/performance.kt +++ b/firebase-perf/src/iosMain/kotlin/dev/gitlive/firebase/perf/performance.kt @@ -1,11 +1,14 @@ package dev.gitlive.firebase.perf import cocoapods.FirebasePerformance.FIRPerformance +import platform.Foundation.NSURL +import cocoapods.FirebasePerformance.FIRHTTPMetric +import cocoapods.FirebasePerformance.FIRHTTPMethod import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.perf.metrics.HttpMetric import dev.gitlive.firebase.perf.metrics.Trace - public val FirebasePerformance.ios: FIRPerformance get() = FIRPerformance.sharedInstance() public actual val Firebase.performance: FirebasePerformance get() = @@ -16,13 +19,20 @@ public actual fun Firebase.performance(app: FirebaseApp): FirebasePerformance = public actual class FirebasePerformance(internal val ios: FIRPerformance) { - public actual fun newTrace(traceName: String): Trace = Trace(ios.traceWithName(traceName)) - public actual fun isPerformanceCollectionEnabled(): Boolean = ios.isDataCollectionEnabled() public actual fun setPerformanceCollectionEnabled(enable: Boolean) { ios.dataCollectionEnabled = enable } + + public actual fun newTrace(traceName: String): Trace = Trace(ios.traceWithName(traceName)) + + public actual fun newHttpMetric(url: String, httpMethod: String): HttpMetric { + val nsUrl = NSURL(string = url) + val method = FIRHTTPMethod.valueOf(httpMethod.uppercase()) + val metric = FIRHTTPMetric(URL = nsUrl, HTTPMethod = method) + return HttpMetric(metric) + } } public actual open class FirebasePerformanceException(message: String) : FirebaseException(message) diff --git a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/externals/performance.kt b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/externals/performance.kt index c20ca6ebc..0a7574daa 100644 --- a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/externals/performance.kt +++ b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/externals/performance.kt @@ -24,4 +24,5 @@ public external interface PerformanceTrace { public fun removeAttribute(attr: String) public fun start() public fun stop() + // no record(startTime, duration, options) defined since it's specific for js } diff --git a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.js.kt b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.js.kt new file mode 100644 index 000000000..1e81198e0 --- /dev/null +++ b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.js.kt @@ -0,0 +1,43 @@ +package dev.gitlive.firebase.perf.metrics + +public actual class HttpMetric { + public actual fun getAttribute(attribute: String): String? { + error("Not supported in JS") + } + + public actual fun getAttributes(): Map { + error("Not supported in JS") + } + + public actual fun putAttribute(attribute: String, value: String) { + error("Not supported in JS") + } + + public actual fun removeAttribute(attribute: String) { + error("Not supported in JS") + } + + public actual fun setHttpResponseCode(responseCode: Int) { + error("Not supported in JS") + } + + public actual fun setRequestPayloadSize(bytes: Long) { + error("Not supported in JS") + } + + public actual fun setResponseContentType(contentType: String) { + error("Not supported in JS") + } + + public actual fun setResponsePayloadSize(bytes: Long) { + error("Not supported in JS") + } + + public actual fun start() { + error("Not supported in JS") + } + + public actual fun stop() { + error("Not supported in JS") + } +} \ No newline at end of file diff --git a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index fd0582711..d36e8470f 100644 --- a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -3,7 +3,7 @@ package dev.gitlive.firebase.perf.metrics import dev.gitlive.firebase.perf.externals.PerformanceTrace import dev.gitlive.firebase.perf.rethrow -public val Trace.js get() = js +public val Trace.js: PerformanceTrace get() = js public actual class Trace internal constructor(internal val js: PerformanceTrace) { @@ -12,7 +12,8 @@ public actual class Trace internal constructor(internal val js: PerformanceTrace public actual fun getLongMetric(metricName: String): Long = rethrow { js.getMetric(metricName).toLong() } public actual fun incrementMetric(metricName: String, incrementBy: Long): Unit = rethrow { js.incrementMetric(metricName, incrementBy.toInt()) } public actual fun putMetric(metricName: String, value: Long): Unit = rethrow { js.putMetric(metricName, value.toInt()) } - public fun getAttribute(attribute: String): String? = rethrow { js.getAttribute(attribute) } - public fun putAttribute(attribute: String, value: String): Unit = rethrow { js.putAttribute(attribute, value) } - public fun removeAttribute(attribute: String): Unit = rethrow { js.removeAttribute(attribute) } + public actual fun getAttribute(attribute: String): String? = rethrow { js.getAttribute(attribute) } + public actual fun putAttribute(attribute: String, value: String): Unit = rethrow { js.putAttribute(attribute, value) } + public actual fun removeAttribute(attribute: String): Unit = rethrow { js.removeAttribute(attribute) } + public actual fun getAttributes(): Map = rethrow { js.getAttributes() } } diff --git a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/performance.kt b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/performance.kt index be5144a10..940ce5d96 100644 --- a/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/performance.kt +++ b/firebase-perf/src/jsMain/kotlin/dev/gitlive/firebase/perf/performance.kt @@ -6,6 +6,7 @@ import dev.gitlive.firebase.FirebaseException import dev.gitlive.firebase.js import dev.gitlive.firebase.perf.externals.getPerformance import dev.gitlive.firebase.perf.externals.trace +import dev.gitlive.firebase.perf.metrics.HttpMetric import dev.gitlive.firebase.perf.metrics.Trace import dev.gitlive.firebase.perf.externals.FirebasePerformance as JsFirebasePerformance @@ -37,6 +38,10 @@ public actual class FirebasePerformance internal constructor(internal val js: Js public fun setInstrumentationEnabled(enable: Boolean) { js.instrumentationEnabled = enable } + + public actual fun newHttpMetric(url: String, httpMethod: String): HttpMetric { + return HttpMetric() + } } public actual open class FirebasePerformanceException(code: String, cause: Throwable) : FirebaseException(code, cause) diff --git a/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.jvm.kt b/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.jvm.kt new file mode 100644 index 000000000..86eee5505 --- /dev/null +++ b/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/HttpMetric.jvm.kt @@ -0,0 +1,43 @@ +package dev.gitlive.firebase.perf.metrics + +public actual class HttpMetric { + public actual fun getAttribute(attribute: String): String? { + error("Not supported in JVM") + } + + public actual fun getAttributes(): Map { + error("Not supported in JVM") + } + + public actual fun putAttribute(attribute: String, value: String) { + error("Not supported in JVM") + } + + public actual fun removeAttribute(attribute: String) { + error("Not supported in JVM") + } + + public actual fun setHttpResponseCode(responseCode: Int) { + error("Not supported in JVM") + } + + public actual fun setRequestPayloadSize(bytes: Long) { + error("Not supported in JVM") + } + + public actual fun setResponseContentType(contentType: String) { + error("Not supported in JVM") + } + + public actual fun setResponsePayloadSize(bytes: Long) { + error("Not supported in JVM") + } + + public actual fun start() { + error("Not supported in JVM") + } + + public actual fun stop() { + error("Not supported in JVM") + } +} \ No newline at end of file diff --git a/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.jvm.kt b/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.jvm.kt index 03144fc7c..e827f7365 100644 --- a/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.jvm.kt +++ b/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/metrics/Trace.jvm.kt @@ -2,18 +2,38 @@ package dev.gitlive.firebase.perf.metrics public actual class Trace { public actual fun start() { + error("Not supported in JVM") } public actual fun stop() { + error("Not supported in JVM") } public actual fun getLongMetric(metricName: String): Long { - TODO("Not yet implemented") + error("Not supported in JVM") } public actual fun incrementMetric(metricName: String, incrementBy: Long) { + error("Not supported in JVM") } public actual fun putMetric(metricName: String, value: Long) { + error("Not supported in JVM") + } + + public actual fun getAttribute(attribute: String): String? { + error("Not supported in JVM") + } + + public actual fun getAttributes(): Map { + error("Not supported in JVM") + } + + public actual fun putAttribute(attribute: String, value: String) { + error("Not supported in JVM") + } + + public actual fun removeAttribute(attribute: String) { + error("Not supported in JVM") } } diff --git a/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/performance.jvm.kt b/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/performance.jvm.kt index 486e96c44..d1d3c6ee4 100644 --- a/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/performance.jvm.kt +++ b/firebase-perf/src/jvmMain/kotlin/dev/gitlive/firebase/perf/performance.jvm.kt @@ -3,27 +3,33 @@ package dev.gitlive.firebase.perf import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.perf.metrics.HttpMetric import dev.gitlive.firebase.perf.metrics.Trace /** Returns the [FirebasePerformance] instance of the default [FirebaseApp]. */ public actual val Firebase.performance: FirebasePerformance - get() = TODO("Not yet implemented") + get() = error("Not supported in JVM") /** Returns the [FirebasePerformance] instance of a given [FirebaseApp]. */ public actual fun Firebase.performance(app: FirebaseApp): FirebasePerformance { - TODO("Not yet implemented") + error("Not supported in JVM") } public actual class FirebasePerformance { public actual fun newTrace(traceName: String): Trace { - TODO("Not yet implemented") + error("Not supported in JVM") } public actual fun isPerformanceCollectionEnabled(): Boolean { - TODO("Not yet implemented") + error("Not supported in JVM") } public actual fun setPerformanceCollectionEnabled(enable: Boolean) { + error("Not supported in JVM") + } + + public actual fun newHttpMetric(url: String, httpMethod: String): HttpMetric { + error("Not supported in JVM") } }