Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate thermal states to OTel #821

Merged
merged 11 commits into from
May 13, 2024
Prev Previous commit
Next Next commit
Merge branch 'master' into leandro/thermal_states
# Conflicts:
#	embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/arch/schema/SchemaType.kt
#	embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/DataSourceModule.kt
#	embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/injection/DataSourceModuleImplTest.kt
  • Loading branch information
leandro-godon committed May 13, 2024
commit c9606217c41ab0f94c116309b1ed2fbeee418025
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ internal sealed class SchemaType(
).toNonNullMap()
}

internal class ReactNativeAction(
name: String,
outcome: String,
payloadSize: Int,
properties: Map<String?, Any?>,
) : SchemaType(
telemetryType = EmbType.System.ReactNativeAction,
fixedObjectName = "rn-action"
) {
override val schemaAttributes = mapOf(
"name" to name,
"outcome" to outcome,
"payload_size" to payloadSize.toString(),
)
.plus(
properties
.mapKeys { it.key.toString().toSessionPropertyAttributeName() }
.mapValues { it.value.toString() }
)
.toNonNullMap()
}

internal class ThermalState(
status: Int
) : SchemaType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.embrace.android.embracesdk.internal.clock.Clock
import io.embrace.android.embracesdk.internal.spans.SpanService
import io.embrace.android.embracesdk.internal.utils.Provider
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.logging.EmbLogger
import io.embrace.android.embracesdk.spans.EmbraceSpan
import io.embrace.android.embracesdk.worker.BackgroundWorker
import io.embrace.android.embracesdk.worker.TaskPriority
Expand All @@ -23,7 +23,7 @@
@RequiresApi(Build.VERSION_CODES.Q)
internal class ThermalStateDataSource(
spanService: SpanService,
logger: InternalEmbraceLogger,
logger: EmbLogger,
private val backgroundWorker: BackgroundWorker,
private val clock: Clock,
powerManagerProvider: Provider<PowerManager?>
Expand All @@ -46,7 +46,7 @@
backgroundWorker.submit(TaskPriority.LOW) {
Systrace.traceSynchronous("thermal-service-registration") {
thermalStatusListener = PowerManager.OnThermalStatusChangedListener {
handleThermalStateChange(it)

Check warning on line 49 in embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/thermalstate/ThermalStateDataSource.kt

View check run for this annotation

Codecov / codecov/patch

embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/thermalstate/ThermalStateDataSource.kt#L49

Added line #L49 was not covered by tests
}
val pm = powerManager
if (pm != null) {
Expand All @@ -54,7 +54,7 @@
// to everything in the codebase so we decorate the BackgroundWorker here as an
// alternative
val executor = Executor {
backgroundWorker.submit(runnable = it)

Check warning on line 57 in embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/thermalstate/ThermalStateDataSource.kt

View check run for this annotation

Codecov / codecov/patch

embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/thermalstate/ThermalStateDataSource.kt#L57

Added line #L57 was not covered by tests
}
thermalStatusListener?.let {
pm.addThermalStatusListener(executor, it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal interface DataSourceModule {
val memoryWarningDataSource: DataSourceState<MemoryWarningDataSource>
val networkStatusDataSource: DataSourceState<NetworkStatusDataSource>
val sigquitDataSource: DataSourceState<SigquitDataSource>
val rnActionDataSource: DataSourceState<RnActionDataSource>
val thermalStateDataSource: DataSourceState<ThermalStateDataSource>?
}

Expand Down Expand Up @@ -214,6 +215,18 @@ internal class DataSourceModuleImpl(
)
}

override val rnActionDataSource: DataSourceState<RnActionDataSource> by dataSourceState {
DataSourceState(
factory = {
RnActionDataSource(
breadcrumbBehavior = configService.breadcrumbBehavior,
otelModule.spanService,
initModule.logger
)
}
)
}

override val thermalStateDataSource: DataSourceState<ThermalStateDataSource>? by dataSourceState {
DataSourceState(
factory = { thermalService },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.embrace.android.embracesdk.concurrency.BlockableExecutorService
import io.embrace.android.embracesdk.fakes.FakeClock
import io.embrace.android.embracesdk.fakes.FakeSpanService
import io.embrace.android.embracesdk.fakes.system.mockPowerManager
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.logging.EmbLoggerImpl
import io.embrace.android.embracesdk.worker.BackgroundWorker
import io.mockk.verify
import org.junit.Assert.assertEquals
Expand All @@ -25,7 +25,7 @@ internal class ThermalStateDataSourceTest {
spanWriter = FakeSpanService()
dataSource = ThermalStateDataSource(
spanWriter,
InternalEmbraceLogger(),
EmbLoggerImpl(),
BackgroundWorker(BlockableExecutorService()),
FakeClock(100),
) { mockPowerManager }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ internal class DataSourceModuleImplTest {
assertNotNull(module.memoryWarningDataSource)
assertNotNull(module.networkStatusDataSource)
assertNotNull(module.sigquitDataSource)
assertNotNull(module.rnActionDataSource)
assertNotNull(module.thermalStateDataSource)
assertEquals(12, module.getDataSources().size)
assertEquals(13, module.getDataSources().size)
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.