-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef5a186
commit 54160e9
Showing
21 changed files
with
628 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ssion-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/ResourceWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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.sessionreplay.internal | ||
|
||
import com.datadog.android.sessionreplay.internal.processor.EnrichedResource | ||
|
||
internal interface ResourceWriter { | ||
/** | ||
* Writes the resource to disk. | ||
* @param resource to write | ||
*/ | ||
fun write(resource: EnrichedResource) | ||
} |
73 changes: 73 additions & 0 deletions
73
...ion-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/ResourcesFeature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.sessionreplay.internal | ||
|
||
import android.content.Context | ||
import com.datadog.android.api.feature.FeatureSdkCore | ||
import com.datadog.android.api.feature.StorageBackedFeature | ||
import com.datadog.android.api.net.RequestFactory | ||
import com.datadog.android.api.storage.FeatureStorageConfiguration | ||
import com.datadog.android.sessionreplay.internal.domain.ResourceRequestFactory | ||
import com.datadog.android.sessionreplay.internal.storage.NoOpResourceWriter | ||
import com.datadog.android.sessionreplay.internal.storage.SessionReplayResourceWriter | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
/** | ||
* Session Replay feature class, which needs to be registered with Datadog SDK instance. | ||
*/ | ||
internal class ResourcesFeature( | ||
private val sdkCore: FeatureSdkCore | ||
) : StorageBackedFeature { | ||
|
||
internal var dataWriter: ResourceWriter = NoOpResourceWriter() | ||
internal val initialized = AtomicBoolean(false) | ||
|
||
// region Feature | ||
|
||
override val name: String = SESSION_REPLAY_RESOURCES_FEATURE_NAME | ||
|
||
override val requestFactory: RequestFactory = ResourceRequestFactory( | ||
customEndpointUrl = null | ||
) | ||
|
||
override fun onInitialize(appContext: Context) { | ||
dataWriter = createResourceWriter() | ||
initialized.set(true) | ||
} | ||
|
||
override val storageConfiguration: FeatureStorageConfiguration = | ||
STORAGE_CONFIGURATION | ||
|
||
override fun onStop() { | ||
dataWriter = NoOpResourceWriter() | ||
initialized.set(false) | ||
} | ||
|
||
private fun createResourceWriter(): ResourceWriter { | ||
return SessionReplayResourceWriter(sdkCore) | ||
} | ||
|
||
// endregion | ||
|
||
internal companion object { | ||
|
||
/** | ||
* Session Replay storage configuration with the following parameters: | ||
* max item size = 10 MB, | ||
* max items per batch = 500, | ||
* max batch size = 10 MB, SR intake batch limit is 10MB | ||
* old batch threshold = 18 hours. | ||
*/ | ||
internal val STORAGE_CONFIGURATION: FeatureStorageConfiguration = | ||
FeatureStorageConfiguration.DEFAULT.copy( | ||
maxItemSize = 10 * 1024 * 1024, | ||
maxBatchSize = 10 * 1024 * 1024 | ||
) | ||
|
||
internal const val SESSION_REPLAY_RESOURCES_FEATURE_NAME = "session-replay-resources" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../kotlin/com/datadog/android/sessionreplay/internal/async/ResourceRecordedDataQueueItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.sessionreplay.internal.async | ||
|
||
import com.datadog.android.sessionreplay.internal.processor.RecordedQueuedItemContext | ||
|
||
internal class ResourceRecordedDataQueueItem( | ||
recordedQueuedItemContext: RecordedQueuedItemContext, | ||
val identifier: String, | ||
val applicationId: String, | ||
val resourceData: ByteArray | ||
) : RecordedDataQueueItem(recordedQueuedItemContext) { | ||
|
||
override fun isValid(): Boolean { | ||
return resourceData.isNotEmpty() | ||
} | ||
|
||
override fun isReady(): Boolean { | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/main/kotlin/com/datadog/android/sessionreplay/internal/processor/EnrichedResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.sessionreplay.internal.processor | ||
|
||
import com.google.gson.JsonObject | ||
|
||
internal data class EnrichedResource( | ||
internal val resource: ByteArray, | ||
internal val applicationId: String, | ||
internal val filename: String, | ||
internal val metadata: JsonObject = JsonObject().apply { | ||
this.addProperty(APPLICATION_ID_KEY, applicationId) | ||
this.addProperty(FILENAME_KEY, filename) | ||
} | ||
) { | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as EnrichedResource | ||
|
||
if (!resource.contentEquals(other.resource)) return false | ||
if (applicationId != other.applicationId) return false | ||
return filename == other.filename | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = resource.contentHashCode() | ||
result = 31 * result + applicationId.hashCode() | ||
result = 31 * result + filename.hashCode() | ||
return result | ||
} | ||
|
||
internal companion object { | ||
internal const val APPLICATION_ID_KEY = "application_id" | ||
internal const val FILENAME_KEY = "filename" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../src/main/kotlin/com/datadog/android/sessionreplay/internal/storage/NoOpResourceWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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.sessionreplay.internal.storage | ||
|
||
import com.datadog.android.sessionreplay.internal.ResourceWriter | ||
import com.datadog.android.sessionreplay.internal.processor.EnrichedResource | ||
|
||
internal class NoOpResourceWriter : ResourceWriter { | ||
override fun write(resource: EnrichedResource) { | ||
// no-op | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../kotlin/com/datadog/android/sessionreplay/internal/storage/SessionReplayResourceWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.sessionreplay.internal.storage | ||
|
||
import com.datadog.android.api.feature.FeatureSdkCore | ||
import com.datadog.android.api.storage.RawBatchEvent | ||
import com.datadog.android.sessionreplay.internal.ResourceWriter | ||
import com.datadog.android.sessionreplay.internal.ResourcesFeature.Companion.SESSION_REPLAY_RESOURCES_FEATURE_NAME | ||
import com.datadog.android.sessionreplay.internal.processor.EnrichedResource | ||
|
||
internal class SessionReplayResourceWriter( | ||
private val sdkCore: FeatureSdkCore | ||
) : ResourceWriter { | ||
override fun write(resource: EnrichedResource) { | ||
sdkCore.getFeature(SESSION_REPLAY_RESOURCES_FEATURE_NAME)?.withWriteContext() { _, eventBatchWriter -> | ||
synchronized(this) { | ||
val serializedMetadata = resource.metadata.toString().toByteArray(Charsets.UTF_8) | ||
@Suppress("ThreadSafety") // called from the worker thread | ||
eventBatchWriter.write( | ||
event = RawBatchEvent( | ||
data = resource.resource, | ||
metadata = serializedMetadata | ||
), | ||
batchMetadata = null | ||
) | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...src/test/kotlin/com/datadog/android/sessionreplay/forge/EnrichedResourceForgeryFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.sessionreplay.forge | ||
|
||
import com.datadog.android.sessionreplay.internal.processor.EnrichedResource | ||
import fr.xgouchet.elmyr.Forge | ||
import fr.xgouchet.elmyr.ForgeryFactory | ||
import java.util.UUID | ||
|
||
internal class EnrichedResourceForgeryFactory : ForgeryFactory<EnrichedResource> { | ||
override fun getForgery(forge: Forge): EnrichedResource { | ||
return EnrichedResource( | ||
applicationId = forge.getForgery<UUID>().toString(), | ||
filename = forge.getForgery<UUID>().toString(), | ||
resource = forge.getForgery<UUID>().toString().toByteArray() | ||
) | ||
} | ||
} |
Oops, something went wrong.