Skip to content

Commit b25c4aa

Browse files
committed
Removing noisy metric tags and adding stress test for telemetry
1 parent 546808d commit b25c4aa

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ open class Analytics protected constructor(
9898
Telemetry.INVOKE_ERROR_METRIC, t.stackTraceToString()) {
9999
it["error"] = t.toString()
100100
it["message"] = "Exception in Analytics Scope"
101-
it["caller"] = t.stackTrace[0].toString()
102101
}
103102
}
104103
override val analyticsScope = CoroutineScope(SupervisorJob() + exceptionHandler)

core/src/main/java/com/segment/analytics/kotlin/core/HTTPClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class HTTPClient(
3939
it["error"] = e.toString()
4040
it["writekey"] = writeKey
4141
it["message"] = "Malformed url"
42-
it["caller"] = e.stackTrace[0].toString()
4342
}
4443
throw error
4544
}

core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ internal fun Analytics.fetchSettings(
124124
it["error"] = ex.toString()
125125
it["writekey"] = writeKey
126126
it["message"] = "Error retrieving settings"
127-
it["caller"] = ex.stackTrace[0].toString()
128127
}
129128
configuration.defaultSettings
130129
}

core/src/main/java/com/segment/analytics/kotlin/core/platform/Mediator.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ internal class Mediator(internal var plugins: CopyOnWriteArrayList<Plugin> = Cop
6363
}
6464
it["writekey"] = plugin.analytics.configuration.writeKey
6565
it["message"] = "Exception executing plugin"
66-
it["caller"] = t.stackTrace[0].toString()
6766
}
6867
}
6968
}
@@ -88,7 +87,6 @@ internal class Mediator(internal var plugins: CopyOnWriteArrayList<Plugin> = Cop
8887
}
8988
it["writekey"] = plugin.analytics.configuration.writeKey
9089
it["message"] = "Exception executing plugin"
91-
it["caller"] = t.stackTrace[0].toString()
9290
}
9391
}
9492
}

core/src/test/kotlin/com/segment/analytics/kotlin/core/TelemetryTest.kt

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import org.junit.jupiter.api.Test
77
import java.lang.reflect.Field
88
import java.net.HttpURLConnection
99
import java.util.concurrent.ConcurrentLinkedQueue
10+
import java.util.concurrent.CountDownLatch
11+
import java.util.concurrent.Executors
12+
import java.util.concurrent.TimeUnit
13+
import kotlin.random.Random
1014

1115
class TelemetryTest {
1216
fun TelemetryResetFlushFirstError() {
@@ -182,7 +186,7 @@ class TelemetryTest {
182186
Telemetry.start()
183187
for (i in 1..Telemetry.maxQueueSize + 1) {
184188
Telemetry.increment(Telemetry.INVOKE_METRIC) { it["test"] = "test" + i }
185-
Telemetry.error(Telemetry.INVOKE_ERROR_METRIC, "error") { it["test"] = "test" + i }
189+
Telemetry.error(Telemetry.INVOKE_ERROR_METRIC, "error") { it["error"] = "test" + i }
186190
}
187191
assertEquals(Telemetry.maxQueueSize, TelemetryQueueSize())
188192
}
@@ -195,6 +199,44 @@ class TelemetryTest {
195199
Telemetry.sendWriteKeyOnError = false
196200
Telemetry.sendErrorLogData = false
197201
Telemetry.error(Telemetry.INVOKE_ERROR_METRIC, longString) { it["writekey"] = longString }
198-
assertTrue(TelemetryQueueSize() < 1000)
202+
assertTrue(TelemetryQueueBytes() < 1000)
203+
}
204+
205+
@Test
206+
fun testConcurrentErrorReportingWithQueuePressure() {
207+
val operationCount = 200
208+
val latch = CountDownLatch(operationCount)
209+
val executor = Executors.newFixedThreadPool(3)
210+
211+
try {
212+
// Launch operations across multiple threads
213+
repeat(operationCount) { i ->
214+
executor.submit {
215+
try {
216+
Telemetry.error(
217+
metric = Telemetry.INVOKE_ERROR_METRIC,
218+
log = "High pressure test $i"
219+
) {
220+
it["error"] = "pressure_test_key"
221+
it["iteration"] = "$i"
222+
}
223+
224+
// Add random delays to increase race condition probability
225+
if (i % 5 == 0) {
226+
Thread.sleep(Random.nextLong(1, 3))
227+
}
228+
} finally {
229+
latch.countDown()
230+
}
231+
}
232+
}
233+
234+
// Wait for all operations to complete
235+
latch.await(15, TimeUnit.SECONDS)
236+
237+
} finally {
238+
executor.shutdown()
239+
}
240+
assertTrue(TelemetryQueueSize() == Telemetry.maxQueueSize)
199241
}
200242
}

0 commit comments

Comments
 (0)