Skip to content

Commit

Permalink
refactor: remove app info field
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed May 28, 2024
1 parent 319b76d commit 1d17239
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ internal fun verifySessionHappened(message: SessionMessage) {

internal fun verifySessionMessage(sessionMessage: SessionMessage) {
assertNotNull(sessionMessage.session)
assertNotNull(sessionMessage.appInfo)
assertNotNull(sessionMessage.deviceInfo)

if (sessionMessage.session.messageType == "en") {
Expand All @@ -226,7 +225,6 @@ internal fun verifyBgActivityHappened(message: SessionMessage) {

internal fun verifyBgActivityMessage(message: SessionMessage) {
assertNotNull(message.session)
assertNotNull(message.appInfo)
assertNotNull(message.deviceInfo)

if (message.session.messageType == "en") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk
import io.embrace.android.embracesdk.arch.schema.EmbType
import io.embrace.android.embracesdk.arch.schema.TelemetryType
import io.embrace.android.embracesdk.internal.payload.Log
import io.embrace.android.embracesdk.internal.payload.Span
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData
import io.embrace.android.embracesdk.internal.spans.hasFixedAttribute
import io.embrace.android.embracesdk.payload.SessionMessage
Expand Down Expand Up @@ -33,6 +34,15 @@ internal fun EmbraceSpanData.findSpanAttribute(key: String): String =
"Attribute not found: $key"
}


/**
* Finds the span attribute matching the name.
*/
internal fun Span.findSpanAttribute(key: String): String =
checkNotNull(attributes?.singleOrNull { it.key == key }?.data) {
"Attribute not found: $key"
}

/**
* Finds the event attribute matching the name.
*/
Expand Down Expand Up @@ -75,6 +85,15 @@ internal fun SessionMessage.findSpansOfType(telemetryType: TelemetryType): List<
"Spans of type not found: ${telemetryType.key}"
}

/**
* Finds the span matching the given [TelemetryType].
*/
internal fun SessionMessage.findSpansByName(name: String): List<Span> {
return checkNotNull(data?.spans?.filter { it.name == name }) {
"Spans not found named: $name"
}
}

internal fun SessionMessage.findSpanSnapshotsOfType(telemetryType: TelemetryType): List<EmbraceSpanData> =
checkNotNull(spanSnapshots?.filter { it.hasFixedAttribute(telemetryType) }) {
"Span snapshots of type not found: ${telemetryType.key}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.LogExceptionType
import io.embrace.android.embracesdk.assertions.assertOtelLogReceived
import io.embrace.android.embracesdk.fakes.FakeClock
import io.embrace.android.embracesdk.fakes.fakeV2OtelBehavior
import io.embrace.android.embracesdk.fakes.injection.FakeInitModule
import io.embrace.android.embracesdk.fakes.injection.FakeWorkerThreadModule
import io.embrace.android.embracesdk.findLogAttribute
import io.embrace.android.embracesdk.getLastSentLog
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.recordSession
import io.embrace.android.embracesdk.worker.WorkerName
import io.opentelemetry.api.logs.Severity
Expand All @@ -38,8 +40,8 @@ internal class FlutterInternalInterfaceTest {
appFramework = Embrace.AppFramework.FLUTTER,
overriddenClock = clock,
overriddenInitModule = fakeInitModule,
overriddenWorkerThreadModule = FakeWorkerThreadModule(fakeInitModule = fakeInitModule, name = WorkerName.REMOTE_LOGGING)
)
overriddenWorkerThreadModule = FakeWorkerThreadModule(fakeInitModule = fakeInitModule, name = WorkerName.REMOTE_LOGGING),
).apply { overriddenConfigService.oTelBehavior = fakeV2OtelBehavior() }
}

@Before
Expand All @@ -50,13 +52,11 @@ internal class FlutterInternalInterfaceTest {
@Test
fun `flutter without values should return defaults`() {
with(testRule) {
val session = harness.recordSession {

}

assertEquals(4, session?.appInfo?.appFramework)
assertNull(session?.appInfo?.hostedSdkVersion)
assertNull(session?.appInfo?.hostedPlatformVersion)
val session = harness.recordSession()
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.FLUTTER, res.appFramework)
assertNull(res.hostedSdkVersion)
assertNull(res.hostedPlatformVersion)
}
}

Expand All @@ -68,9 +68,10 @@ internal class FlutterInternalInterfaceTest {
embrace.flutterInternalInterface?.setEmbraceFlutterSdkVersion("1.2.3")
}

assertEquals(4, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.FLUTTER, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
}
}

Expand All @@ -86,9 +87,10 @@ internal class FlutterInternalInterfaceTest {

}

assertEquals(4, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.FLUTTER, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
}
}

