Skip to content

Commit 8d081e4

Browse files
authored
Merge 0e1b15a into 1f3652d
2 parents 1f3652d + 0e1b15a commit 8d081e4

File tree

28 files changed

+472
-17
lines changed

28 files changed

+472
-17
lines changed

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/it/SentrySpringIntegrationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ class SentrySpringIntegrationTest {
210210

211211
@SpringBootApplication
212212
open class App {
213-
private val transport = mock<ITransport>()
213+
private val transport = mock<ITransport>().also {
214+
whenever(it.isHealthy).thenReturn(true)
215+
}
214216

215217
@Bean
216218
open fun mockTransportFactory(): ITransportFactory {

sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/it/SentrySpringIntegrationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ class SentrySpringIntegrationTest {
210210

211211
@SpringBootApplication
212212
open class App {
213-
private val transport = mock<ITransport>()
213+
private val transport = mock<ITransport>().also {
214+
whenever(it.isHealthy).thenReturn(true)
215+
}
214216

215217
@Bean
216218
open fun mockTransportFactory(): ITransportFactory {

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/EnableSentryTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import io.sentry.ITransportFactory
66
import io.sentry.Integration
77
import io.sentry.Sentry
88
import io.sentry.SentryOptions
9+
import io.sentry.transport.ITransport
910
import org.assertj.core.api.Assertions.assertThat
11+
import org.mockito.kotlin.any
1012
import org.mockito.kotlin.mock
13+
import org.mockito.kotlin.whenever
1114
import org.springframework.boot.context.annotation.UserConfigurations
1215
import org.springframework.boot.test.context.runner.ApplicationContextRunner
1316
import org.springframework.context.annotation.Bean
@@ -185,7 +188,9 @@ class EnableSentryTest {
185188
class AppConfigWithCustomTransportFactory {
186189

187190
@Bean
188-
fun transport() = mock<ITransportFactory>()
191+
fun transport() = mock<ITransportFactory>().also {
192+
whenever(it.create(any(), any())).thenReturn(mock<ITransport>())
193+
}
189194
}
190195

191196
@EnableSentry(dsn = "http://key@localhost/proj")

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebfluxIntegrationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ class SentryWebfluxIntegrationTest {
145145
@SpringBootApplication(exclude = [ReactiveSecurityAutoConfiguration::class, SecurityAutoConfiguration::class])
146146
open class App {
147147

148-
private val transport = mock<ITransport>()
148+
private val transport = mock<ITransport>().also {
149+
whenever(it.isHealthy).thenReturn(true)
150+
}
149151

150152
@Bean
151153
open fun mockTransportFactory(): ITransportFactory {

sentry-spring/src/test/kotlin/io/sentry/spring/EnableSentryTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import io.sentry.ITransportFactory
66
import io.sentry.Integration
77
import io.sentry.Sentry
88
import io.sentry.SentryOptions
9+
import io.sentry.transport.ITransport
910
import org.assertj.core.api.Assertions.assertThat
11+
import org.mockito.kotlin.any
1012
import org.mockito.kotlin.mock
13+
import org.mockito.kotlin.whenever
1114
import org.springframework.boot.context.annotation.UserConfigurations
1215
import org.springframework.boot.test.context.runner.ApplicationContextRunner
1316
import org.springframework.context.annotation.Bean
@@ -185,7 +188,9 @@ class EnableSentryTest {
185188
class AppConfigWithCustomTransportFactory {
186189

187190
@Bean
188-
fun transport() = mock<ITransportFactory>()
191+
fun transport() = mock<ITransportFactory>().also {
192+
whenever(it.create(any(), any())).thenReturn(mock<ITransport>())
193+
}
189194
}
190195

191196
@EnableSentry(dsn = "http://key@localhost/proj")

sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebfluxIntegrationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ class SentryWebfluxIntegrationTest {
145145
@SpringBootApplication(exclude = [ReactiveSecurityAutoConfiguration::class, SecurityAutoConfiguration::class])
146146
open class App {
147147

148-
private val transport = mock<ITransport>()
148+
private val transport = mock<ITransport>().also {
149+
whenever(it.isHealthy).thenReturn(true)
150+
}
149151

150152
@Bean
151153
open fun mockTransportFactory(): ITransportFactory {

sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
package io.sentry.test
33

44
import io.sentry.ISentryExecutorService
5+
import io.sentry.backpressure.IBackpressureMonitor
56
import org.mockito.kotlin.mock
67
import java.util.concurrent.Callable
78
import java.util.concurrent.Future
89

910
class ImmediateExecutorService : ISentryExecutorService {
1011
override fun submit(runnable: Runnable): Future<*> {
11-
runnable.run()
12+
if (runnable !is IBackpressureMonitor) {
13+
runnable.run()
14+
}
1215
return mock()
1316
}
1417

1518
override fun <T> submit(callable: Callable<T>): Future<T> = mock()
1619
override fun schedule(runnable: Runnable, delayMillis: Long): Future<*> {
17-
runnable.run()
20+
if (runnable !is IBackpressureMonitor) {
21+
runnable.run()
22+
}
1823
return mock<Future<Runnable>>()
1924
}
2025
override fun close(timeoutMillis: Long) {}

sentry/api/sentry.api

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ public final class io/sentry/Hub : io/sentry/IHub {
435435
public fun getTransaction ()Lio/sentry/ITransaction;
436436
public fun isCrashedLastRun ()Ljava/lang/Boolean;
437437
public fun isEnabled ()Z
438+
public fun isHealthy ()Z
438439
public fun popScope ()V
439440
public fun pushScope ()V
440441
public fun removeExtra (Ljava/lang/String;)V
@@ -485,6 +486,7 @@ public final class io/sentry/HubAdapter : io/sentry/IHub {
485486
public fun getTransaction ()Lio/sentry/ITransaction;
486487
public fun isCrashedLastRun ()Ljava/lang/Boolean;
487488
public fun isEnabled ()Z
489+
public fun isHealthy ()Z
488490
public fun popScope ()V
489491
public fun pushScope ()V
490492
public fun removeExtra (Ljava/lang/String;)V
@@ -578,6 +580,7 @@ public abstract interface class io/sentry/IHub {
578580
public abstract fun getTransaction ()Lio/sentry/ITransaction;
579581
public abstract fun isCrashedLastRun ()Ljava/lang/Boolean;
580582
public abstract fun isEnabled ()Z
583+
public abstract fun isHealthy ()Z
581584
public abstract fun popScope ()V
582585
public abstract fun pushScope ()V
583586
public abstract fun removeExtra (Ljava/lang/String;)V
@@ -718,6 +721,7 @@ public abstract interface class io/sentry/ISentryClient {
718721
public abstract fun flush (J)V
719722
public abstract fun getRateLimiter ()Lio/sentry/transport/RateLimiter;
720723
public abstract fun isEnabled ()Z
724+
public fun isHealthy ()Z
721725
}
722726

723727
public abstract interface class io/sentry/ISentryExecutorService {
@@ -1119,6 +1123,7 @@ public final class io/sentry/NoOpHub : io/sentry/IHub {
11191123
public fun getTransaction ()Lio/sentry/ITransaction;
11201124
public fun isCrashedLastRun ()Ljava/lang/Boolean;
11211125
public fun isEnabled ()Z
1126+
public fun isHealthy ()Z
11221127
public fun popScope ()V
11231128
public fun pushScope ()V
11241129
public fun removeExtra (Ljava/lang/String;)V
@@ -1665,6 +1670,7 @@ public final class io/sentry/Sentry {
16651670
public static fun init (Ljava/lang/String;)V
16661671
public static fun isCrashedLastRun ()Ljava/lang/Boolean;
16671672
public static fun isEnabled ()Z
1673+
public static fun isHealthy ()Z
16681674
public static fun popScope ()V
16691675
public static fun pushScope ()V
16701676
public static fun removeExtra (Ljava/lang/String;)V
@@ -1781,6 +1787,7 @@ public final class io/sentry/SentryClient : io/sentry/ISentryClient {
17811787
public fun flush (J)V
17821788
public fun getRateLimiter ()Lio/sentry/transport/RateLimiter;
17831789
public fun isEnabled ()Z
1790+
public fun isHealthy ()Z
17841791
}
17851792

17861793
public final class io/sentry/SentryCrashLastRunState {
@@ -2078,6 +2085,7 @@ public class io/sentry/SentryOptions {
20782085
public fun addOptionsObserver (Lio/sentry/IOptionsObserver;)V
20792086
public fun addScopeObserver (Lio/sentry/IScopeObserver;)V
20802087
public fun addTracingOrigin (Ljava/lang/String;)V
2088+
public fun getBackpressureMonitor ()Lio/sentry/backpressure/IBackpressureMonitor;
20812089
public fun getBeforeBreadcrumb ()Lio/sentry/SentryOptions$BeforeBreadcrumbCallback;
20822090
public fun getBeforeSend ()Lio/sentry/SentryOptions$BeforeSendCallback;
20832091
public fun getBeforeSendTransaction ()Lio/sentry/SentryOptions$BeforeSendTransactionCallback;
@@ -2156,6 +2164,7 @@ public class io/sentry/SentryOptions {
21562164
public fun isAttachThreads ()Z
21572165
public fun isDebug ()Z
21582166
public fun isEnableAutoSessionTracking ()Z
2167+
public fun isEnableBackpressureHandling ()Z
21592168
public fun isEnableDeduplication ()Z
21602169
public fun isEnableExternalConfiguration ()Z
21612170
public fun isEnablePrettySerializationOutput ()Z
@@ -2177,6 +2186,7 @@ public class io/sentry/SentryOptions {
21772186
public fun setAttachServerName (Z)V
21782187
public fun setAttachStacktrace (Z)V
21792188
public fun setAttachThreads (Z)V
2189+
public fun setBackpressureMonitor (Lio/sentry/backpressure/IBackpressureMonitor;)V
21802190
public fun setBeforeBreadcrumb (Lio/sentry/SentryOptions$BeforeBreadcrumbCallback;)V
21812191
public fun setBeforeSend (Lio/sentry/SentryOptions$BeforeSendCallback;)V
21822192
public fun setBeforeSendTransaction (Lio/sentry/SentryOptions$BeforeSendTransactionCallback;)V
@@ -2191,6 +2201,7 @@ public class io/sentry/SentryOptions {
21912201
public fun setDistinctId (Ljava/lang/String;)V
21922202
public fun setDsn (Ljava/lang/String;)V
21932203
public fun setEnableAutoSessionTracking (Z)V
2204+
public fun setEnableBackpressureHandling (Z)V
21942205
public fun setEnableDeduplication (Z)V
21952206
public fun setEnableExternalConfiguration (Z)V
21962207
public fun setEnablePrettySerializationOutput (Z)V
@@ -2821,6 +2832,24 @@ public final class io/sentry/UserFeedback$JsonKeys {
28212832
public fun <init> ()V
28222833
}
28232834

2835+
public final class io/sentry/backpressure/BackpressureMonitor : io/sentry/backpressure/IBackpressureMonitor, java/lang/Runnable {
2836+
public fun <init> (Lio/sentry/SentryOptions;Lio/sentry/IHub;)V
2837+
public fun getDownsampleFactor ()I
2838+
public fun run ()V
2839+
public fun start ()V
2840+
}
2841+
2842+
public abstract interface class io/sentry/backpressure/IBackpressureMonitor {
2843+
public abstract fun getDownsampleFactor ()I
2844+
public abstract fun start ()V
2845+
}
2846+
2847+
public final class io/sentry/backpressure/NoOpBackpressureMonitor : io/sentry/backpressure/IBackpressureMonitor {
2848+
public fun getDownsampleFactor ()I
2849+
public static fun getInstance ()Lio/sentry/backpressure/NoOpBackpressureMonitor;
2850+
public fun start ()V
2851+
}
2852+
28242853
public class io/sentry/cache/EnvelopeCache : io/sentry/cache/IEnvelopeCache {
28252854
public static final field CRASH_MARKER_FILE Ljava/lang/String;
28262855
public static final field NATIVE_CRASH_MARKER_FILE Ljava/lang/String;
@@ -4429,6 +4458,7 @@ public final class io/sentry/transport/AsyncHttpTransport : io/sentry/transport/
44294458
public fun close ()V
44304459
public fun flush (J)V
44314460
public fun getRateLimiter ()Lio/sentry/transport/RateLimiter;
4461+
public fun isHealthy ()Z
44324462
public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
44334463
}
44344464

@@ -4444,6 +4474,7 @@ public abstract interface class io/sentry/transport/ICurrentDateProvider {
44444474
public abstract interface class io/sentry/transport/ITransport : java/io/Closeable {
44454475
public abstract fun flush (J)V
44464476
public abstract fun getRateLimiter ()Lio/sentry/transport/RateLimiter;
4477+
public fun isHealthy ()Z
44474478
public fun send (Lio/sentry/SentryEnvelope;)V
44484479
public abstract fun send (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
44494480
}
@@ -4478,6 +4509,7 @@ public final class io/sentry/transport/RateLimiter {
44784509
public fun <init> (Lio/sentry/transport/ICurrentDateProvider;Lio/sentry/SentryOptions;)V
44794510
public fun filter (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/SentryEnvelope;
44804511
public fun isActiveForCategory (Lio/sentry/DataCategory;)Z
4512+
public fun isAnyRateLimitActive ()Z
44814513
public fun updateRetryAfterLimits (Ljava/lang/String;Ljava/lang/String;I)V
44824514
}
44834515

sentry/src/main/java/io/sentry/Hub.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,11 @@ public void bindClient(final @NotNull ISentryClient client) {
604604
}
605605
}
606606

607+
@Override
608+
public boolean isHealthy() {
609+
return stack.peek().getClient().isHealthy();
610+
}
611+
607612
@Override
608613
public void flush(long timeoutMillis) {
609614
if (!isEnabled()) {

sentry/src/main/java/io/sentry/HubAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public void bindClient(@NotNull ISentryClient client) {
168168
Sentry.bindClient(client);
169169
}
170170

171+
@Override
172+
public boolean isHealthy() {
173+
return Sentry.isHealthy();
174+
}
175+
171176
@Override
172177
public void flush(long timeoutMillis) {
173178
Sentry.flush(timeoutMillis);

0 commit comments

Comments
 (0)