Skip to content

Commit

Permalink
Apply code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusc83 committed Sep 16, 2024
1 parent 40283db commit c17f90a
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 472 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class _InternalProxy internal constructor(
message = message,
additionalProperties = null
)
rumFeature?.sendEvent(bundleEventIntoTelemetry(telemetryEvent))
rumFeature?.sendEvent(telemetryEvent)
}

fun error(message: String, throwable: Throwable? = null) {
val telemetryEvent = InternalTelemetryEvent.Log.Error(
message = message,
error = throwable
)
rumFeature?.sendEvent(bundleEventIntoTelemetry(telemetryEvent))
rumFeature?.sendEvent(telemetryEvent)
}

fun error(message: String, stack: String?, kind: String?) {
Expand All @@ -67,19 +67,8 @@ class _InternalProxy internal constructor(
stacktrace = stack,
kind = kind
)
rumFeature?.sendEvent(bundleEventIntoTelemetry(telemetryEvent))
rumFeature?.sendEvent(telemetryEvent)
}

// region Internal

private fun bundleEventIntoTelemetry(event: Any): Map<String, Any?> {
return mapOf(
"type" to "telemetry_event",
"event" to event
)
}

// endregion
}

@Suppress("PropertyName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,7 @@ internal class DatadogCore(
batchUploadFrequency = configuration.coreConfig.uploadFrequency.baseStepMs,
batchProcessingLevel = configuration.coreConfig.batchProcessingLevel.maxBatchesPerUploadJob
)
rumFeature.sendEvent(
mapOf(
"type" to "telemetry_event",
"event" to event
)
)
rumFeature.sendEvent(event)
}

coreFeature.uploadExecutorService.scheduleSafe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal class SdkInternalLogger(
message = messageBuilder(),
additionalProperties = additionalProperties
)
rumFeature.sendEvent(bundleEventIntoTelemetry(metricEvent))
rumFeature.sendEvent(metricEvent)
}

override fun startPerformanceMeasure(
Expand Down Expand Up @@ -132,20 +132,13 @@ internal class SdkInternalLogger(
) {
if (!RateBasedSampler(samplingRate).sample()) return
val rumFeature = sdkCore?.getFeature(Feature.RUM_FEATURE_NAME) ?: return
rumFeature.sendEvent(bundleEventIntoTelemetry(apiUsageEvent))
rumFeature.sendEvent(apiUsageEvent)
}

// endregion

// region Internal

private fun bundleEventIntoTelemetry(event: Any): Map<String, Any?> {
return mapOf(
TYPE_KEY to TELEMETRY_EVENT_MESSAGE_TYPE,
TELEMETRY_EVENT_KEY to event
)
}

private fun logToUser(
level: InternalLogger.Level,
messageBuilder: () -> String,
Expand Down Expand Up @@ -234,7 +227,7 @@ internal class SdkInternalLogger(
additionalProperties = additionalProperties
)
}
rumFeature.sendEvent(bundleEventIntoTelemetry(telemetryEvent))
rumFeature.sendEvent(telemetryEvent)
}