Expand All @@ -105,9 +107,10 @@ internal class FlutterInternalInterfaceTest {
embrace.flutterInternalInterface?.setEmbraceFlutterSdkVersion(null)
}

assertEquals(4, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.FLUTTER, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
}
}

Expand All @@ -124,9 +127,10 @@ internal class FlutterInternalInterfaceTest {
embrace.flutterInternalInterface?.setEmbraceFlutterSdkVersion("1.2.4")
}

assertEquals(4, session?.appInfo?.appFramework)
assertEquals("28.9.2", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.4", checkNotNull(session?.appInfo?.hostedSdkVersion))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.FLUTTER, res.appFramework)
assertEquals("28.9.2", res.hostedPlatformVersion)
assertEquals("1.2.4", res.hostedSdkVersion)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
@file:Suppress("DEPRECATION")

package io.embrace.android.embracesdk.testcases

import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.arch.schema.EmbType
import io.embrace.android.embracesdk.fakes.fakeV2OtelBehavior
import io.embrace.android.embracesdk.findSpanAttribute
import io.embrace.android.embracesdk.findSpansByName
import io.embrace.android.embracesdk.findSpansOfType
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.clock.nanosToMillis
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
Expand All @@ -30,7 +31,9 @@ internal class ReactNativeInternalInterfaceTest {
@JvmField
val testRule: IntegrationTestRule = IntegrationTestRule(
harnessSupplier = {
IntegrationTestRule.Harness(appFramework = Embrace.AppFramework.REACT_NATIVE)
IntegrationTestRule.Harness(appFramework = Embrace.AppFramework.REACT_NATIVE).apply {
overriddenConfigService.oTelBehavior = fakeV2OtelBehavior()
}
}
)

Expand All @@ -46,10 +49,10 @@ internal class ReactNativeInternalInterfaceTest {

}

assertEquals(2, session?.appInfo?.appFramework)
assertNull(session?.appInfo?.reactNativeVersion)
assertNull(session?.appInfo?.hostedSdkVersion)
assertNull(session?.appInfo?.javaScriptPatchNumber)
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.REACT_NATIVE, res.appFramework)
assertNull(res.hostedPlatformVersion)
assertNull(res.javascriptPatchNumber)
}
}

Expand All @@ -62,10 +65,11 @@ internal class ReactNativeInternalInterfaceTest {
embrace.reactNativeInternalInterface?.setJavaScriptPatchNumber("666")
}

assertEquals(2, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.reactNativeVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
assertEquals("666", checkNotNull(session?.appInfo?.javaScriptPatchNumber))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.REACT_NATIVE, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
assertEquals("666", res.javascriptPatchNumber)
}
}

Expand All @@ -82,10 +86,11 @@ internal class ReactNativeInternalInterfaceTest {

}

assertEquals(2, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.reactNativeVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
assertEquals("666", checkNotNull(session?.appInfo?.javaScriptPatchNumber))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.REACT_NATIVE, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
assertEquals("666", res.javascriptPatchNumber)
}
}

Expand All @@ -104,10 +109,11 @@ internal class ReactNativeInternalInterfaceTest {
embrace.reactNativeInternalInterface?.setJavaScriptPatchNumber("999")
}

assertEquals(2, session?.appInfo?.appFramework)
assertEquals("28.9.2", checkNotNull(session?.appInfo?.reactNativeVersion))
assertEquals("1.2.4", checkNotNull(session?.appInfo?.hostedSdkVersion))
assertEquals("999", checkNotNull(session?.appInfo?.javaScriptPatchNumber))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.REACT_NATIVE, res.appFramework)
assertEquals("28.9.2", res.hostedPlatformVersion)
assertEquals("1.2.4", res.hostedSdkVersion)
assertEquals("999", res.javascriptPatchNumber)
}
}

Expand All @@ -125,21 +131,18 @@ internal class ReactNativeInternalInterfaceTest {
)
})

val spans = message.findSpansOfType(EmbType.System.ReactNativeAction)

val spans = message.findSpansByName("emb-rn-action")
assertEquals(1, spans.size)

val span = spans.single()

