Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,7 @@ public void close(final boolean isRestarting) {
try {
flush(isRestarting ? 0 : options.getShutdownTimeoutMillis());
loggerBatchProcessor.close(isRestarting);
metricsBatchProcessor.close(isRestarting);
transport.close(isRestarting);
} catch (IOException e) {
options
Expand Down Expand Up @@ -1684,6 +1685,7 @@ public void close(final boolean isRestarting) {
@Override
public void flush(final long timeoutMillis) {
loggerBatchProcessor.flush(timeoutMillis);
metricsBatchProcessor.flush(timeoutMillis);
transport.flush(timeoutMillis);
}

Expand Down
22 changes: 20 additions & 2 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import io.sentry.hints.Cached
import io.sentry.hints.DiskFlushNotification
import io.sentry.hints.TransactionEnd
import io.sentry.logger.ILoggerBatchProcessor
import io.sentry.logger.ILoggerBatchProcessorFactory
import io.sentry.metrics.IMetricsBatchProcessor
import io.sentry.metrics.IMetricsBatchProcessorFactory
import io.sentry.protocol.Contexts
import io.sentry.protocol.Feedback
import io.sentry.protocol.Mechanism
Expand Down Expand Up @@ -78,6 +80,10 @@ class SentryClientTest {
class Fixture {
var transport = mock<ITransport>()
var factory = mock<ITransportFactory>()
var loggerBatchProcessor = mock<ILoggerBatchProcessor>()
var loggerBatchProcessorFactory = mock<ILoggerBatchProcessorFactory>()
var metricsBatchProcessor = mock<IMetricsBatchProcessor>()
var metricsBatchProcessorFactory = mock<IMetricsBatchProcessorFactory>()
val maxAttachmentSize: Long = (5 * 1024 * 1024).toLong()
val scopes = mock<IScopes>()
val sentryTracer: SentryTracer
Expand All @@ -94,12 +100,16 @@ class SentryClientTest {
setLogger(mock())
maxAttachmentSize = this@Fixture.maxAttachmentSize
setTransportFactory(factory)
logs.setLoggerBatchProcessorFactory(loggerBatchProcessorFactory)
metrics.setMetricsBatchProcessorFactory(metricsBatchProcessorFactory)
release = "0.0.1"
isTraceSampling = true
}

init {
whenever(factory.create(any(), any())).thenReturn(transport)
whenever(loggerBatchProcessorFactory.create(any(), any())).thenReturn(loggerBatchProcessor)
whenever(metricsBatchProcessorFactory.create(any(), any())).thenReturn(metricsBatchProcessor)
whenever(scopes.options).thenReturn(sentryOptions)
sentryTracer =
SentryTracer(
Expand Down Expand Up @@ -168,21 +178,29 @@ class SentryClientTest {

@Test
fun `when client is closed with isRestarting false, transport waits`() {
val sut = fixture.getSut()
val sut = fixture.getSut { options -> options.logs.isEnabled = true }
assertTrue(sut.isEnabled)
sut.close(false)
assertNotEquals(0, fixture.sentryOptions.shutdownTimeoutMillis)
verify(fixture.transport).flush(eq(fixture.sentryOptions.shutdownTimeoutMillis))
verify(fixture.loggerBatchProcessor).flush(eq(fixture.sentryOptions.shutdownTimeoutMillis))
verify(fixture.metricsBatchProcessor).flush(eq(fixture.sentryOptions.shutdownTimeoutMillis))
verify(fixture.transport).close(eq(false))
verify(fixture.loggerBatchProcessor).close(eq(false))
verify(fixture.metricsBatchProcessor).close(eq(false))
}

@Test
fun `when client is closed with isRestarting true, transport does not wait`() {
val sut = fixture.getSut()
val sut = fixture.getSut { options -> options.logs.isEnabled = true }
assertTrue(sut.isEnabled)
sut.close(true)
verify(fixture.transport).flush(eq(0))
verify(fixture.loggerBatchProcessor).flush(eq(0))
verify(fixture.metricsBatchProcessor).flush(eq(0))
verify(fixture.transport).close(eq(true))
verify(fixture.loggerBatchProcessor).close(eq(true))
verify(fixture.metricsBatchProcessor).close(eq(true))
}

@Test
Expand Down
Loading