@@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey
99import io.opentelemetry.api.common.Attributes
1010import io.opentelemetry.api.logs.Severity
1111import com.example.androidobservability.TestUtils.TelemetryType
12+ import com.launchdarkly.observability.api.Options
1213import junit.framework.TestCase.assertEquals
1314import junit.framework.TestCase.assertFalse
1415import junit.framework.TestCase.assertNotNull
@@ -27,22 +28,23 @@ class DisablingConfigOptionsE2ETest {
2728 private val application = ApplicationProvider .getApplicationContext<Application >() as TestApplication
2829
2930 @Test
30- fun `Logs should not be exported when disableLogs is set to true` () {
31- application.pluginOptions = application.pluginOptions .copy(disableLogs = true )
31+ fun `Logs should NOT be exported when disableLogs is set to true` () {
32+ application.pluginOptions = getOptionsAllEnabled() .copy(disableLogs = true )
3233 application.initForTest()
3334 val logsUrl = " http://localhost:${application.mockWebServer?.port} /v1/logs"
3435
3536 triggerTestLog()
3637 LDObserve .flush()
3738 waitForTelemetryData(telemetryInspector = application.telemetryInspector, telemetryType = TelemetryType .LOGS )
39+ val logsExported = application.telemetryInspector?.logExporter?.finishedLogRecordItems
3840
39- assertNull(application.telemetryInspector?.logExporter )
41+ assertTrue(logsExported?.isEmpty() == true )
4042 assertFalse(requestsContainsUrl(logsUrl))
4143 }
4244
4345 @Test
4446 fun `Logs should be exported when disableLogs is set to false` () {
45- application.pluginOptions = application.pluginOptions .copy(disableLogs = false )
47+ application.pluginOptions = getOptionsAllEnabled() .copy(disableLogs = false )
4648 application.initForTest()
4749 val logsUrl = " http://localhost:${application.mockWebServer?.port} /v1/logs"
4850
@@ -56,21 +58,23 @@ class DisablingConfigOptionsE2ETest {
5658
5759 @Test
5860 fun `Spans should NOT be exported when disableTraces is set to true` () {
59- application.pluginOptions = application.pluginOptions .copy(disableTraces = true )
61+ application.pluginOptions = getOptionsAllEnabled() .copy(disableTraces = true )
6062 application.initForTest()
6163 val tracesUrl = " http://localhost:${application.mockWebServer?.port} /v1/traces"
6264
6365 triggerTestSpan()
6466 LDObserve .flush()
67+
6568 waitForTelemetryData(telemetryInspector = application.telemetryInspector, telemetryType = TelemetryType .SPANS )
69+ val spansExported = application.telemetryInspector?.spanExporter?.finishedSpanItems
6670
67- assertNull(application.telemetryInspector?.spanExporter )
71+ assertTrue(spansExported?.isEmpty() == true )
6872 assertFalse(requestsContainsUrl(tracesUrl))
6973 }
7074
7175 @Test
7276 fun `Spans should be exported when disableTraces is set to false` () {
73- application.pluginOptions = application.pluginOptions .copy(disableTraces = false )
77+ application.pluginOptions = getOptionsAllEnabled() .copy(disableTraces = false )
7478 application.initForTest()
7579 val tracesUrl = " http://localhost:${application.mockWebServer?.port} /v1/traces"
7680
@@ -84,7 +88,7 @@ class DisablingConfigOptionsE2ETest {
8488
8589 @Test
8690 fun `Metrics should NOT be exported when disableMetrics is set to true` () {
87- application.pluginOptions = application.pluginOptions .copy(disableMetrics = true )
91+ application.pluginOptions = getOptionsAllEnabled() .copy(disableMetrics = true )
8892 application.initForTest()
8993 val metricsUrl = " http://localhost:${application.mockWebServer?.port} /v1/metrics"
9094
@@ -98,7 +102,7 @@ class DisablingConfigOptionsE2ETest {
98102
99103 @Test
100104 fun `Metrics should be exported when disableMetrics is set to false` () {
101- application.pluginOptions = application.pluginOptions .copy(disableMetrics = false )
105+ application.pluginOptions = getOptionsAllEnabled() .copy(disableMetrics = false )
102106 application.initForTest()
103107 val metricsUrl = " http://localhost:${application.mockWebServer?.port} /v1/metrics"
104108
@@ -112,7 +116,7 @@ class DisablingConfigOptionsE2ETest {
112116
113117 @Test
114118 fun `Errors should NOT be exported when disableErrorTracking is set to true` () {
115- application.pluginOptions = application.pluginOptions .copy(disableErrorTracking = true )
119+ application.pluginOptions = getOptionsAllEnabled() .copy(disableErrorTracking = true )
116120 application.initForTest()
117121 val tracesUrl = " http://localhost:${application.mockWebServer?.port} /v1/traces"
118122
@@ -127,8 +131,8 @@ class DisablingConfigOptionsE2ETest {
127131 }
128132
129133 @Test
130- fun `Errors should be exported when disableErrorTracking is set to false` () {
131- application.pluginOptions = application.pluginOptions. copy(disableErrorTracking = false )
134+ fun `Errors should be exported as spans when disableErrorTracking is set to false and disableTraces set to true ` () {
135+ application.pluginOptions = getOptionsAllEnabled(). copy(disableTraces = true , disableErrorTracking = false )
132136 application.initForTest()
133137 val tracesUrl = " http://localhost:${application.mockWebServer?.port} /v1/traces"
134138
@@ -146,6 +150,41 @@ class DisablingConfigOptionsE2ETest {
146150 )
147151 }
148152
153+ @Test
154+ fun `Crashes should NOT be exported when disableErrorTracking is set to true` () {
155+ application.pluginOptions = getOptionsAllEnabled().copy(disableErrorTracking = true )
156+ application.initForTest()
157+ val logsUrl = " http://localhost:${application.mockWebServer?.port} /v1/logs"
158+
159+ Thread { throw RuntimeException (" Exception for testing" ) }.start()
160+
161+ waitForTelemetryData(telemetryInspector = application.telemetryInspector, telemetryType = TelemetryType .LOGS )
162+ val logsExported = application.telemetryInspector?.logExporter?.finishedLogRecordItems
163+
164+ assertFalse(requestsContainsUrl(logsUrl))
165+ assertEquals(0 , logsExported?.size)
166+ }
167+
168+ @Test
169+ fun `Crashes should be exported as logs when disableErrorTracking is set to false and disableLogs set to true` () {
170+ application.pluginOptions = getOptionsAllEnabled().copy(disableLogs = true , disableErrorTracking = false )
171+ application.initForTest()
172+ val logsUrl = " http://localhost:${application.mockWebServer?.port} /v1/logs"
173+ val exceptionMessage = " Exception for testing"
174+
175+ Thread { throw RuntimeException (exceptionMessage) }.start()
176+
177+ waitForTelemetryData(telemetryInspector = application.telemetryInspector, telemetryType = TelemetryType .LOGS )
178+ val logsExported = application.telemetryInspector?.logExporter?.finishedLogRecordItems
179+
180+ assertTrue(requestsContainsUrl(logsUrl))
181+ assertEquals(1 , logsExported?.size)
182+ assertEquals(
183+ exceptionMessage,
184+ logsExported?.get(0 )?.attributes?.get(AttributeKey .stringKey(" exception.message" ))
185+ )
186+ }
187+
149188 private fun requestsContainsUrl (url : String ): Boolean {
150189 while (true ) {
151190 val request = application.mockWebServer?.takeRequest(100 , TimeUnit .MILLISECONDS )
@@ -180,4 +219,14 @@ class DisablingConfigOptionsE2ETest {
180219 private fun triggerTestMetric () {
181220 LDObserve .recordMetric(Metric (" test" , 50.0 ))
182221 }
222+
223+ private fun getOptionsAllEnabled (): Options {
224+ return Options (
225+ debug = true ,
226+ disableTraces = false ,
227+ disableLogs = false ,
228+ disableMetrics = false ,
229+ disableErrorTracking = false
230+ )
231+ }
183232}
0 commit comments