Skip to content

Commit

Permalink
RUMM-2602: Use event write context in RUM
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnm committed Oct 31, 2022
1 parent 4317825 commit d71fe7b
Show file tree
Hide file tree
Showing 41 changed files with 1,221 additions and 1,001 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal class DatadogExceptionHandler(
devLogger.i("Logs feature is not registered, won't report crash as log.")
}

// TODO RUMM-2697 Use message bus to communicate with RUM
// write a RUM Error too
(GlobalRum.get() as? AdvancedRumMonitor)?.addCrash(
createCrashMessage(e),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ interface RumMonitor {
*
* @see _RumInternalProxy
*/
@Suppress("FunctionNaming")
@Suppress("FunctionName")
fun _getInternal(): _RumInternalProxy?

// region Builder
Expand Down Expand Up @@ -296,11 +296,12 @@ interface RumMonitor {
} else {
DatadogRumMonitor(
applicationId = rumApplicationId,
sdkCore = datadogCore,
samplingRate = samplingRate ?: rumFeature.samplingRate,
writer = rumFeature.persistenceStrategy.getWriter(),
writer = rumFeature.dataWriter,
handler = Handler(Looper.getMainLooper()),
telemetryEventHandler = TelemetryEventHandler(
coreFeature.sdkVersion,
sdkCore = datadogCore,
RumEventSourceProvider(coreFeature.sourceName),
coreFeature.timeProvider,
RateBasedSampler(rumFeature.telemetrySamplingRate / 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.configuration.VitalsUpdateFrequency
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.event.NoOpEventMapper
import com.datadog.android.core.internal.persistence.NoOpPersistenceStrategy
import com.datadog.android.core.internal.persistence.PersistenceStrategy
import com.datadog.android.core.internal.persistence.file.batch.BatchFileReaderWriter
import com.datadog.android.core.internal.thread.NoOpScheduledExecutorService
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.executeSafe
import com.datadog.android.core.internal.utils.scheduleSafe
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.event.EventMapper
import com.datadog.android.event.MapperSerializer
import com.datadog.android.rum.internal.anr.ANRDetectorRunnable
import com.datadog.android.rum.internal.debug.UiRumDebugListener
import com.datadog.android.rum.internal.domain.RumFilePersistenceStrategy
import com.datadog.android.rum.internal.domain.RumDataWriter
import com.datadog.android.rum.internal.domain.event.RumEventSerializer
import com.datadog.android.rum.internal.ndk.DatadogNdkCrashHandler
import com.datadog.android.rum.internal.tracking.NoOpUserActionTrackingStrategy
import com.datadog.android.rum.internal.tracking.UserActionTrackingStrategy
Expand All @@ -42,7 +43,8 @@ import com.datadog.android.rum.tracking.NoOpTrackingStrategy
import com.datadog.android.rum.tracking.NoOpViewTrackingStrategy
import com.datadog.android.rum.tracking.TrackingStrategy
import com.datadog.android.rum.tracking.ViewTrackingStrategy
import com.datadog.android.v2.core.internal.storage.Storage
import com.datadog.android.v2.core.internal.storage.DataWriter
import com.datadog.android.v2.core.internal.storage.NoOpDataWriter
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
Expand All @@ -51,10 +53,9 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean

internal class RumFeature(
private val coreFeature: CoreFeature,
private val storage: Storage
private val coreFeature: CoreFeature
) {
internal var persistenceStrategy: PersistenceStrategy<Any> = NoOpPersistenceStrategy()
internal var dataWriter: DataWriter<Any> = NoOpDataWriter()
internal val initialized = AtomicBoolean(false)

internal var samplingRate: Float = 0f
Expand Down Expand Up @@ -83,7 +84,7 @@ internal class RumFeature(
// region SdkFeature

fun initialize(context: Context, configuration: Configuration.Feature.RUM) {
persistenceStrategy = createPersistenceStrategy(configuration)
dataWriter = createDataWriter(configuration)

samplingRate = configuration.samplingRate
telemetrySamplingRate = configuration.telemetrySamplingRate
Expand All @@ -109,6 +110,8 @@ internal class RumFeature(
fun stop() {
unregisterTrackingStrategies(appContext)

dataWriter = NoOpDataWriter()

viewTrackingStrategy = NoOpViewTrackingStrategy()
actionTrackingStrategy = NoOpUserActionTrackingStrategy()
longTaskTrackingStrategy = NoOpTrackingStrategy()
Expand All @@ -124,17 +127,18 @@ internal class RumFeature(
vitalExecutorService = NoOpScheduledExecutorService()
}

private fun createPersistenceStrategy(
private fun createDataWriter(
configuration: Configuration.Feature.RUM
): PersistenceStrategy<Any> {
return RumFilePersistenceStrategy(
coreFeature.contextProvider,
configuration.rumEventMapper,
coreFeature.persistenceExecutorService,
sdkLogger,
coreFeature.localDataEncryption,
DatadogNdkCrashHandler.getLastViewEventFile(coreFeature.storageDir),
storage
): DataWriter<Any> {
return RumDataWriter(
serializer = MapperSerializer(
configuration.rumEventMapper,
RumEventSerializer()
),
fileWriter = BatchFileReaderWriter.create(sdkLogger, coreFeature.localDataEncryption),
internalLogger = sdkLogger,
lastViewEventFile = DatadogNdkCrashHandler.getLastViewEventFile(coreFeature.storageDir)

)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package com.datadog.android.rum.internal.domain
import androidx.annotation.WorkerThread
import com.datadog.android.core.internal.persistence.Serializer
import com.datadog.android.core.internal.persistence.file.FileWriter
import com.datadog.android.core.internal.persistence.file.batch.BatchFileDataWriter
import com.datadog.android.core.internal.persistence.file.existsSafe
import com.datadog.android.core.internal.persistence.serializeToByteArray
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.log.Logger
import com.datadog.android.rum.GlobalRum
Expand All @@ -21,27 +21,39 @@ import com.datadog.android.rum.model.ErrorEvent
import com.datadog.android.rum.model.LongTaskEvent
import com.datadog.android.rum.model.ResourceEvent
import com.datadog.android.rum.model.ViewEvent
import com.datadog.android.v2.core.internal.ContextProvider
import com.datadog.android.v2.core.internal.storage.Storage
import com.datadog.android.v2.api.EventBatchWriter
import com.datadog.android.v2.core.internal.storage.DataWriter
import java.io.File
import java.util.Locale

internal class RumDataWriter(
storage: Storage,
contextProvider: ContextProvider,
serializer: Serializer<Any>,
private val serializer: Serializer<Any>,
private val fileWriter: FileWriter,
internalLogger: Logger,
private val internalLogger: Logger,
private val lastViewEventFile: File
) : BatchFileDataWriter<Any>(
storage,
contextProvider,
serializer,
internalLogger
) {
) : DataWriter<Any> {

// region DataWriter

@WorkerThread
override fun onDataWritten(data: Any, rawData: ByteArray) {
override fun write(writer: EventBatchWriter, element: Any): Boolean {
val byteArray = serializer.serializeToByteArray(element, internalLogger) ?: return false

synchronized(this) {
val result = writer.write(byteArray, null)
if (result) {
onDataWritten(element, byteArray)
}
return result
}
}

// endregion

// region Internal

@WorkerThread
internal fun onDataWritten(data: Any, rawData: ByteArray) {
when (data) {
is ViewEvent -> persistViewEvent(rawData)
is ActionEvent -> notifyEventSent(
Expand All @@ -64,10 +76,6 @@ internal class RumDataWriter(
}
}

// endregion

// region Internal

@WorkerThread
private fun persistViewEvent(data: ByteArray) {
// directory structure may not exist: currently it is a file which is located in NDK reports
Expand Down

This file was deleted.

Loading

0 comments on commit d71fe7b

Please sign in to comment.