Skip to content

Commit

Permalink
Rename classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusc83 committed Sep 13, 2024
1 parent fb0aa66 commit e2bd3f2
Show file tree
Hide file tree
Showing 33 changed files with 235 additions and 274 deletions.
2 changes: 1 addition & 1 deletion dd-sdk-android-core/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface com.datadog.android.api.InternalLogger
fun log(Level, List<Target>, () -> String, Throwable? = null, Boolean = false, Map<String, Any?>? = null)
fun logMetric(() -> String, Map<String, Any?>, Float)
fun startPerformanceMeasure(String, com.datadog.android.core.metrics.TelemetryMetricType, Float, String): com.datadog.android.core.metrics.PerformanceMetric?
fun logApiUsage(com.datadog.android.internal.telemetry.TelemetryEvent.ApiUsage, Float)
fun logApiUsage(com.datadog.android.internal.telemetry.InternalTelemetryEvent.ApiUsage, Float)
companion object
val UNBOUND: InternalLogger
interface com.datadog.android.api.SdkCore
Expand Down
2 changes: 1 addition & 1 deletion dd-sdk-android-core/api/dd-sdk-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public abstract interface class com/datadog/android/api/InternalLogger {
public static final field Companion Lcom/datadog/android/api/InternalLogger$Companion;
public abstract fun log (Lcom/datadog/android/api/InternalLogger$Level;Lcom/datadog/android/api/InternalLogger$Target;Lkotlin/jvm/functions/Function0;Ljava/lang/Throwable;ZLjava/util/Map;)V
public abstract fun log (Lcom/datadog/android/api/InternalLogger$Level;Ljava/util/List;Lkotlin/jvm/functions/Function0;Ljava/lang/Throwable;ZLjava/util/Map;)V
public abstract fun logApiUsage (Lcom/datadog/android/internal/telemetry/TelemetryEvent$ApiUsage;F)V
public abstract fun logApiUsage (Lcom/datadog/android/internal/telemetry/InternalTelemetryEvent$ApiUsage;F)V
public abstract fun logMetric (Lkotlin/jvm/functions/Function0;Ljava/util/Map;F)V
public abstract fun startPerformanceMeasure (Ljava/lang/String;Lcom/datadog/android/core/metrics/TelemetryMetricType;FLjava/lang/String;)Lcom/datadog/android/core/metrics/PerformanceMetric;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.datadog.android.api.feature.FeatureScope
import com.datadog.android.api.feature.FeatureSdkCore
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.internal.DatadogCore
import com.datadog.android.internal.telemetry.TelemetryEvent
import com.datadog.android.internal.telemetry.InternalTelemetryEvent
import com.datadog.android.lint.InternalApi

/**
Expand Down Expand Up @@ -46,23 +46,23 @@ class _InternalProxy internal constructor(
}

fun debug(message: String) {
val telemetryEvent = TelemetryEvent.Log.Debug(
val telemetryEvent = InternalTelemetryEvent.Log.Debug(
message = message,
additionalProperties = null
)
rumFeature?.sendEvent(bundleEventIntoTelemetry(telemetryEvent))
}

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

fun error(message: String, stack: String?, kind: String?) {
val telemetryEvent = TelemetryEvent.Log.Error(
val telemetryEvent = InternalTelemetryEvent.Log.Error(
message = message,
stacktrace = stack,
kind = kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package com.datadog.android.api
import com.datadog.android.core.internal.logger.SdkInternalLogger
import com.datadog.android.core.metrics.PerformanceMetric
import com.datadog.android.core.metrics.TelemetryMetricType
import com.datadog.android.internal.telemetry.TelemetryEvent
import com.datadog.android.internal.telemetry.InternalTelemetryEvent
import com.datadog.android.lint.InternalApi
import com.datadog.tools.annotation.NoOpImplementation

Expand Down Expand Up @@ -141,7 +141,7 @@ interface InternalLogger {
*/
@InternalApi
fun logApiUsage(
apiUsageEvent: TelemetryEvent.ApiUsage,
apiUsageEvent: InternalTelemetryEvent.ApiUsage,
samplingRate: Float
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.datadog.android.core.internal.utils.scheduleSafe
import com.datadog.android.core.internal.utils.submitSafe
import com.datadog.android.core.thread.FlushableExecutorService
import com.datadog.android.error.internal.CrashReportsFeature
import com.datadog.android.internal.telemetry.TelemetryEvent
import com.datadog.android.internal.telemetry.InternalTelemetryEvent
import com.datadog.android.ndk.internal.NdkCrashHandler
import com.datadog.android.privacy.TrackingConsent
import com.google.gson.JsonObject
Expand Down Expand Up @@ -500,10 +500,10 @@ internal class DatadogCore(
}

@Suppress("FunctionMaxLength")
internal fun sendCoreConfigurationTelemetryEvent(configuration: Configuration) {
private fun sendCoreConfigurationTelemetryEvent(configuration: Configuration) {
val runnable = Runnable {
val rumFeature = getFeature(Feature.RUM_FEATURE_NAME) ?: return@Runnable
val event = TelemetryEvent.Configuration(
val event = InternalTelemetryEvent.Configuration(
trackErrors = configuration.crashReportsEnabled,
batchSize = configuration.coreConfig.batchSize.windowDurationMs,
useProxy = configuration.coreConfig.proxy != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.datadog.android.core.internal.metrics.MethodCalledTelemetry
import com.datadog.android.core.metrics.PerformanceMetric
import com.datadog.android.core.metrics.TelemetryMetricType
import com.datadog.android.core.sampling.RateBasedSampler
import com.datadog.android.internal.telemetry.TelemetryEvent
import com.datadog.android.internal.telemetry.InternalTelemetryEvent

internal class SdkInternalLogger(
private val sdkCore: FeatureSdkCore?,
Expand Down Expand Up @@ -100,7 +100,7 @@ internal class SdkInternalLogger(
) {
if (!RateBasedSampler(samplingRate).sample()) return
val rumFeature = sdkCore?.getFeature(Feature.RUM_FEATURE_NAME) ?: return
val metricEvent = TelemetryEvent.Metric(
val metricEvent = InternalTelemetryEvent.Metric(
message = messageBuilder(),
additionalProperties = additionalProperties
)
Expand All @@ -127,7 +127,7 @@ internal class SdkInternalLogger(
}

override fun logApiUsage(
apiUsageEvent: TelemetryEvent.ApiUsage,
apiUsageEvent: InternalTelemetryEvent.ApiUsage,
samplingRate: Float
) {
if (!RateBasedSampler(samplingRate).sample()) return
Expand Down Expand Up @@ -223,13 +223,13 @@ internal class SdkInternalLogger(
level == InternalLogger.Level.WARN ||
error != null
) {
TelemetryEvent.Log.Error(
InternalTelemetryEvent.Log.Error(
message = message,
additionalProperties = additionalProperties,
error = error
)
} else {
TelemetryEvent.Log.Debug(
InternalTelemetryEvent.Log.Debug(
message = message,
additionalProperties = additionalProperties
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.datadog.android.api.feature.FeatureScope
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.DatadogCore
import com.datadog.android.core.internal.system.AppVersionProvider
import com.datadog.android.internal.telemetry.TelemetryEvent
import com.datadog.android.internal.telemetry.InternalTelemetryEvent
import com.datadog.android.utils.forge.Configurator
import fr.xgouchet.elmyr.annotation.Forgery
import fr.xgouchet.elmyr.annotation.StringForgery
Expand Down Expand Up @@ -56,7 +56,7 @@ internal class InternalProxyTest {
verify(mockRumFeatureScope).sendEvent(capture())
val payload = firstValue
assert(payload["type"] == "telemetry_event")
val logEvent = payload["event"] as TelemetryEvent.Log.Debug
val logEvent = payload["event"] as InternalTelemetryEvent.Log.Debug
assertThat(logEvent.message).isEqualTo(message)
}
}
Expand All @@ -81,7 +81,7 @@ internal class InternalProxyTest {
verify(mockRumFeatureScope).sendEvent(capture())
val payload = firstValue
assert(payload["type"] == "telemetry_event")
val logEvent = payload["event"] as TelemetryEvent.Log.Error
val logEvent = payload["event"] as InternalTelemetryEvent.Log.Error
assertThat(logEvent.message).isEqualTo(message)
assertThat(logEvent.stacktrace).isEqualTo(stack)
assertThat(logEvent.kind).isEqualTo(kind)
Expand All @@ -107,7 +107,7 @@ internal class InternalProxyTest {
verify(mockRumFeatureScope).sendEvent(capture())
val payload = firstValue
assert(payload["type"] == "telemetry_event")
val logEvent = payload["event"] as TelemetryEvent.Log.Error
val logEvent = payload["event"] 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 @@ -20,6 +20,7 @@ import com.datadog.android.core.internal.DatadogCore
import com.datadog.android.core.internal.SdkFeature
import com.datadog.android.core.thread.FlushableExecutorService
import com.datadog.android.error.internal.CrashReportsFeature
import com.datadog.android.internal.telemetry.InternalTelemetryEvent
import com.datadog.android.privacy.TrackingConsent
import com.datadog.android.security.Encryption
import com.datadog.android.utils.config.ApplicationContextTestConfiguration
Expand Down Expand Up @@ -48,6 +49,7 @@ import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
Expand Down Expand Up @@ -371,19 +373,24 @@ internal class DatadogCoreInitializationTest {
}
testedCore.coreFeature.uploadExecutorService.shutdownNow()

verify(mockRumFeature)
.sendEvent(
mapOf(
"type" to "telemetry_configuration",
"use_proxy" to useProxy,
"use_local_encryption" to useLocalEncryption,
"batch_size" to batchSize.windowDurationMs,
"batch_upload_frequency" to uploadFrequency.baseStepMs,
"track_errors" to trackErrors,
"batch_processing_level" to batchProcessingLevel.maxBatchesPerUploadJob,
"use_persistence_strategy_factory" to usePersistenceStrategyFactory
)
)
argumentCaptor<Map<String, Any>> {
verify(mockRumFeature).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val telemetryConfigurationEvent = firstValue["event"] as InternalTelemetryEvent.Configuration
assertThat(telemetryConfigurationEvent.trackErrors)
.isEqualTo(configuration.crashReportsEnabled)
assertThat(telemetryConfigurationEvent.batchSize)
.isEqualTo(configuration.coreConfig.batchSize.windowDurationMs)
assertThat(telemetryConfigurationEvent.useLocalEncryption)
.isEqualTo(configuration.coreConfig.encryption != null)
assertThat(telemetryConfigurationEvent.batchUploadFrequency)
.isEqualTo(configuration.coreConfig.uploadFrequency.baseStepMs)
assertThat(telemetryConfigurationEvent.batchProcessingLevel)
.isEqualTo(configuration.coreConfig.batchProcessingLevel.maxBatchesPerUploadJob)
assertThat(telemetryConfigurationEvent.useProxy)
.isEqualTo(configuration.coreConfig.proxy != null)
}
}

// region AdditionalConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.datadog.android.core.internal.time.NoOpTimeProvider
import com.datadog.android.core.internal.time.TimeProvider
import com.datadog.android.core.internal.user.MutableUserInfoProvider
import com.datadog.android.core.thread.FlushableExecutorService
import com.datadog.android.internal.telemetry.TelemetryEvent
import com.datadog.android.ndk.internal.NdkCrashHandler
import com.datadog.android.privacy.TrackingConsent
import com.datadog.android.utils.config.ApplicationContextTestConfiguration
Expand Down Expand Up @@ -80,7 +79,6 @@ import java.util.Collections
import java.util.Locale
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Future
import java.util.concurrent.ScheduledThreadPoolExecutor
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -159,53 +157,6 @@ internal class DatadogCoreTest {
verify(mockConsentProvider).setConsent(fakeConsent)
}

@Test
fun `M send configuration telemetry W initialize()`() {
// Given
val mockRumFeature = mock<SdkFeature>()
testedCore = DatadogCore(
appContext.mockInstance,
fakeInstanceId,
fakeInstanceName,
internalLoggerProvider = { mockInternalLogger },
executorServiceFactory = { _, _, _ -> mockPersistenceExecutorService },
buildSdkVersionProvider = mockBuildSdkVersionProvider
)
val mockUploadExecutorService = mock<ScheduledThreadPoolExecutor> { executor ->
whenever(executor.schedule(any(), any(), any())) doAnswer { invocation ->
val runnable = invocation.getArgument<Runnable>(0)
runnable.run()
mock()
}
}
testedCore.features[Feature.RUM_FEATURE_NAME] = mockRumFeature
testedCore.initialize(fakeConfiguration)

// When
testedCore.coreFeature.uploadExecutorService = mockUploadExecutorService
testedCore.sendCoreConfigurationTelemetryEvent(fakeConfiguration)

// Then
argumentCaptor<Map<String, Any>> {
verify(mockRumFeature).sendEvent(capture())
assertThat(firstValue.size).isEqualTo(2)
assertThat(firstValue["type"]).isEqualTo("telemetry_event")
val telemetryConfigurationEvent = firstValue["event"] as TelemetryEvent.Configuration
assertThat(telemetryConfigurationEvent.trackErrors)
.isEqualTo(fakeConfiguration.crashReportsEnabled)
assertThat(telemetryConfigurationEvent.batchSize)
.isEqualTo(fakeConfiguration.coreConfig.batchSize.windowDurationMs)
assertThat(telemetryConfigurationEvent.useLocalEncryption)
.isEqualTo(fakeConfiguration.coreConfig.encryption != null)
assertThat(telemetryConfigurationEvent.batchUploadFrequency)
.isEqualTo(fakeConfiguration.coreConfig.uploadFrequency.baseStepMs)
assertThat(telemetryConfigurationEvent.batchProcessingLevel)
.isEqualTo(fakeConfiguration.coreConfig.batchProcessingLevel.maxBatchesPerUploadJob)
assertThat(telemetryConfigurationEvent.useProxy)
.isEqualTo(fakeConfiguration.coreConfig.proxy != null)
}
}

@Test
fun `M register feature W registerFeature()`(
@Mock mockFeature: Feature,
Expand Down
Loading

0 comments on commit e2bd3f2

Please sign in to comment.