-
Notifications
You must be signed in to change notification settings - Fork 83
RUM-9508: LogsCustom scenario for android benchmark app #2625
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
Merged
aleksandr-gringauz
merged 3 commits into
develop
from
aleksandr-gringauz/RUM-9508/logs-scenarios
May 5, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
sample/benchmark/src/main/java/com/datadog/benchmark/sample/DatadogFeaturesInitializer.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import com.datadog.android.api.SdkCore | ||
| import com.datadog.android.compose.enableComposeActionTracking | ||
| import com.datadog.android.log.Logs | ||
| import com.datadog.android.log.LogsConfiguration | ||
| import com.datadog.android.rum.Rum | ||
| import com.datadog.android.rum.RumConfiguration | ||
| import com.datadog.android.rum.tracking.NavigationViewTrackingStrategy | ||
| import com.datadog.android.sessionreplay.SessionReplay | ||
| import com.datadog.android.sessionreplay.SessionReplayConfiguration | ||
| import com.datadog.android.sessionreplay.SessionReplayPrivacy | ||
| import com.datadog.android.sessionreplay.compose.ComposeExtensionSupport | ||
| import com.datadog.android.sessionreplay.material.MaterialExtensionSupport | ||
| import com.datadog.benchmark.sample.config.BenchmarkConfig | ||
| import com.datadog.benchmark.sample.config.SyntheticsRun | ||
| import com.datadog.benchmark.sample.config.SyntheticsScenario | ||
| import com.datadog.benchmark.sample.navigation.BenchmarkNavigationPredicate | ||
| import com.datadog.sample.benchmark.BuildConfig | ||
| import com.datadog.sample.benchmark.R | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| /** | ||
| * The general recommendation is to initialize all the components at the Application.onCreate | ||
| * to have all the observability as early as possible. However in the Benchmark app we know what features | ||
| * we need only in [MainActivity.onCreate], it depends on the [SyntheticsScenario] which is derived from intent extras. | ||
| */ | ||
| @Singleton | ||
| @Suppress("TooManyFunctions") | ||
| internal class DatadogFeaturesInitializer @Inject constructor( | ||
| private val sdkCore: SdkCore | ||
| ) { | ||
| private var isInitialized = false | ||
| fun initialize(config: BenchmarkConfig) { | ||
| if (isInitialized) { | ||
| return | ||
| } | ||
| isInitialized = true | ||
|
|
||
| if (needToEnableRum(config)) { | ||
| enableRum() | ||
| } | ||
|
|
||
| if (needToEnableLogs(config)) { | ||
| enableLogs() | ||
| } | ||
|
|
||
| if (needToEnableSessionReplay(config)) { | ||
| enableSessionReplay() | ||
| } | ||
| } | ||
|
|
||
| private fun needToEnableSessionReplay(config: BenchmarkConfig): Boolean { | ||
| return isInstrumentedRun(config) && isSessionReplayScenario(config) | ||
| } | ||
|
|
||
| @Suppress("DEPRECATION") | ||
| private fun enableSessionReplay() { | ||
| val sessionReplayConfig = SessionReplayConfiguration | ||
| .Builder(SAMPLE_IN_ALL_SESSIONS) | ||
| .setPrivacy(SessionReplayPrivacy.ALLOW) | ||
| .addExtensionSupport(MaterialExtensionSupport()) | ||
| .addExtensionSupport(ComposeExtensionSupport()) | ||
| .build() | ||
|
|
||
| SessionReplay.enable(sessionReplayConfig, sdkCore) | ||
| } | ||
|
|
||
| private fun needToEnableLogs(config: BenchmarkConfig): Boolean { | ||
| return isInstrumentedRun(config) && isLogsScenario(config) | ||
| } | ||
|
|
||
| private fun enableLogs() { | ||
| val logsConfig = LogsConfiguration.Builder().build() | ||
| Logs.enable(logsConfig, sdkCore) | ||
| } | ||
|
|
||
| private fun needToEnableRum(config: BenchmarkConfig): Boolean { | ||
| return when (isInstrumentedRun(config)) { | ||
| true -> isSessionReplayScenario(config) || isRumScenario(config) | ||
| false -> isSessionReplayScenario(config) | ||
| } | ||
| } | ||
|
|
||
| private fun createRumConfiguration(): RumConfiguration { | ||
| return RumConfiguration.Builder(BuildConfig.BENCHMARK_RUM_APPLICATION_ID) | ||
| .useViewTrackingStrategy( | ||
| NavigationViewTrackingStrategy( | ||
| R.id.nav_host_fragment, | ||
| true, | ||
| BenchmarkNavigationPredicate() | ||
| ) | ||
| ) | ||
| .setTelemetrySampleRate(SAMPLE_RATE_TELEMETRY) | ||
| .trackUserInteractions() | ||
| .trackLongTasks(THRESHOLD_LONG_TASK_INTERVAL) | ||
| .trackNonFatalAnrs(true) | ||
| .setViewEventMapper { event -> | ||
| event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's this attribute used for ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| event | ||
| } | ||
| .setActionEventMapper { event -> | ||
| event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true) | ||
| event | ||
| } | ||
| .setResourceEventMapper { event -> | ||
| event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true) | ||
| event | ||
| } | ||
| .setErrorEventMapper { event -> | ||
| event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true) | ||
| event | ||
| } | ||
| .setLongTaskEventMapper { event -> | ||
| event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true) | ||
| event | ||
| } | ||
| .enableComposeActionTracking() | ||
| .build() | ||
| } | ||
|
|
||
| private fun enableRum() { | ||
| val rumConfig = createRumConfiguration() | ||
| Rum.enable(rumConfig, sdkCore = sdkCore) | ||
| } | ||
|
|
||
| private fun isSessionReplayScenario(config: BenchmarkConfig) = when (config.scenario) { | ||
| SyntheticsScenario.SessionReplayCompose, | ||
| SyntheticsScenario.Upload, | ||
| SyntheticsScenario.SessionReplay -> true | ||
| SyntheticsScenario.Rum, | ||
| SyntheticsScenario.Trace, | ||
| SyntheticsScenario.LogsCustom, | ||
| SyntheticsScenario.LogsHeavyTraffic, | ||
| null -> false | ||
| } | ||
|
|
||
| private fun isRumScenario(config: BenchmarkConfig) = when (config.scenario) { | ||
| SyntheticsScenario.Rum -> true | ||
| SyntheticsScenario.SessionReplay, | ||
| SyntheticsScenario.SessionReplayCompose, | ||
| SyntheticsScenario.Trace, | ||
| SyntheticsScenario.LogsCustom, | ||
| SyntheticsScenario.LogsHeavyTraffic, | ||
| SyntheticsScenario.Upload, | ||
| null -> false | ||
| } | ||
|
|
||
| private fun isLogsScenario(config: BenchmarkConfig) = when (config.scenario) { | ||
| SyntheticsScenario.LogsCustom, | ||
| SyntheticsScenario.LogsHeavyTraffic -> true | ||
| SyntheticsScenario.SessionReplay, | ||
| SyntheticsScenario.SessionReplayCompose, | ||
| SyntheticsScenario.Rum, | ||
| SyntheticsScenario.Trace, | ||
| SyntheticsScenario.Upload, | ||
| null -> false | ||
| } | ||
|
|
||
| private fun isInstrumentedRun(config: BenchmarkConfig) = config.run == SyntheticsRun.Instrumented | ||
|
|
||
| companion object { | ||
| private const val SAMPLE_IN_ALL_SESSIONS = 100f | ||
| private const val ATTR_IS_MAPPED = "is_mapped" | ||
| private const val SAMPLE_RATE_TELEMETRY = 100f | ||
| private const val THRESHOLD_LONG_TASK_INTERVAL = 250L | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integrated dagger in the benchmark app. If anyone has any objections - tell me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it doesn't bring a dramatic compilation time penalty, I'm personally okay with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark app is a small app that compiles very fast. Dagger might add something, but it is not noticeable (I didn't measure, just describe the feeling) and will not be in any foreseeable future.
The Dagger annotation processor is run only when compiling the application module, it is not run when compiling dd-sdk-core for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions from me about this:
Hiltinstead ofDagger2?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.