Skip to content
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

Add telemetry configuration mapper #1142

Merged
merged 1 commit into from
Nov 14, 2022
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
2 changes: 2 additions & 0 deletions dd-sdk-android/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class com.datadog.android._InternalProxy
fun error(String, String?, String?)
val _telemetry: _TelemetryProxy
fun setCustomAppVersion(String)
companion object
fun setTelemetryConfigurationEventMapper(com.datadog.android.core.configuration.Configuration.Builder, com.datadog.android.event.EventMapper<com.datadog.android.telemetry.model.TelemetryConfigurationEvent>): com.datadog.android.core.configuration.Configuration.Builder
enum com.datadog.android.core.configuration.BatchSize
constructor(Long)
- SMALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

package com.datadog.android

import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.event.EventMapper
import com.datadog.android.telemetry.internal.Telemetry
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent

/**
* This class exposes internal methods that are used by other Datadog modules and cross platform
Expand Down Expand Up @@ -48,4 +51,14 @@ class _InternalProxy internal constructor(telemetry: Telemetry) {
fun setCustomAppVersion(version: String) {
CoreFeature.packageVersionProvider.version = version
}

companion object {
@Suppress("FunctionMaxLength")
fun setTelemetryConfigurationEventMapper(
builder: Configuration.Builder,
eventMapper: EventMapper<TelemetryConfigurationEvent>
): Configuration.Builder {
return builder.setTelemetryConfigurationEventMapper(eventMapper)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.datadog.android.rum.tracking.NoOpInteractionPredicate
import com.datadog.android.rum.tracking.TrackingStrategy
import com.datadog.android.rum.tracking.ViewAttributesProvider
import com.datadog.android.rum.tracking.ViewTrackingStrategy
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
import okhttp3.Authenticator
import java.net.Proxy
import java.util.Locale
Expand Down Expand Up @@ -581,6 +582,16 @@ internal constructor(
return this
}

@Suppress("FunctionMaxLength")
internal fun setTelemetryConfigurationEventMapper(eventMapper: EventMapper<TelemetryConfigurationEvent>): Builder {
applyIfFeatureEnabled(PluginFeature.RUM, "setTelemetryConfigurationEventMapper") {
rumConfig = rumConfig.copy(
rumEventMapper = getRumEventMapper().copy(telemetryConfigurationMapper = eventMapper)
)
}
return this
}

/**
* Allows to set the necessary security configuration (used to control local
* data storage encryption, for example).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal data class RumEventMapper(
val errorEventMapper: EventMapper<ErrorEvent> = NoOpEventMapper(),
val resourceEventMapper: EventMapper<ResourceEvent> = NoOpEventMapper(),
val actionEventMapper: EventMapper<ActionEvent> = NoOpEventMapper(),
val longTaskEventMapper: EventMapper<LongTaskEvent> = NoOpEventMapper()
val longTaskEventMapper: EventMapper<LongTaskEvent> = NoOpEventMapper(),
val telemetryConfigurationMapper: EventMapper<TelemetryConfigurationEvent> = NoOpEventMapper()
) : EventMapper<Any> {

override fun map(event: Any): Any? {
Expand All @@ -55,9 +56,9 @@ internal data class RumEventMapper(
}
is ResourceEvent -> resourceEventMapper.map(event)
is LongTaskEvent -> longTaskEventMapper.map(event)
is TelemetryConfigurationEvent -> telemetryConfigurationMapper.map(event)
is TelemetryDebugEvent,
is TelemetryErrorEvent,
is TelemetryConfigurationEvent -> event
is TelemetryErrorEvent -> event
else -> {
sdkLogger.warningWithTelemetry(
NO_EVENT_MAPPER_ASSIGNED_WARNING_MESSAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.os.Build
import android.util.Log
import com.datadog.android.DatadogEndpoint
import com.datadog.android.DatadogSite
import com.datadog.android._InternalProxy
import com.datadog.android.core.internal.event.NoOpEventMapper
import com.datadog.android.event.EventMapper
import com.datadog.android.event.NoOpSpanEventMapper
Expand All @@ -35,6 +36,7 @@ import com.datadog.android.rum.tracking.InteractionPredicate
import com.datadog.android.rum.tracking.NoOpInteractionPredicate
import com.datadog.android.rum.tracking.ViewAttributesProvider
import com.datadog.android.rum.tracking.ViewTrackingStrategy
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
import com.datadog.android.utils.config.LoggerTestConfiguration
import com.datadog.android.utils.forge.Configurator
import com.datadog.tools.unit.annotations.TestConfigurationsProvider
Expand Down Expand Up @@ -765,6 +767,30 @@ internal class ConfigurationBuilderTest {
assertThat(config.additionalConfig).isEmpty()
}

@Test
fun `𝕄 build config with RUM Telemetry eventMapper 𝕎 _InternalProxy setTelemetryConfigurationEventMapper() & build()`() {
// Given
val eventMapper: EventMapper<TelemetryConfigurationEvent> = mock()

// When
val builder = testedBuilder
_InternalProxy.setTelemetryConfigurationEventMapper(builder, eventMapper)
val config = builder.build()

// Then
assertThat(config.coreConfig).isEqualTo(Configuration.DEFAULT_CORE_CONFIG)
assertThat(config.logsConfig).isEqualTo(Configuration.DEFAULT_LOGS_CONFIG)
assertThat(config.tracesConfig).isEqualTo(Configuration.DEFAULT_TRACING_CONFIG)
assertThat(config.crashReportConfig).isEqualTo(Configuration.DEFAULT_CRASH_CONFIG)
val expectedRumEventMapper = RumEventMapper(telemetryConfigurationMapper = eventMapper)
assertThat(config.rumConfig).isEqualTo(
Configuration.DEFAULT_RUM_CONFIG.copy(
rumEventMapper = expectedRumEventMapper
)
)
assertThat(config.additionalConfig).isEmpty()
}

@Test
fun `𝕄 build config with plugin 𝕎 addPlugin() and build()`() {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ internal class RumEventMapperTest {
@Mock
lateinit var mockLongTaskEventMapper: EventMapper<LongTaskEvent>

@Mock
lateinit var mockTelemetryConfigurationMapper: EventMapper<TelemetryConfigurationEvent>

@BeforeEach
fun `set up`() {
whenever(mockViewEventMapper.map(any())).thenAnswer { it.arguments[0] }
Expand All @@ -80,7 +83,8 @@ internal class RumEventMapperTest {
viewEventMapper = mockViewEventMapper,
resourceEventMapper = mockResourceEventMapper,
errorEventMapper = mockErrorEventMapper,
longTaskEventMapper = mockLongTaskEventMapper
longTaskEventMapper = mockLongTaskEventMapper,
telemetryConfigurationMapper = mockTelemetryConfigurationMapper
)
}

Expand Down Expand Up @@ -211,14 +215,19 @@ internal class RumEventMapperTest {
}

@Test
fun `M return the original event W map { TelemetryConfigurationEvent }`(
fun `M return the bundled event W map { TelemetryConfigurationEvent }`(
@Forgery telemetryConfigurationEvent: TelemetryConfigurationEvent
) {
// GIVEN
whenever(mockTelemetryConfigurationMapper.map(telemetryConfigurationEvent))
.thenReturn(telemetryConfigurationEvent)

// WHEN
val mappedRumEvent = testedRumEventMapper.map(telemetryConfigurationEvent)

// THEN
verifyZeroInteractions(logger.mockSdkLogHandler)
verify(mockTelemetryConfigurationMapper).map(telemetryConfigurationEvent)
assertThat(mappedRumEvent).isSameAs(telemetryConfigurationEvent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ internal class RumEventMapperFactory : ForgeryFactory<RumEventMapper> {
viewEventMapper = mock(),
actionEventMapper = mock(),
resourceEventMapper = mock(),
errorEventMapper = mock()
errorEventMapper = mock(),
telemetryConfigurationMapper = mock()
)
}
}