Skip to content

Commit 1fafea0

Browse files
committed
RUM-12047: Sending same properties that is being sent for the rest events
1 parent fd31d41 commit 1fafea0

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumEventExt.kt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,43 @@ internal fun NetworkInfo.toActionConnectivity(): ActionEvent.Connectivity {
350350
)
351351
}
352352

353+
internal fun NetworkInfo.toVitalConnectivity(): VitalEvent.Connectivity {
354+
val status = if (isConnected()) {
355+
VitalEvent.Status.CONNECTED
356+
} else {
357+
VitalEvent.Status.NOT_CONNECTED
358+
}
359+
val interfaces = when (connectivity) {
360+
NetworkInfo.Connectivity.NETWORK_ETHERNET -> listOf(VitalEvent.Interface.ETHERNET)
361+
NetworkInfo.Connectivity.NETWORK_WIFI -> listOf(VitalEvent.Interface.WIFI)
362+
NetworkInfo.Connectivity.NETWORK_WIMAX -> listOf(VitalEvent.Interface.WIMAX)
363+
NetworkInfo.Connectivity.NETWORK_BLUETOOTH -> listOf(VitalEvent.Interface.BLUETOOTH)
364+
NetworkInfo.Connectivity.NETWORK_2G,
365+
NetworkInfo.Connectivity.NETWORK_3G,
366+
NetworkInfo.Connectivity.NETWORK_4G,
367+
NetworkInfo.Connectivity.NETWORK_5G,
368+
NetworkInfo.Connectivity.NETWORK_MOBILE_OTHER,
369+
NetworkInfo.Connectivity.NETWORK_CELLULAR -> listOf(VitalEvent.Interface.CELLULAR)
370+
371+
NetworkInfo.Connectivity.NETWORK_OTHER -> listOf(VitalEvent.Interface.OTHER)
372+
NetworkInfo.Connectivity.NETWORK_NOT_CONNECTED -> emptyList()
373+
}
374+
375+
val cellular = if (cellularTechnology != null || carrierName != null) {
376+
VitalEvent.Cellular(
377+
technology = cellularTechnology,
378+
carrierName = carrierName
379+
)
380+
} else {
381+
null
382+
}
383+
return VitalEvent.Connectivity(
384+
status,
385+
interfaces,
386+
cellular = cellular
387+
)
388+
}
389+
353390
internal fun NetworkInfo.isConnected(): Boolean {
354391
return connectivity != NetworkInfo.Connectivity.NETWORK_NOT_CONNECTED
355392
}
@@ -418,6 +455,18 @@ internal fun DeviceType.toErrorSchemaType(): ErrorEvent.DeviceType {
418455
}
419456
}
420457

458+
internal fun DeviceType.toVitalSchemaType(): VitalEvent.DeviceType {
459+
return when (this) {
460+
DeviceType.MOBILE -> VitalEvent.DeviceType.MOBILE
461+
DeviceType.TABLET -> VitalEvent.DeviceType.TABLET
462+
DeviceType.TV -> VitalEvent.DeviceType.TV
463+
DeviceType.DESKTOP -> VitalEvent.DeviceType.DESKTOP
464+
DeviceType.GAMING_CONSOLE -> VitalEvent.DeviceType.GAMING_CONSOLE
465+
DeviceType.BOT -> VitalEvent.DeviceType.BOT
466+
DeviceType.OTHER -> VitalEvent.DeviceType.OTHER
467+
}
468+
}
469+
421470
// endregion
422471

423472
// region Source
@@ -507,6 +556,23 @@ internal fun ResourceEvent.ResourceEventSource.Companion.tryFromSource(
507556
}
508557
}
509558

559+
internal fun VitalEvent.VitalEventSource.Companion.tryFromSource(
560+
source: String,
561+
internalLogger: InternalLogger
562+
): VitalEvent.VitalEventSource? {
563+
return try {
564+
fromJson(source)
565+
} catch (e: NoSuchElementException) {
566+
internalLogger.log(
567+
InternalLogger.Level.ERROR,
568+
InternalLogger.Target.USER,
569+
{ UNKNOWN_SOURCE_WARNING_MESSAGE_FORMAT.format(Locale.US, source) },
570+
e
571+
)
572+
null
573+
}
574+
}
575+
510576
internal const val UNKNOWN_SOURCE_WARNING_MESSAGE_FORMAT = "You are using an unknown " +
511577
"source %s for your events"
512578

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ internal open class RumViewScope(
326326
syntheticsAttribute == null -> VitalEvent.VitalEventSessionType.USER
327327
else -> VitalEvent.VitalEventSessionType.SYNTHETICS
328328
}
329+
val batteryInfo = batteryInfoProvider.getState()
330+
val displayInfo = displayInfoProvider.getState()
331+
val user = datadogContext.userInfo
329332

330333
return VitalEvent(
331334
date = event.eventTime.timestamp + serverTimeOffsetInMs,
@@ -355,6 +358,49 @@ internal open class RumViewScope(
355358
name = rumContext.viewName,
356359
url = rumContext.viewUrl.orEmpty()
357360
),
361+
source = VitalEvent.VitalEventSource.tryFromSource(
362+
source = datadogContext.source,
363+
internalLogger = sdkCore.internalLogger
364+
),
365+
account = datadogContext.accountInfo?.let {
366+
VitalEvent.Account(
367+
id = it.id,
368+
name = it.name,
369+
additionalProperties = it.extraInfo.toMutableMap()
370+
)
371+
},
372+
usr = if (user.hasUserData()) {
373+
VitalEvent.Usr(
374+
id = user.id,
375+
name = user.name,
376+
email = user.email,
377+
anonymousId = user.anonymousId,
378+
additionalProperties = user.additionalProperties.toMutableMap()
379+
)
380+
} else {
381+
null
382+
},
383+
device = VitalEvent.Device(
384+
type = datadogContext.deviceInfo.deviceType.toVitalSchemaType(),
385+
name = datadogContext.deviceInfo.deviceName,
386+
model = datadogContext.deviceInfo.deviceModel,
387+
brand = datadogContext.deviceInfo.deviceBrand,
388+
architecture = datadogContext.deviceInfo.architecture,
389+
locales = datadogContext.deviceInfo.localeInfo.locales,
390+
timeZone = datadogContext.deviceInfo.localeInfo.timeZone,
391+
batteryLevel = batteryInfo.batteryLevel,
392+
powerSavingMode = batteryInfo.lowPowerMode,
393+
brightnessLevel = displayInfo.screenBrightness
394+
),
395+
os = VitalEvent.Os(
396+
name = datadogContext.deviceInfo.osName,
397+
version = datadogContext.deviceInfo.osVersion,
398+
versionMajor = datadogContext.deviceInfo.osMajorVersion
399+
),
400+
connectivity = datadogContext.networkInfo.toVitalConnectivity(),
401+
version = datadogContext.version,
402+
service = datadogContext.service,
403+
ddtags = buildDDTagsString(datadogContext),
358404
vital = VitalEvent.VitalEventVital(
359405
id = UUID.randomUUID().toString(),
360406
name = name,

0 commit comments

Comments
 (0)