Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.datadog.android.core.InternalSdkCore
import com.datadog.android.core.sampling.RateBasedSampler
import com.datadog.android.rum.internal.RumAnonymousIdentifierManager
import com.datadog.android.rum.internal.RumFeature
import com.datadog.android.rum.internal.domain.scope.RumVitalEventHelper
import com.datadog.android.rum.internal.metric.SessionEndedMetricDispatcher
import com.datadog.android.rum.internal.monitor.DatadogRumMonitor
import com.datadog.android.rum.internal.startup.RumAppStartupTelemetryReporter
Expand Down Expand Up @@ -145,7 +146,14 @@ object Rum {
accessibilitySnapshotManager = rumFeature.accessibilitySnapshotManager,
batteryInfoProvider = rumFeature.batteryInfoProvider,
displayInfoProvider = rumFeature.displayInfoProvider,
rumAppStartupTelemetryReporter = RumAppStartupTelemetryReporter.create(sdkCore)
rumAppStartupTelemetryReporter = RumAppStartupTelemetryReporter.create(sdkCore),
rumVitalEventHelper = RumVitalEventHelper(
rumSessionTypeOverride = rumFeature.configuration.rumSessionTypeOverride,
batteryInfoProvider = rumFeature.batteryInfoProvider,
displayInfoProvider = rumFeature.displayInfoProvider,
sampleRate = rumFeature.sampleRate,
internalLogger = sdkCore.internalLogger
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ internal class RumFeature(
override fun onFirstFrameDrawn(timestampNs: Long) {
val info = RumTTIDInfo(
scenario = scenario,
durationNs = timestampNs - scenario.initialTimeNs
durationNs = timestampNs - scenario.initialTime.nanoTime
)
(GlobalRumMonitor.get(sdkCore) as? AdvancedRumMonitor)
?.sendTTIDEvent(info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ internal class RumApplicationScope(
private val accessibilitySnapshotManager: AccessibilitySnapshotManager,
private val batteryInfoProvider: InfoProvider<BatteryInfo>,
private val displayInfoProvider: InfoProvider<DisplayInfo>,
private val rumAppStartupTelemetryReporter: RumAppStartupTelemetryReporter
private val rumAppStartupTelemetryReporter: RumAppStartupTelemetryReporter,
private val rumVitalEventHelper: RumVitalEventHelper
) : RumScope, RumViewChangedListener {

override val parentScope: RumScope? = null
Expand Down Expand Up @@ -81,7 +82,8 @@ internal class RumApplicationScope(
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider,
rumAppStartupTelemetryReporter = rumAppStartupTelemetryReporter
rumAppStartupTelemetryReporter = rumAppStartupTelemetryReporter,
rumVitalEventHelper = rumVitalEventHelper
)
)

Expand Down Expand Up @@ -202,7 +204,8 @@ internal class RumApplicationScope(
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider,
rumAppStartupTelemetryReporter = rumAppStartupTelemetryReporter
rumAppStartupTelemetryReporter = rumAppStartupTelemetryReporter,
rumVitalEventHelper = rumVitalEventHelper
)
childScopes.add(newSession)
if (event !is RumRawEvent.StartView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import com.datadog.android.rum.RumResourceMethod
import com.datadog.android.rum.featureoperations.FailureReason
import com.datadog.android.rum.internal.RumErrorSourceType
import com.datadog.android.rum.internal.domain.event.ResourceTiming
import com.datadog.android.rum.internal.startup.RumStartupScenario
import com.datadog.android.rum.model.ActionEvent
import com.datadog.android.rum.model.ErrorEvent
import com.datadog.android.rum.model.LongTaskEvent
import com.datadog.android.rum.model.ResourceEvent
import com.datadog.android.rum.model.ViewEvent
import com.datadog.android.rum.model.VitalEvent
import com.datadog.android.rum.model.VitalEvent.StartupType
import java.util.Locale

// region Resource.Method conversion
Expand Down Expand Up @@ -669,4 +671,13 @@ internal fun FailureReason.toSchemaFailureReason(): VitalEvent.FailureReason {
FailureReason.OTHER -> VitalEvent.FailureReason.OTHER
}
}

internal fun RumStartupScenario.toVitalStartupType(): StartupType {
return when (this) {
is RumStartupScenario.Cold -> StartupType.COLD_START
is RumStartupScenario.WarmAfterActivityDestroyed,
is RumStartupScenario.WarmFirstActivity -> StartupType.WARM_START
}
}

// endregion
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import com.datadog.android.rum.internal.domain.display.DisplayInfo
import com.datadog.android.rum.internal.metric.SessionMetricDispatcher
import com.datadog.android.rum.internal.metric.slowframes.SlowFramesListener
import com.datadog.android.rum.internal.startup.RumAppStartupTelemetryReporter
import com.datadog.android.rum.internal.utils.newRumEventWriteOperation
import com.datadog.android.rum.internal.utils.percent
import com.datadog.android.rum.internal.vitals.VitalMonitor
import com.datadog.android.rum.metric.interactiontonextview.LastInteractionIdentifier
import com.datadog.android.rum.metric.networksettled.InitialResourceIdentifier
import com.datadog.android.rum.model.VitalEvent
import java.security.SecureRandom
import java.util.UUID
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -58,7 +60,8 @@ internal class RumSessionScope(
private val sessionInactivityNanos: Long = DEFAULT_SESSION_INACTIVITY_NS,
private val sessionMaxDurationNanos: Long = DEFAULT_SESSION_MAX_DURATION_NS,
rumSessionTypeOverride: RumSessionType?,
private val rumAppStartupTelemetryReporter: RumAppStartupTelemetryReporter
private val rumAppStartupTelemetryReporter: RumAppStartupTelemetryReporter,
private val rumVitalEventHelper: RumVitalEventHelper
) : RumScope {

internal var sessionId = RumContext.NULL_UUID
Expand Down Expand Up @@ -95,7 +98,8 @@ internal class RumSessionScope(
rumSessionTypeOverride = rumSessionTypeOverride,
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider
displayInfoProvider = displayInfoProvider,
rumVitalEventHelper = rumVitalEventHelper
)

internal val activeView: RumViewScope?
Expand Down Expand Up @@ -156,11 +160,12 @@ internal class RumSessionScope(
when (event) {
is RumRawEvent.AppStartTTIDEvent -> {
if (sessionState == State.TRACKED) {
rumAppStartupTelemetryReporter.reportTTID(
info = event.info,
indexInSession = appStartIndex
handleTTIDEvent(
event = event,
datadogContext = datadogContext,
writeScope = writeScope,
writer = actualWriter
)
appStartIndex++
}
}
is RumRawEvent.SdkInit -> {}
Expand Down Expand Up @@ -281,6 +286,54 @@ internal class RumSessionScope(
)
}

private fun handleTTIDEvent(
event: RumRawEvent.AppStartTTIDEvent,
datadogContext: DatadogContext,
writeScope: EventWriteScope,
writer: DataWriter<Any>
) {
sdkCore.newRumEventWriteOperation(datadogContext, writeScope, writer) {
createTTIDVitalEvent(
event = event,
datadogContext = datadogContext
)
}.submit()

rumAppStartupTelemetryReporter.reportTTID(
info = event.info,
indexInSession = appStartIndex
)

appStartIndex++
}

private fun createTTIDVitalEvent(
event: RumRawEvent.AppStartTTIDEvent,
datadogContext: DatadogContext
): VitalEvent {
val rumContext = getRumContext()

return rumVitalEventHelper.newVitalEvent(
timestampMs = event.info.scenario.initialTime.timestamp + sdkCore.time.serverTimeOffsetMs,
datadogContext = datadogContext,
eventAttributes = emptyMap(),
customAttributes = getCustomAttributes(),
view = null,
hasReplay = null,
rumContext = rumContext,
vital = VitalEvent.Vital.AppLaunchProperties(
id = UUID.randomUUID().toString(),
name = null,
description = null,
appLaunchMetric = VitalEvent.AppLaunchMetric.TTID,
duration = event.info.durationNs,
startupType = event.info.scenario.toVitalStartupType(),
isPrewarmed = null,
hasSavedInstanceStateBundle = event.info.scenario.hasSavedInstanceStateBundle
)
)
}

// endregion

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ internal class RumViewManagerScope(
private val rumSessionTypeOverride: RumSessionType?,
private val accessibilitySnapshotManager: AccessibilitySnapshotManager,
private val batteryInfoProvider: InfoProvider<BatteryInfo>,
private val displayInfoProvider: InfoProvider<DisplayInfo>
private val displayInfoProvider: InfoProvider<DisplayInfo>,
private val rumVitalEventHelper: RumVitalEventHelper
) : RumScope {

private val interactionToNextViewMetricResolver: InteractionToNextViewMetricResolver =
Expand Down Expand Up @@ -285,7 +286,8 @@ internal class RumViewManagerScope(
rumSessionTypeOverride = rumSessionTypeOverride,
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider
displayInfoProvider = displayInfoProvider,
rumVitalEventHelper = rumVitalEventHelper
)
applicationDisplayed = true
childrenScopes.add(viewScope)
Expand Down Expand Up @@ -368,7 +370,8 @@ internal class RumViewManagerScope(
rumSessionTypeOverride = rumSessionTypeOverride,
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider
displayInfoProvider = displayInfoProvider,
rumVitalEventHelper = rumVitalEventHelper
)
}

Expand Down Expand Up @@ -410,7 +413,8 @@ internal class RumViewManagerScope(
rumSessionTypeOverride = rumSessionTypeOverride,
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider
displayInfoProvider = displayInfoProvider,
rumVitalEventHelper = rumVitalEventHelper
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import com.datadog.android.rum.internal.toAction
import com.datadog.android.rum.internal.toError
import com.datadog.android.rum.internal.toLongTask
import com.datadog.android.rum.internal.toView
import com.datadog.android.rum.internal.toVital
import com.datadog.android.rum.internal.utils.buildDDTagsString
import com.datadog.android.rum.internal.utils.hasUserData
import com.datadog.android.rum.internal.utils.newRumEventWriteOperation
Expand Down Expand Up @@ -88,7 +87,8 @@ internal open class RumViewScope(
private val rumSessionTypeOverride: RumSessionType?,
private val accessibilitySnapshotManager: AccessibilitySnapshotManager,
private val batteryInfoProvider: InfoProvider<BatteryInfo>,
private val displayInfoProvider: InfoProvider<DisplayInfo>
private val displayInfoProvider: InfoProvider<DisplayInfo>,
private val rumVitalEventHelper: RumVitalEventHelper
) : RumScope {

internal val url = key.url.replace('.', '/')
Expand Down Expand Up @@ -305,102 +305,24 @@ internal open class RumViewScope(
eventAttributes: Map<String, Any?>
): VitalEvent {
val rumContext = getRumContext()
val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
) {
null
} else {
VitalEvent.Synthetics(
testId = rumContext.syntheticsTestId,
resultId = rumContext.syntheticsResultId
)
}

val hasReplay = featuresContextResolver.resolveViewHasReplay(
datadogContext,
rumContext.viewId.orEmpty()
)

val sessionType = when {
rumSessionTypeOverride != null -> rumSessionTypeOverride.toVital()
syntheticsAttribute == null -> VitalEvent.VitalEventSessionType.USER
else -> VitalEvent.VitalEventSessionType.SYNTHETICS
}
val batteryInfo = batteryInfoProvider.getState()
val displayInfo = displayInfoProvider.getState()
val user = datadogContext.userInfo

return VitalEvent(
date = event.eventTime.timestamp + serverTimeOffsetInMs,
context = VitalEvent.Context(
additionalProperties = getCustomAttributes().toMutableMap().also {
it.putAll(eventAttributes)
}
),
dd = VitalEvent.Dd(
session = VitalEvent.DdSession(
sessionPrecondition = rumContext.sessionStartReason.toVitalSessionPrecondition()
),
configuration = VitalEvent.Configuration(sessionSampleRate = sampleRate)
),
application = VitalEvent.Application(
id = rumContext.applicationId,
currentLocale = datadogContext.deviceInfo.localeInfo.currentLocale
),
synthetics = syntheticsAttribute,
session = VitalEvent.VitalEventSession(
id = rumContext.sessionId,
type = sessionType,
hasReplay = hasReplay
),
return rumVitalEventHelper.newVitalEvent(
timestampMs = event.eventTime.timestamp + serverTimeOffsetInMs,
datadogContext = datadogContext,
eventAttributes = eventAttributes,
customAttributes = getCustomAttributes(),
view = VitalEvent.VitalEventView(
id = rumContext.viewId.orEmpty(),
name = rumContext.viewName,
url = rumContext.viewUrl.orEmpty()
),
source = VitalEvent.VitalEventSource.tryFromSource(
source = datadogContext.source,
internalLogger = sdkCore.internalLogger
),
account = datadogContext.accountInfo?.let {
VitalEvent.Account(
id = it.id,
name = it.name,
additionalProperties = it.extraInfo.toMutableMap()
)
},
usr = if (user.hasUserData()) {
VitalEvent.Usr(
id = user.id,
name = user.name,
email = user.email,
anonymousId = user.anonymousId,
additionalProperties = user.additionalProperties.toMutableMap()
)
} else {
null
},
device = VitalEvent.Device(
type = datadogContext.deviceInfo.deviceType.toVitalSchemaType(),
name = datadogContext.deviceInfo.deviceName,
model = datadogContext.deviceInfo.deviceModel,
brand = datadogContext.deviceInfo.deviceBrand,
architecture = datadogContext.deviceInfo.architecture,
locales = datadogContext.deviceInfo.localeInfo.locales,
timeZone = datadogContext.deviceInfo.localeInfo.timeZone,
batteryLevel = batteryInfo.batteryLevel,
powerSavingMode = batteryInfo.lowPowerMode,
brightnessLevel = displayInfo.screenBrightness
),
os = VitalEvent.Os(
name = datadogContext.deviceInfo.osName,
version = datadogContext.deviceInfo.osVersion,
versionMajor = datadogContext.deviceInfo.osMajorVersion
),
connectivity = datadogContext.networkInfo.toVitalConnectivity(),
version = datadogContext.version,
service = datadogContext.service,
ddtags = buildDDTagsString(datadogContext),
hasReplay = hasReplay,
rumContext = rumContext,
vital = VitalEvent.Vital.FeatureOperationProperties(
id = UUID.randomUUID().toString(),
name = name,
Expand Down Expand Up @@ -460,7 +382,8 @@ internal open class RumViewScope(
rumSessionTypeOverride = rumSessionTypeOverride,
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider
displayInfoProvider = displayInfoProvider,
rumVitalEventHelper = rumVitalEventHelper
)
}

Expand Down Expand Up @@ -1747,7 +1670,8 @@ internal open class RumViewScope(
rumSessionTypeOverride: RumSessionType?,
accessibilitySnapshotManager: AccessibilitySnapshotManager,
batteryInfoProvider: InfoProvider<BatteryInfo>,
displayInfoProvider: InfoProvider<DisplayInfo>
displayInfoProvider: InfoProvider<DisplayInfo>,
rumVitalEventHelper: RumVitalEventHelper
): RumViewScope {
val networkSettledMetricResolver = NetworkSettledMetricResolver(
networkSettledResourceIdentifier,
Expand Down Expand Up @@ -1783,7 +1707,8 @@ internal open class RumViewScope(
rumSessionTypeOverride = rumSessionTypeOverride,
accessibilitySnapshotManager = accessibilitySnapshotManager,
batteryInfoProvider = batteryInfoProvider,
displayInfoProvider = displayInfoProvider
displayInfoProvider = displayInfoProvider,
rumVitalEventHelper = rumVitalEventHelper
)
}

Expand Down
Loading
Loading