assertEquals("emb-rn-action", span.name)
assertEquals("sys.rn_action", span.findSpanAttribute("emb.type"))
assertEquals("MyAction", span.findSpanAttribute("name"))
assertEquals("SUCCESS", span.findSpanAttribute("outcome"))
assertEquals("100", span.findSpanAttribute("payload_size"))
assertEquals("value", span.findSpanAttribute("emb.properties.key"))
assertEquals(1000, span.startTimeNanos.nanosToMillis())
assertEquals(5000, span.endTimeNanos.nanosToMillis())

assertEquals(1000L, span.startTimeUnixNano?.nanosToMillis())
assertEquals(5000L, span.endTimeUnixNano?.nanosToMillis())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@file:Suppress("DEPRECATION")

package io.embrace.android.embracesdk.testcases

import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.fakes.fakeV2OtelBehavior
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
Expand All @@ -26,7 +26,9 @@ internal class UnityInternalInterfaceTest {
@JvmField
val testRule: IntegrationTestRule = IntegrationTestRule(
harnessSupplier = {
IntegrationTestRule.Harness(appFramework = Embrace.AppFramework.UNITY)
IntegrationTestRule.Harness(appFramework = Embrace.AppFramework.UNITY).apply {
overriddenConfigService.oTelBehavior = fakeV2OtelBehavior()
}
}
)

Expand All @@ -42,9 +44,10 @@ internal class UnityInternalInterfaceTest {

}

assertEquals(3, session?.appInfo?.appFramework)
assertNull(session?.appInfo?.hostedSdkVersion)
assertNull(session?.appInfo?.hostedPlatformVersion)
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.UNITY, res.appFramework)
assertNull(res.hostedSdkVersion)
assertNull(res.hostedPlatformVersion)
}
}

Expand All @@ -55,10 +58,11 @@ internal class UnityInternalInterfaceTest {
embrace.unityInternalInterface?.setUnityMetaData("28.9.1", "unity build id", "1.2.3")
}

assertEquals(3, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
assertEquals("unity build id", checkNotNull(session?.appInfo?.buildGuid))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.UNITY, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
assertEquals("unity build id", res.unityBuildId)
}
}

Expand All @@ -73,10 +77,11 @@ internal class UnityInternalInterfaceTest {

}

assertEquals(3, session?.appInfo?.appFramework)
assertEquals("28.9.1", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.3", checkNotNull(session?.appInfo?.hostedSdkVersion))
assertEquals("unity build id", checkNotNull(session?.appInfo?.buildGuid))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.UNITY, res.appFramework)
assertEquals("28.9.1", res.hostedPlatformVersion)
assertEquals("1.2.3", res.hostedSdkVersion)
assertEquals("unity build id", res.unityBuildId)
}
}

Expand All @@ -91,10 +96,11 @@ internal class UnityInternalInterfaceTest {
embrace.unityInternalInterface?.setUnityMetaData("28.9.2", "new unity build id", "1.2.4")
}

assertEquals(3, session?.appInfo?.appFramework)
assertEquals("28.9.2", checkNotNull(session?.appInfo?.hostedPlatformVersion))
assertEquals("1.2.4", checkNotNull(session?.appInfo?.hostedSdkVersion))
assertEquals("new unity build id", checkNotNull(session?.appInfo?.buildGuid))
val res = checkNotNull(session?.resource)
assertEquals(EnvelopeResource.AppFramework.UNITY, res.appFramework)
assertEquals("28.9.2", res.hostedPlatformVersion)
assertEquals("1.2.4", res.hostedSdkVersion)
assertEquals("new unity build id", res.unityBuildId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ internal data class SessionMessage @JvmOverloads internal constructor(
@Json(name = "s")
val session: Session,

/**
* The app information.
*/
@Json(name = "a")
val appInfo: AppInfo? = null,

/**
* The device information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ internal class V1PayloadMessageCollator(
}
spans
}

else -> spanSink.completedSpans()
}
// add ANR spans if the payload is capturing spans.
Expand All @@ -176,7 +177,6 @@ internal class V1PayloadMessageCollator(

return SessionMessage(
session = finalPayload,
appInfo = captureDataSafely(logger, metadataService::getAppInfo),
deviceInfo = captureDataSafely(logger, metadataService::getDeviceInfo),
performanceInfo = captureDataSafely(logger) {
performanceInfoService.getSessionPerformanceInfo(
Expand Down
Loading

0 comments on commit 1d17239

Please sign in to comment.