Skip to content

Commit 581d7ca

Browse files
Merge pull request #2689 from DataDog/aleksandr-gringauz/RUM-9511/rum-auto-scenario-benchmark-move-to-app-save
RUM-9511: RumAuto scenario for android benchmark app
2 parents faae92a + 415d233 commit 581d7ca

File tree

89 files changed

+4133
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4133
-270
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ buildscript {
3434
classpath(libs.unmockGradlePlugin)
3535
classpath(libs.sqlDelightGradlePlugin)
3636
classpath(libs.binaryCompatibilityGradlePlugin)
37+
classpath(libs.kotlinxSerializationPlugin)
3738
}
3839
}
3940

gradle/libs.versions.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ kotlinSP = "1.9.24-1.0.20"
55
gson = "2.10.1"
66
okHttp = "4.12.0"
77
kronosNTP = "0.0.1-alpha11"
8+
kotlinxSerialization = "1.6.3"
89

910
# Android
11+
adapterDelegates = "4.3.2"
1012
androidDesugaringSdk = "2.0.4"
1113
androidToolsPlugin = "8.9.1"
1214
androidXAnnotations = "1.9.1"
@@ -90,7 +92,7 @@ timber = "5.0.1"
9092
coroutines = "1.4.2"
9193

9294
# Local Server
93-
ktor = "1.6.8"
95+
ktor = "2.3.13"
9496
ktorServer = "3.0.0-rc-1"
9597

9698
# Otel
@@ -115,6 +117,7 @@ sqlDelightGradlePlugin = { module = "com.squareup.sqldelight:gradle-plugin", ver
115117
binaryCompatibilityGradlePlugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binaryCompatibility" }
116118
dependencyLicenseGradlePlugin = { module = "com.datadoghq:dependency-license", version.ref = "dependencyLicense" }
117119
versionsGradlePlugin = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "versionsGradlePlugin" }
120+
kotlinxSerializationPlugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin"}
118121

119122
# Annotation processors
120123
glideCompiler = { module = "com.github.bumptech.glide:compiler", version.ref = "glide" }
@@ -123,13 +126,15 @@ roomCompiler = { module = "androidx.room:room-compiler", version.ref = "room" }
123126
# Common
124127

125128
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
129+
kotlinxSerializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }
126130

127131
okHttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okHttp" }
128132
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
129133
kronosNTP = { module = "com.lyft.kronos:kronos-android", version.ref = "kronosNTP" }
130134
assertJ = { module = "org.assertj:assertj-core", version.ref = "assertJ" }
131135

132136
# Android libs
137+
adapterDelegatesViewBinding = { module = "com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding", version.ref = "adapterDelegates" }
133138
androidDesugaringSdk = { module = "com.android.tools:desugar_jdk_libs", version.ref = "androidDesugaringSdk" }
134139
androidXAnnotation = { module = "androidx.annotation:annotation", version.ref = "androidXAnnotations" }
135140
androidXAppCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidXAppCompat" }
@@ -239,11 +244,18 @@ coroutinesCore = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", ver
239244

240245
# Local Server
241246
ktorCore = { module = "io.ktor:ktor", version.ref = "ktor" }
242-
ktorGson = { module = "io.ktor:ktor-gson", version.ref = "ktor" }
247+
ktorGson = { module = "io.ktor:ktor-serialization-gson", version.ref = "ktor" }
243248
ktorServerCore = { module = "io.ktor:ktor-server-core", version.ref = "ktorServer" }
244249
ktorServerNetty = { module = "io.ktor:ktor-server-netty", version.ref = "ktorServer" }
245250
ktorServerSSE = { module = "io.ktor:ktor-server-sse", version.ref = "ktorServer" }
246251

