Skip to content

Commit

Permalink
RUM-7085:Add compose session replay scenario for benchmark sample app…
Browse files Browse the repository at this point in the history
…lication
  • Loading branch information
ambushwork committed Nov 6, 2024
1 parent cd1b01e commit 9df10a1
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
8 changes: 8 additions & 0 deletions sample/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ android {
java17()
}

buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidXComposeRuntime.get()
}
val bmPassword = System.getenv("BM_STORE_PASSWD")
signingConfigs {
if (bmPassword != null) {
Expand Down Expand Up @@ -76,6 +82,8 @@ dependencies {
implementation(libs.googleMaterial)
implementation(libs.glideCore)
implementation(libs.timber)
implementation(platform(libs.androidXComposeBom))
implementation(libs.bundles.androidXCompose)
implementation(project(":features:dd-sdk-android-logs"))
implementation(project(":features:dd-sdk-android-rum"))
implementation(project(":features:dd-sdk-android-trace"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
package com.datadog.benchmark.sample

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.datadog.benchmark.sample.benchmark.DatadogBenchmark
import com.datadog.benchmark.sample.compose.MainView
import com.datadog.sample.benchmark.R

/**
Expand All @@ -22,10 +24,17 @@ class MainActivity : AppCompatActivity() {
private lateinit var datadogBenchmark: DatadogBenchmark
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

datadogBenchmark = DatadogBenchmark(
DatadogBenchmark.Config.resolveSyntheticsBundle(intent.extras)
)
if (datadogBenchmark.isComposeEnabled) {
setContent {
MainView()
}
} else {
setContentView(R.layout.activity_main)
}
}

override fun onStart() {
Expand All @@ -40,6 +49,8 @@ class MainActivity : AppCompatActivity() {

override fun onResume() {
super.onResume()
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
if (!datadogBenchmark.isComposeEnabled) {
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ internal class DatadogBenchmark(config: Config) {
.build()
)

val isComposeEnabled = config.scenario == SyntheticsScenario.SessionReplayCompose

init {
if (config.run == SyntheticsRun.Instrumented) {
when (config.scenario) {
SyntheticsScenario.SessionReplayCompose,
SyntheticsScenario.SessionReplay -> enableSessionReplay()
else -> {} // do nothing for now
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal enum class SyntheticsScenario(val value: String) {

SessionReplay("sr"),

SessionReplayCompose("sr_compose"),

Rum("rum"),

Trace("trace"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.benchmark.sample.compose

import androidx.compose.runtime.Composable

@Composable
internal fun MainView() {
// TODO RUM-7085: Add compose view
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.widget.ImageView
import android.widget.NumberPicker
import android.widget.Spinner
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment.findNavController
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.widget.ImageView
import android.widget.NumberPicker
import android.widget.Spinner
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment.findNavController
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class DatadogBenchmarkTest {
Assertions.assertThat(config.run).isEqualTo(SyntheticsRun.Instrumented)
}

@Test
fun `M build correct config W resolve bundle {scenario = 'sr_compose', run = 'instrumented'}`() {
whenever(mockedBundle.getString("synthetics.benchmark.scenario")).thenReturn("sr_compose")
whenever(mockedBundle.getString("synthetics.benchmark.run")).thenReturn("instrumented")

val config = DatadogBenchmark.Config.resolveSyntheticsBundle(mockedBundle)
Assertions.assertThat(config.scenario).isEqualTo(SyntheticsScenario.SessionReplayCompose)
Assertions.assertThat(config.run).isEqualTo(SyntheticsRun.Instrumented)
}

@Test
fun `M build empty config W resolve invalid bundle`() {
whenever(mockedBundle.getString("synthetics.benchmark.scenario")).thenReturn("")
Expand Down

0 comments on commit 9df10a1

Please sign in to comment.