Skip to content

Commit

Permalink
Handle TelemetryUsageEvent in RumEventMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusc83 committed Sep 16, 2024
1 parent c17f90a commit db9a4f1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.datadog.android.rum.model.ViewEvent
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
import com.datadog.android.telemetry.model.TelemetryDebugEvent
import com.datadog.android.telemetry.model.TelemetryErrorEvent
import com.datadog.android.telemetry.model.TelemetryUsageEvent
import java.util.Locale

internal data class RumEventMapper(
Expand Down Expand Up @@ -61,6 +62,7 @@ internal data class RumEventMapper(
is LongTaskEvent -> longTaskEventMapper.map(event)
is TelemetryConfigurationEvent -> telemetryConfigurationMapper.map(event)
is TelemetryDebugEvent,
is TelemetryUsageEvent,
is TelemetryErrorEvent -> event
else -> {
internalLogger.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.datadog.android.rum.utils.verifyLog
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
import com.datadog.android.telemetry.model.TelemetryDebugEvent
import com.datadog.android.telemetry.model.TelemetryErrorEvent
import com.datadog.android.telemetry.model.TelemetryUsageEvent
import fr.xgouchet.elmyr.Forge
import fr.xgouchet.elmyr.annotation.Forgery
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
Expand Down Expand Up @@ -208,6 +209,18 @@ internal class RumEventMapperTest {
assertThat(mappedRumEvent).isEqualTo(fakeRumEvent)
}

@Test
fun `M return the original event W map { TelemetryUsageEvent }`(
@Forgery telemetryUsageEvent: TelemetryUsageEvent
) {
// WHEN
val mappedRumEvent = testedRumEventMapper.map(telemetryUsageEvent)

// THEN
verifyNoInteractions(mockInternalLogger)
assertThat(mappedRumEvent).isSameAs(telemetryUsageEvent)
}

@Test
fun `M return the original event W map { TelemetryDebugEvent }`(
@Forgery telemetryDebugEvent: TelemetryDebugEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal class Configurator : BaseConfigurator() {
forge.addFactory(TelemetryDebugEventForgeryFactory())
forge.addFactory(TelemetryErrorEventForgeryFactory())
forge.addFactory(TelemetryConfigurationEventForgeryFactory())
forge.addFactory(TelemetryUsageEventForgeryFactory())

// Telemetry internal models
forge.addFactory(InternalTelemetryEventForgeryFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.rum.utils.forge

import com.datadog.android.telemetry.model.TelemetryUsageEvent
import com.datadog.android.tests.elmyr.exhaustiveAttributes
import fr.xgouchet.elmyr.Forge
import fr.xgouchet.elmyr.ForgeryFactory

internal class TelemetryUsageEventForgeryFactory : ForgeryFactory<TelemetryUsageEvent> {
override fun getForgery(forge: Forge): TelemetryUsageEvent {
return TelemetryUsageEvent(
dd = TelemetryUsageEvent.Dd(),
date = forge.aPositiveLong(),
service = forge.anAlphabeticalString(),
source = forge.aValueFrom(TelemetryUsageEvent.Source::class.java),
version = forge.anAlphabeticalString(),
application = forge.aNullable {
TelemetryUsageEvent.Application(
id = anAlphabeticalString()
)
},
session = forge.aNullable {
TelemetryUsageEvent.Session(
id = anAlphabeticalString()
)
},
view = forge.aNullable {
TelemetryUsageEvent.View(
id = anAlphabeticalString()
)
},
action = forge.aNullable {
TelemetryUsageEvent.Action(
id = anAlphabeticalString()
)
},
experimentalFeatures = forge.aNullable { aList { anAlphabeticalString() } },
telemetry = TelemetryUsageEvent.Telemetry(
device = forge.aNullable {
TelemetryUsageEvent.Device(
architecture = anAlphabeticalString(),
brand = anAlphabeticalString(),
model = anAlphabeticalString()
)
},
os = forge.aNullable {
TelemetryUsageEvent.Os(
build = anAlphabeticalString(),
name = anAlphabeticalString(),
version = anAlphabeticalString()
)
},
usage = TelemetryUsageEvent.Usage.AddViewLoadingTime(
noView = forge.aBool(),
noActiveView = forge.aBool(),
overwritten = forge.aBool()
),
additionalProperties = forge.exhaustiveAttributes()
)
)
}
}

0 comments on commit db9a4f1

Please sign in to comment.