252+
# ktor client
253+
ktorClientCore = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
254+
ktorClientOkHttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
255+
ktorContentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
256+
ktorSerializationKotlinxJson = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
257+
ktorClientMock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
258+
247259
# Otel
248260
jctools = { module = "org.jctools:jctools-core", version.ref = "jctools" }
249261
openTelemetryApi = { module = "io.opentelemetry:opentelemetry-api", version.ref = "openTelemetry" }
@@ -329,6 +341,12 @@ ktorServer = [
329341
"ktorServerNetty",
330342
"ktorServerSSE"
331343
]
344+
ktorClient = [
345+
"ktorClientCore",
346+
"ktorClientOkHttp",
347+
"ktorContentNegotiation",
348+
"ktorSerializationKotlinxJson"
349+
]
332350

333351
traceCore = [
334352
"jctools",

sample/benchmark/build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ plugins {
1010
id("com.android.application")
1111
kotlin("android")
1212
kotlin("kapt")
13+
kotlin("plugin.serialization")
14+
id("kotlin-parcelize")
1315
alias(libs.plugins.datadogGradlePlugin)
16+
id("transitiveDependencies")
1417
}
1518

1619
@Suppress("StringLiteralDuplication")
@@ -38,6 +41,7 @@ android {
3841

3942
buildFeatures {
4043
compose = true
44+
viewBinding = true
4145
}
4246
composeOptions {
4347
kotlinCompilerExtensionVersion = libs.versions.androidXComposeRuntime.get()
@@ -83,21 +87,25 @@ dependencies {
8387
implementation(libs.kotlin)
8488

8589
// Android dependencies
90+
implementation(libs.adapterDelegatesViewBinding)
8691
implementation(libs.androidXMultidex)
8792
implementation(libs.bundles.androidXNavigation)
8893
implementation(libs.androidXAppCompat)
8994
implementation(libs.androidXConstraintLayout)
9095
implementation(libs.androidXLifecycleCompose)
9196
implementation(libs.googleMaterial)
92-
implementation(libs.glideCore)
93-
implementation(libs.material3Android)
97+
implementation(libs.bundles.glide)
9498
implementation(libs.timber)
9599
implementation(platform(libs.androidXComposeBom))
100+
implementation(libs.material3Android)
96101
implementation(libs.bundles.androidXCompose)
97102
implementation(libs.coilCompose)
98103
implementation(libs.daggerLib)
99104
kapt(libs.daggerCompiler)
105+
kapt(libs.glideCompiler)
100106
implementation(libs.coroutinesCore)
107+
implementation(libs.bundles.ktorClient)
108+
implementation(libs.kotlinxSerializationJson)
101109
implementation(project(":features:dd-sdk-android-logs"))
102110
implementation(project(":features:dd-sdk-android-rum"))
103111
implementation(project(":features:dd-sdk-android-trace"))
@@ -108,11 +116,14 @@ dependencies {
108116
implementation(project(":features:dd-sdk-android-session-replay-material"))
109117
implementation(project(":features:dd-sdk-android-session-replay-compose"))
110118
implementation(project(":integrations:dd-sdk-android-compose"))
119+
implementation(project(":integrations:dd-sdk-android-glide"))
120+
implementation(project(":integrations:dd-sdk-android-okhttp"))
111121
implementation(project(":tools:benchmark"))
112122

113123
testImplementation(libs.bundles.jUnit5)
114124
testImplementation(libs.bundles.testTools)
115125
testImplementation(libs.systemStubsJupiter)
126+
testImplementation(libs.ktorClientMock)
116127
}
117128

118129
kotlinConfig()

sample/benchmark/src/main/AndroidManifest.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<uses-permission android:name="android.permission.INTERNET" />
55
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
6+
67
<application
78
android:name="com.datadog.benchmark.sample.BenchmarkApplication"
89
android:allowBackup="true"
@@ -12,10 +13,37 @@
1213
android:supportsRtl="true"
1314
android:theme="@style/Theme.BenchmarkApp">
1415
<activity
15-
android:name="com.datadog.benchmark.sample.MainActivity"
16+
android:name="com.datadog.benchmark.sample.activities.scenarios.DefaultScenarioActivity"
1617
android:exported="true"
1718
android:label="@string/app_name"
1819
android:theme="@style/Theme.BenchmarkApp">
20+
21+
</activity>
22+
23+
<activity
24+
android:name="com.datadog.benchmark.sample.activities.scenarios.RumAutoScenarioActivity"
25+
android:exported="true"
26+
android:theme="@style/Theme.BenchmarkApp">
27+
28+
</activity>
29+
30+
<activity
31+
android:name="com.datadog.benchmark.sample.activities.scenarios.SessionReplayComposeScenarioActivity"
32+
android:exported="true"
33+
android:theme="@style/Theme.BenchmarkApp">
34+
35+
</activity>
36+
37+
<activity
38+
android:name="com.datadog.benchmark.sample.activities.scenarios.SessionReplayScenarioActivity"
39+
android:exported="true"
40+
android:theme="@style/Theme.BenchmarkApp">
41+
42+
</activity>
43+
44+
<activity
45+
android:name="com.datadog.benchmark.sample.activities.LaunchActivity"
46+
android:exported="true">
1947
<intent-filter>
2048
<action android:name="android.intent.action.MAIN" />
2149

sample/benchmark/src/main/java/com/datadog/benchmark/sample/BenchmarkApplication.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package com.datadog.benchmark.sample
88

99
import android.app.Application
10+
import android.content.Context
1011
import com.datadog.benchmark.sample.di.app.BenchmarkAppComponent
1112
import com.datadog.benchmark.sample.di.app.DaggerBenchmarkAppComponent
1213

@@ -22,5 +23,5 @@ internal class BenchmarkApplication : Application() {
2223
}
2324
}
2425

25-
internal val Application.benchmarkAppComponent: BenchmarkAppComponent
26-
get() = (this as BenchmarkApplication).benchmarkAppComponent
26+
internal val Context.benchmarkAppComponent: BenchmarkAppComponent
27+
get() = (applicationContext as BenchmarkApplication).benchmarkAppComponent
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2016-Present Datadog, Inc.
5+
*/
6+
7+
package com.datadog.benchmark.sample
8+
9+
import com.datadog.benchmark.sample.config.BenchmarkConfig
10+
import javax.inject.Inject
11+
import javax.inject.Singleton
12+
13+
@Singleton
14+
internal class BenchmarkConfigHolder @Inject constructor() {
15+
lateinit var config: BenchmarkConfig
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2016-Present Datadog, Inc.
5+
*/
6+
7+
package com.datadog.benchmark.sample
8+
9+
import android.content.Context
10+
import com.bumptech.glide.Glide
11+
import com.bumptech.glide.Registry
12+
import com.bumptech.glide.annotation.GlideModule
13+
import com.datadog.android.glide.DatadogGlideModule
14+
import com.datadog.benchmark.sample.di.app.DATADOG_SDK_INSTANCE_NAME
15+
import okhttp3.OkHttpClient
16+
import javax.inject.Inject
17+
18+
@GlideModule
19+
internal class BenchmarkGlideModule : DatadogGlideModule(
20+
sdkInstanceName = DATADOG_SDK_INSTANCE_NAME
21+
) {
22+
@Inject
23+
lateinit var okHttpClient: OkHttpClient
24+
25+
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
26+
context.benchmarkAppComponent.inject(this)
27+
28+
super.registerComponents(context, glide, registry)
29+
}
30+
31+
override fun getClientBuilder(): OkHttpClient.Builder {
32+
return okHttpClient.newBuilder()
33+
}
34+
}

sample/benchmark/src/main/java/com/datadog/benchmark/sample/DatadogFeaturesInitializer.kt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.datadog.android.log.LogsConfiguration
1313
import com.datadog.android.rum.Rum
1414
import com.datadog.android.rum.RumConfiguration
1515
import com.datadog.android.rum.tracking.NavigationViewTrackingStrategy
16+
import com.datadog.android.rum.tracking.ViewTrackingStrategy
1617
import com.datadog.android.sessionreplay.SessionReplay
1718
import com.datadog.android.sessionreplay.SessionReplayConfiguration
1819
import com.datadog.android.sessionreplay.SessionReplayPrivacy
@@ -23,19 +24,19 @@ import com.datadog.android.trace.TraceConfiguration
2324
import com.datadog.benchmark.sample.config.BenchmarkConfig
2425
import com.datadog.benchmark.sample.config.SyntheticsRun
2526
import com.datadog.benchmark.sample.config.SyntheticsScenario
26-
import com.datadog.benchmark.sample.di.activity.BenchmarkActivityScope
2727
import com.datadog.benchmark.sample.navigation.BenchmarkNavigationPredicate
2828
import com.datadog.sample.benchmark.BuildConfig
2929
import com.datadog.sample.benchmark.R
3030
import dagger.Lazy
3131
import javax.inject.Inject
32+
import javax.inject.Singleton
3233

3334
/**
3435
* The general recommendation is to initialize all the components at the Application.onCreate
3536
* to have all the observability as early as possible. However in the Benchmark app we know what features
3637
* we need only in [MainActivity.onCreate], it depends on the [SyntheticsScenario] which is derived from intent extras.
3738
*/
38-
@BenchmarkActivityScope
39+
@Singleton
3940
@Suppress("TooManyFunctions")
4041
internal class DatadogFeaturesInitializer @Inject constructor(
4142
private val sdkCore: Lazy<SdkCore>
@@ -104,17 +105,7 @@ internal class DatadogFeaturesInitializer @Inject constructor(
104105

105106
private fun createRumConfiguration(config: BenchmarkConfig): RumConfiguration {
106107
return RumConfiguration.Builder(BuildConfig.BENCHMARK_RUM_APPLICATION_ID).apply {
107-
if (config.scenario != SyntheticsScenario.RumManual) {
108-
useViewTrackingStrategy(
109-
NavigationViewTrackingStrategy(
110-
R.id.nav_host_fragment,
111-
true,
112-
BenchmarkNavigationPredicate()
113-
)
114-
)
115-
} else {
116-
useViewTrackingStrategy(null)
117-
}
108+
useViewTrackingStrategy(rumViewTrackingStrategy(config))
118109
setTelemetrySampleRate(SAMPLE_RATE_TELEMETRY)
119110
trackUserInteractions()
120111
trackLongTasks(THRESHOLD_LONG_TASK_INTERVAL)
@@ -143,6 +134,17 @@ internal class DatadogFeaturesInitializer @Inject constructor(
143134
}.build()
144135
}
145136

137+
private fun rumViewTrackingStrategy(config: BenchmarkConfig): ViewTrackingStrategy? {
138+
return when (config.scenario) {
139+
SyntheticsScenario.RumManual -> null
140+
else -> NavigationViewTrackingStrategy(
141+
R.id.nav_host_fragment,
142+
true,
143+
BenchmarkNavigationPredicate()
144+
)
145+
}
146+
}
147+
146148
private fun enableRum(config: BenchmarkConfig) {
147149
val rumConfig = createRumConfiguration(config)
148150
Rum.enable(rumConfig, sdkCore = sdkCore.get())
@@ -156,10 +158,12 @@ internal class DatadogFeaturesInitializer @Inject constructor(
156158
SyntheticsScenario.Trace,
157159
SyntheticsScenario.LogsCustom,
158160
SyntheticsScenario.LogsHeavyTraffic,
161+
SyntheticsScenario.RumAuto,
159162
null -> false
160163
}
161164

162165
private fun isRumScenario(config: BenchmarkConfig) = when (config.scenario) {
166+
SyntheticsScenario.RumAuto,
163167
SyntheticsScenario.RumManual -> true
164168
SyntheticsScenario.SessionReplay,
165169
SyntheticsScenario.SessionReplayCompose,
@@ -178,6 +182,7 @@ internal class DatadogFeaturesInitializer @Inject constructor(
178182
SyntheticsScenario.RumManual,
179183
SyntheticsScenario.Trace,
180184
SyntheticsScenario.Upload,
185+
SyntheticsScenario.RumAuto,
181186
null -> false
182187
}
183188

0 commit comments

Comments
 (0)