@@ -23,6 +23,7 @@ import io.sentry.SentryEnvelope
2323import io.sentry.SentryLevel
2424import io.sentry.SentryLevel.DEBUG
2525import io.sentry.SentryLevel.FATAL
26+ import io.sentry.SentryLogEvent
2627import io.sentry.SentryOptions
2728import io.sentry.SentryOptions.BeforeSendCallback
2829import io.sentry.Session
@@ -84,6 +85,7 @@ import org.robolectric.annotation.Config
8485import org.robolectric.shadow.api.Shadow
8586import org.robolectric.shadows.ShadowActivityManager
8687import org.robolectric.shadows.ShadowActivityManager.ApplicationExitInfoBuilder
88+ import timber.log.Timber
8789
8890@RunWith(AndroidJUnit4 ::class )
8991@Config(sdk = [Build .VERSION_CODES .N ], shadows = [SentryShadowProcess ::class ])
@@ -238,6 +240,46 @@ class SentryAndroidTest {
238240 assertNotEquals(0 , AppStartMetrics .getInstance().appStartTimeSpan.durationMs)
239241 }
240242
243+ @Test
244+ fun `auto-installed Timber integration uses Logs option set in configuration callback` () {
245+ val logs = mutableListOf<SentryLogEvent >()
246+ fixture.initSut { options ->
247+ options.isEnableTimberLogs = true
248+ options.logs.beforeSend =
249+ SentryOptions .Logs .BeforeSendLogCallback { log ->
250+ logs.add(log)
251+ log
252+ }
253+ }
254+
255+ Timber .i(" message" )
256+
257+ assertEquals(1 , logs.size)
258+ }
259+
260+ @Test
261+ fun `auto-installed Timber integration uses configuration callback override of manifest option` () {
262+ val metadata =
263+ Bundle ().apply {
264+ putString(ManifestMetadataReader .DSN , " https://key@sentry.io/123" )
265+ putBoolean(ManifestMetadataReader .ENABLE_TIMBER_LOGS , true )
266+ }
267+ val mockContext = ContextUtilsTestHelper .mockMetaData(metaData = metadata)
268+ val logs = mutableListOf<SentryLogEvent >()
269+
270+ initForTest(mockContext) { options ->
271+ options.isEnableTimberLogs = false
272+ options.logs.beforeSend =
273+ SentryOptions .Logs .BeforeSendLogCallback { log ->
274+ logs.add(log)
275+ log
276+ }
277+ }
278+ Timber .i(" message" )
279+
280+ assertTrue(logs.isEmpty())
281+ }
282+
241283 @Test
242284 fun `deduplicates fragment, timber and system events integrations` () {
243285 var refOptions: SentryAndroidOptions ? = null
0 commit comments