private fun InternalLogger.Level.toLogLevel(): Int {
Expand All @@ -259,9 +252,6 @@ internal class SdkInternalLogger(
companion object {
internal const val SDK_LOG_TAG = "DD_LOG"
internal const val DEV_LOG_TAG = "Datadog"
private const val TYPE_KEY = "type"
private const val TELEMETRY_EVENT_MESSAGE_TYPE = "telemetry_event"
internal const val TELEMETRY_EVENT_KEY = "event"
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ internal class InternalProxyTest {
proxy._telemetry.debug(message)

// Then
argumentCaptor<Map<String, Any>> {
argumentCaptor<InternalTelemetryEvent> {
verify(mockRumFeatureScope).sendEvent(capture())
val payload = firstValue
assert(payload["type"] == "telemetry_event")
val logEvent = payload["event"] as InternalTelemetryEvent.Log.Debug
val logEvent = firstValue as InternalTelemetryEvent.Log.Debug
assertThat(logEvent.message).isEqualTo(message)
}
}
Expand All @@ -77,11 +75,9 @@ internal class InternalProxyTest {
proxy._telemetry.error(message, stack, kind)

// Then
argumentCaptor<Map<String, Any>> {
argumentCaptor<InternalTelemetryEvent> {
verify(mockRumFeatureScope).sendEvent(capture())
val payload = firstValue
assert(payload["type"] == "telemetry_event")
val logEvent = payload["event"] as InternalTelemetryEvent.Log.Error
val logEvent = firstValue as InternalTelemetryEvent.Log.Error
assertThat(logEvent.message).isEqualTo(message)
assertThat(logEvent.stacktrace).isEqualTo(stack)
assertThat(logEvent.kind).isEqualTo(kind)
Expand All @@ -103,11 +99,9 @@ internal class InternalProxyTest {
proxy._telemetry.error(message, throwable)

// Then
argumentCaptor<Map<String, Any>> {
argumentCaptor<InternalTelemetryEvent> {
verify(mockRumFeatureScope).sendEvent(capture())
val payload = firstValue
assert(payload["type"] == "telemetry_event")
val logEvent = payload["event"] as InternalTelemetryEvent.Log.Error
val logEvent = firstValue as InternalTelemetryEvent.Log.Error
assertThat(logEvent.message).isEqualTo(message)
assertThat(logEvent.error).isEqualTo(throwable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,9 @@ internal class DatadogCoreInitializationTest {
}
testedCore.coreFeature.uploadExecutorService.shutdownNow()

argumentCaptor<Map<String, Any>> {
argumentCaptor<InternalTelemetryEvent> {
verify(mockRumFeature).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val telemetryConfigurationEvent = firstValue["event"] as InternalTelemetryEvent.Configuration
val telemetryConfigurationEvent = firstValue as InternalTelemetryEvent.Configuration
assertThat(telemetryConfigurationEvent.trackErrors)
.isEqualTo(configuration.crashReportsEnabled)
assertThat(telemetryConfigurationEvent.batchSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,9 @@ internal class SdkInternalLoggerTest {
)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val logEvent = firstValue["event"] as InternalTelemetryEvent.Log.Debug
val logEvent = firstValue as InternalTelemetryEvent.Log.Debug
assertThat(logEvent.message).isEqualTo(fakeMessage)
assertThat(logEvent.additionalProperties).isNull()
}
Expand Down Expand Up @@ -318,11 +316,9 @@ internal class SdkInternalLoggerTest {
)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val logEvent = firstValue["event"] as InternalTelemetryEvent.Log.Debug
val logEvent = firstValue as InternalTelemetryEvent.Log.Debug
assertThat(logEvent.message).isEqualTo(fakeMessage)
assertThat(logEvent.additionalProperties).isEqualTo(fakeAdditionalProperties)
}
Expand Down Expand Up @@ -350,11 +346,9 @@ internal class SdkInternalLoggerTest {
)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val logEvent = firstValue["event"] as InternalTelemetryEvent.Log.Debug
val logEvent = firstValue as InternalTelemetryEvent.Log.Debug
assertThat(logEvent.message).isEqualTo(fakeMessage)
assertThat(logEvent.additionalProperties).isEmpty()
}
Expand Down Expand Up @@ -383,11 +377,9 @@ internal class SdkInternalLoggerTest {
)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val logEvent = firstValue["event"] as InternalTelemetryEvent.Log.Error
val logEvent = firstValue as InternalTelemetryEvent.Log.Error
assertThat(logEvent.message).isEqualTo(fakeMessage)
assertThat(logEvent.additionalProperties).isEqualTo(fakeAdditionalProperties)
}
Expand Down Expand Up @@ -417,11 +409,9 @@ internal class SdkInternalLoggerTest {
)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val logEvent = firstValue["event"] as InternalTelemetryEvent.Log.Error
val logEvent = firstValue as InternalTelemetryEvent.Log.Error
assertThat(logEvent.message).isEqualTo(fakeMessage)
assertThat(logEvent.error).isEqualTo(fakeThrowable)
assertThat(logEvent.additionalProperties).isEqualTo(fakeAdditionalProperties)
Expand Down Expand Up @@ -452,11 +442,9 @@ internal class SdkInternalLoggerTest {
}

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val logEvent = firstValue["event"] as InternalTelemetryEvent.Log.Debug
val logEvent = firstValue as InternalTelemetryEvent.Log.Debug
assertThat(logEvent.message).isEqualTo(fakeMessage)
}
}
Expand All @@ -481,11 +469,9 @@ internal class SdkInternalLoggerTest {
)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val metricEvent = firstValue["event"] as InternalTelemetryEvent.Metric
val metricEvent = firstValue as InternalTelemetryEvent.Metric
assertThat(metricEvent.message).isEqualTo(fakeMessage)
assertThat(metricEvent.additionalProperties).isEqualTo(fakeAdditionalProperties)
}
Expand Down Expand Up @@ -578,11 +564,9 @@ internal class SdkInternalLoggerTest {
testedInternalLogger.logApiUsage(fakeApiUsageInternalTelemetryEvent, 100.0f)

// Then
argumentCaptor<Map<String, Any>>() {
argumentCaptor<InternalTelemetryEvent>() {
verify(mockRumFeatureScope).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val apiUsageEvent = firstValue["event"] as InternalTelemetryEvent.ApiUsage
val apiUsageEvent = firstValue as InternalTelemetryEvent.ApiUsage
assertThat(apiUsageEvent).isEqualTo(fakeApiUsageInternalTelemetryEvent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InternalTelemetryApiUsageForgeryFactory : ForgeryFactory<InternalTelemetry
overwrite = forge.aBool(),
noView = forge.aBool(),
noActiveView = forge.aBool(),
additionalProperties = forge.aMap { forge.aString() to forge.aString() }.toMutableMap()
additionalProperties = forge.aMap { aString() to aString() }.toMutableMap()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class InternalTelemetryDebugLogForgeryFactory : ForgeryFactory<InternalTelemetry
override fun getForgery(forge: Forge): InternalTelemetryEvent.Log.Debug {
return InternalTelemetryEvent.Log.Debug(
message = forge.aString(),
additionalProperties = forge.aMap { forge.aString() to forge.aString() }
additionalProperties = forge.aMap { aString() to aString() }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class InternalTelemetryErrorLogForgeryFactory : ForgeryFactory<InternalTelemetry
override fun getForgery(forge: Forge): InternalTelemetryEvent.Log.Error {
return InternalTelemetryEvent.Log.Error(
message = forge.aString(),
additionalProperties = forge.aMap { forge.aString() to forge.aString() },
error = forge.aNullable { forge.aThrowable() },
stacktrace = forge.aNullable { forge.aString() },
kind = forge.aNullable { forge.aString() }
additionalProperties = forge.aMap { aString() to aString() },
error = forge.aNullable { aThrowable() },
stacktrace = forge.aNullable { aString() },
kind = forge.aNullable { aString() }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class InternalTelemetryMetricForgeryFactory : ForgeryFactory<InternalTelemetryEv
override fun getForgery(forge: Forge): InternalTelemetryEvent.Metric {
return InternalTelemetryEvent.Metric(
message = forge.aString(),
additionalProperties = forge.aMap { forge.aString() to forge.aString() }
additionalProperties = forge.aMap { aString() to aString() }
)
}
}
67 changes: 0 additions & 67 deletions features/dd-sdk-android-rum/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -1712,73 +1712,6 @@ data class com.datadog.android.rum.model.ViewEvent
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): State
data class com.datadog.android.telemetry.model.CommonTelemetryProperties
constructor(Dd, kotlin.Long, kotlin.String, Source, kotlin.String, Application? = null, Session? = null, View? = null, Action? = null, kotlin.collections.List<kotlin.String>? = null, Telemetry? = null)
val type: kotlin.String
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): CommonTelemetryProperties
fun fromJsonObject(com.google.gson.JsonObject): CommonTelemetryProperties
class Dd
val formatVersion: kotlin.Long
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Dd
fun fromJsonObject(com.google.gson.JsonObject): Dd
data class Application
constructor(kotlin.String)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Application
fun fromJsonObject(com.google.gson.JsonObject): Application
data class Session
constructor(kotlin.String)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Session
fun fromJsonObject(com.google.gson.JsonObject): Session
data class View
constructor(kotlin.String)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): View
fun fromJsonObject(com.google.gson.JsonObject): View
data class Action
constructor(kotlin.String)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Action
fun fromJsonObject(com.google.gson.JsonObject): Action
data class Telemetry
constructor(Device? = null, Os? = null, kotlin.collections.MutableMap<kotlin.String, kotlin.Any?> = mutableMapOf())
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Telemetry
fun fromJsonObject(com.google.gson.JsonObject): Telemetry
data class Device
constructor(kotlin.String? = null, kotlin.String? = null, kotlin.String? = null)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Device
fun fromJsonObject(com.google.gson.JsonObject): Device
data class Os
constructor(kotlin.String? = null, kotlin.String? = null, kotlin.String? = null)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Os
fun fromJsonObject(com.google.gson.JsonObject): Os
enum Source
constructor(kotlin.String)
- ANDROID
- IOS
- BROWSER
- FLUTTER
- REACT_NATIVE
- UNITY
- KOTLIN_MULTIPLATFORM
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): Source
data class com.datadog.android.telemetry.model.TelemetryConfigurationEvent
constructor(Dd, kotlin.Long, kotlin.String, Source, kotlin.String, Application? = null, Session? = null, View? = null, Action? = null, kotlin.collections.List<kotlin.String>? = null, Telemetry)
val type: kotlin.String
Expand Down
Loading

0 comments on commit c17f90a

Please sign in to comment.