Skip to content

Commit 6c0f222

Browse files
1 parent be0f376 commit 6c0f222

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/main/kotlin/com/statsig/sdk/ErrorBoundary.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ internal class ErrorBoundary(private val apiKey: String, private val options: St
5959
}
6060
}
6161

62-
internal fun logException(tag: String, ex: Throwable, configName: String? = null, extraInfo: String? = null) {
62+
internal fun logException(tag: String, ex: Throwable, configName: String? = null, extraInfo: String? = null, bypassDedupe: Boolean = false) {
6363
try {
64-
if (options.localMode || options.disableAllLogging || seen.contains(ex.javaClass.name)) {
64+
if (options.localMode || options.disableAllLogging) {
65+
return
66+
}
67+
if (!bypassDedupe && seen.contains(ex.javaClass.name)) {
6568
return
6669
}
67-
6870
seen.add(ex.javaClass.name)
6971

7072
val info = ex.stackTraceToString()
@@ -80,7 +82,7 @@ internal class ErrorBoundary(private val apiKey: String, private val options: St
8082
"statsigMetadata": ${statsigMetadata.asJson()},
8183
"configName": "$configName",
8284
"setupOptions": $optionsCopy,
83-
"extraInfo": $extraInfo
85+
"extra": $extraInfo
8486
}
8587
""".trimIndent()
8688
val req =

src/main/kotlin/com/statsig/sdk/StatsigNetwork.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ private const val MS_IN_S: Long = 1000
2626
const val STATSIG_API_URL_BASE: String = "https://statsigapi.net/v1"
2727
private const val STATSIG_CDN_URL_BASE: String = "https://api.statsigcdn.com/v1"
2828
const val LOG_EVENT_RETRY_COUNT = 5
29+
const val LOG_EVENT_FAILURE_TAG = "statsig::log_event_failed"
30+
2931
internal class StatsigNetwork(
3032
private val sdkKey: String,
3133
private val options: StatsigOptions,
@@ -257,6 +259,7 @@ internal class StatsigNetwork(
257259
return@coroutineScope
258260
} else if (!retryCodes.contains(response.code) || currRetry == 0) {
259261
options.customLogger.warning("[Statsig]: Network request failed with status code: ${response.code}")
262+
logPostLogFailure(eventsCount)
260263
return@coroutineScope
261264
} else if (retryCodes.contains(response.code) && currRetry > 0) {
262265
options.customLogger.info("[Statsig]: Retrying network request. Retry count: $currRetry. Response code: ${response.code}")
@@ -267,6 +270,10 @@ internal class StatsigNetwork(
267270
if (e is JsonParseException) {
268271
errorBoundary.logException("retryPostLogs", e)
269272
}
273+
if (currRetry == 0) {
274+
logPostLogFailure(eventsCount)
275+
return@coroutineScope
276+
}
270277
}
271278

272279
val count = retries - --currRetry
@@ -278,4 +285,17 @@ internal class StatsigNetwork(
278285
fun shutdown() {
279286
statsigHttpClient.dispatcher.executorService.shutdown()
280287
}
288+
289+
private fun logPostLogFailure(eventsCount: String) {
290+
errorBoundary.logException(
291+
LOG_EVENT_FAILURE_TAG,
292+
Exception("Drop log event"),
293+
null,
294+
extraInfo = """{
295+
"eventCount": $eventsCount
296+
}
297+
""".trimIndent(),
298+
bypassDedupe = true,
299+
)
300+
}
281301
}

src/main/kotlin/com/statsig/sdk/StatsigServer.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ sealed class StatsigServer {
196196
): CompletableFuture<Layer>
197197

198198
@JvmSynthetic abstract fun overrideLayerAsync(layerName: String, value: Map<String, Any>): CompletableFuture<Unit>
199+
199200
@JvmSynthetic abstract fun removeLayerOverrideAsync(layerName: String): CompletableFuture<Unit>
201+
200202
@JvmSynthetic abstract fun removeConfigOverrideAsync(configName: String): CompletableFuture<Unit>
203+
201204
@JvmSynthetic abstract fun removeGateOverrideAsync(gateName: String): CompletableFuture<Unit>
202205

203206
abstract fun manuallyLogLayerParameterExposureAsync(user: StatsigUser, layerName: String, paramName: String): CompletableFuture<Void>
@@ -216,6 +219,7 @@ sealed class StatsigServer {
216219

217220
@JvmSynthetic
218221
internal abstract suspend fun flush()
222+
219223
@JvmSynthetic internal abstract fun getCustomLogger(): LoggerInterface
220224

221225
companion object {

0 commit comments

Comments
 (0)