Skip to content

Commit

Permalink
RUM-1187 Add more information into the batch telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusc83 committed Sep 27, 2023
1 parent 876f439 commit 938ab50
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import com.datadog.android.api.feature.Feature
import com.datadog.android.core.internal.configuration.DataUploadConfiguration
import com.datadog.android.core.internal.lifecycle.ProcessLifecycleMonitor
import com.datadog.android.core.internal.persistence.file.FilePersistenceConfig
import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOrchestrator
import com.datadog.android.core.internal.persistence.file.existsSafe
import com.datadog.android.core.internal.persistence.file.lengthSafe
import com.datadog.android.core.internal.time.TimeProvider
import com.datadog.android.core.sampling.RateBasedSampler
import com.datadog.android.core.sampling.Sampler
import com.datadog.android.privacy.TrackingConsent
import java.io.File
import java.util.Locale
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -99,7 +101,10 @@ internal class BatchMetricsDispatcher(
UPLOADER_WINDOW_KEY to filePersistenceConfig.recentDelayMs,

BATCH_REMOVAL_KEY to deletionReason.toString(),
IN_BACKGROUND_KEY to isInBackground.get()
IN_BACKGROUND_KEY to isInBackground.get(),
TRACKING_CONSENT_KEY to file.resolveFileOriginAsConsent(),
FILE_NAME to file.name,
THREAD_NAME to Thread.currentThread().name
)
}

Expand All @@ -118,7 +123,10 @@ internal class BatchMetricsDispatcher(
// be sent as a batch_delete telemetry later
BATCH_SIZE_KEY to file.lengthSafe(internalLogger),
BATCH_EVENTS_COUNT_KEY to batchMetadata.eventsCount,
FORCE_NEW_KEY to batchMetadata.forcedNew
FORCE_NEW_KEY to batchMetadata.forcedNew,
TRACKING_CONSENT_KEY to file.resolveFileOriginAsConsent(),
FILE_NAME to file.name,
THREAD_NAME to Thread.currentThread().name
)
}

Expand All @@ -144,6 +152,17 @@ internal class BatchMetricsDispatcher(
}
}

private fun File.resolveFileOriginAsConsent(): String? {
val fileDirectory = this.parentFile?.name ?: return null
return if (fileDirectory.matches(FeatureFileOrchestrator.IS_PENDING_DIR_REG_EX)) {
TrackingConsent.PENDING.toString().lowercase(Locale.US)
} else if (fileDirectory.matches(FeatureFileOrchestrator.IS_GRANTED_DIR_REG_EX)) {
TrackingConsent.GRANTED.toString().lowercase(Locale.US)
} else {
null
}
}

// endregion

companion object {
Expand Down Expand Up @@ -218,6 +237,15 @@ internal class BatchMetricsDispatcher(
/* The value for the type of the metric.*/
internal const val BATCH_CLOSED_TYPE_VALUE = "batch closed"

/* The value of the tracking consent according with this file origin.*/
internal const val TRACKING_CONSENT_KEY = "consent"

/* The file name.*/
internal const val FILE_NAME = "filename"

/* The thread name from which the current metric was sent.*/
internal const val THREAD_NAME = "thread"

// endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ internal class FeatureFileOrchestrator(
)

companion object {
private const val BASE_DIR_NAME_REG_EX = "([a-z]+[-|_])+"
internal val IS_GRANTED_DIR_REG_EX = Regex("${BASE_DIR_NAME_REG_EX}v[0-9]+")
internal val IS_PENDING_DIR_REG_EX = Regex("${BASE_DIR_NAME_REG_EX}pending-v[0-9]+")

internal const val VERSION = 2
internal const val PENDING_DIR = "%s-pending-v$VERSION"
internal const val PENDING_DIR_SUFFIX = "-pending-v$VERSION"
internal const val PENDING_DIR = "%s$PENDING_DIR_SUFFIX"
internal const val GRANTED_DIR = "%s-v$VERSION"

private val PERSISTENCE_CONFIG = FilePersistenceConfig()
Expand Down
Loading

0 comments on commit 938ab50

Please sign in to comment.