Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for ignoring certain monitor slugs #2943

Merged
merged 25 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b2debe
checkin
adinauer Sep 11, 2023
1de0ba7
Add trace context, release and env; factory methods; fix serializatio…
adinauer Sep 12, 2023
3dd4fce
add tests
adinauer Sep 13, 2023
41cd16d
remove serial version uid
adinauer Sep 13, 2023
97b8e63
Merge branch 'main' into feat/crons
adinauer Sep 13, 2023
083e021
add back serial version uid
adinauer Sep 13, 2023
4828fa3
quartz support for spring jakarta
adinauer Sep 15, 2023
ef54e76
changelog
adinauer Sep 15, 2023
cc23d3c
code review changes; add sample code to spring scheduled job
adinauer Sep 15, 2023
6038dc5
Merge branch 'feat/crons' into feat/crons-quartz
adinauer Sep 15, 2023
44a3c75
add checkin example to scheduled job
adinauer Sep 15, 2023
b558570
Merge branch 'feat/crons' into feat/crons-quartz
adinauer Sep 15, 2023
0c29f12
Move quartz job listener into a separate module
adinauer Sep 18, 2023
24215e5
add quartz auto config to spring boot 2
adinauer Sep 19, 2023
68931af
Merge branch 'main' into feat/crons-quartz
adinauer Sep 19, 2023
a709a40
fix comment
adinauer Sep 19, 2023
372a2f0
Add enableAutomaticCheckIns and ignoreCheckIns options
adinauer Sep 20, 2023
66cb754
move __ slug logic
adinauer Sep 20, 2023
f4fb1dd
fix sample by adding quartz lib
adinauer Sep 20, 2023
2e7fb74
Merge branch 'feat/crons-quartz' into feat/crons-options
adinauer Sep 20, 2023
86e5ded
changelog
adinauer Sep 20, 2023
c420272
code review changes
adinauer Sep 22, 2023
fc2a884
ignore unused monitors
adinauer Sep 22, 2023
b2290f5
changelog
adinauer Sep 25, 2023
15d9388
Merge branch 'feat/crons-lib-support' into feat/crons-options
adinauer Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
- Add `sendModules` option for disable sending modules ([#2926](https://github.com/getsentry/sentry-java/pull/2926))
- Send `db.system` and `db.name` in span data for androidx.sqlite spans ([#2928](https://github.com/getsentry/sentry-java/pull/2928))
- Add API for sending checkins (CRONS) manually ([#2935](https://github.com/getsentry/sentry-java/pull/2935))
- Support check-ins for Quartz ([#2940](https://github.com/getsentry/sentry-java/pull/2940))
- Support check-ins (CRONS) for Quartz ([#2940](https://github.com/getsentry/sentry-java/pull/2940))
- Add option for ignoring certain monitor slugs ([#2943](https://github.com/getsentry/sentry-java/pull/2943))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ sentry.logging.minimum-breadcrumb-level=debug
# Performance configuration
sentry.traces-sample-rate=1.0
sentry.enable-tracing=true
sentry.enable-automatic-checkins=true
sentry.ignored-checkins=ignored_monitor_slug_1,ignored_monitor_slug_2
sentry.debug=true
in-app-includes="io.sentry.samples"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ sentry.logging.minimum-breadcrumb-level=debug
# Performance configuration
sentry.traces-sample-rate=1.0
sentry.enable-tracing=true
sentry.enable-automatic-checkins=true
sentry.ignored-checkins=ignored_monitor_slug_1,ignored_monitor_slug_2
sentry.debug=true
in-app-includes="io.sentry.samples"

Expand Down
2 changes: 2 additions & 0 deletions sentry-spring-boot-jakarta/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {

// tests
testImplementation(projects.sentryLogback)
testImplementation(projects.sentryQuartz)
testImplementation(projects.sentryApacheHttpClient5)
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
Expand All @@ -69,6 +70,7 @@ dependencies {
testImplementation(Config.Libs.springBoot3StarterWebflux)
testImplementation(Config.Libs.springBoot3StarterSecurity)
testImplementation(Config.Libs.springBoot3StarterAop)
testImplementation(Config.Libs.springBoot3StarterQuartz)
testImplementation(projects.sentryOpentelemetry.sentryOpentelemetryCore)
testImplementation(Config.Libs.contextPropagation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.sentry.checkEvent
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor
import io.sentry.protocol.SentryTransaction
import io.sentry.protocol.User
import io.sentry.quartz.SentryJobListener
import io.sentry.spring.jakarta.ContextTagsEventProcessor
import io.sentry.spring.jakarta.HttpServletRequestSentryUserProvider
import io.sentry.spring.jakarta.SentryExceptionResolver
Expand All @@ -36,9 +37,11 @@ import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.quartz.core.QuartzScheduler
import org.slf4j.MDC
import org.springframework.aop.support.NameMatchMethodPointcut
import org.springframework.boot.autoconfigure.AutoConfigurations
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
import org.springframework.boot.context.annotation.UserConfigurations
import org.springframework.boot.info.GitProperties
Expand All @@ -51,6 +54,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.scheduling.quartz.SchedulerFactoryBean
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.client.RestTemplate
import org.springframework.web.reactive.function.client.WebClient
Expand Down Expand Up @@ -157,7 +161,9 @@ class SentryAutoConfigurationTest {
"sentry.ignored-exceptions-for-type=java.lang.RuntimeException,java.lang.IllegalStateException,io.sentry.Sentry",
"sentry.trace-propagation-targets=localhost,^(http|https)://api\\..*\$",
"sentry.enabled=false",
"sentry.send-modules=false"
"sentry.send-modules=false",
"sentry.enable-automatic-checkins=true",
"sentry.ignored-checkins=slug1,slugB"
).run {
val options = it.getBean(SentryProperties::class.java)
assertThat(options.readTimeoutMillis).isEqualTo(10)
Expand Down Expand Up @@ -188,6 +194,8 @@ class SentryAutoConfigurationTest {
assertThat(options.tracePropagationTargets).containsOnly("localhost", "^(http|https)://api\\..*\$")
assertThat(options.isEnabled).isEqualTo(false)
assertThat(options.isSendModules).isEqualTo(false)
assertThat(options.isEnableAutomaticCheckIns).isEqualTo(true)
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
}
}

Expand Down Expand Up @@ -724,6 +732,57 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `when auto checkins is enabled, creates quartz config`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.run {
assertThat(it).hasSingleBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is enabled, does not create quartz config if quartz lib missing`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.withClassLoader(FilteredClassLoader(QuartzScheduler::class.java))
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is enabled, does not create quartz config if spring-quartz lib missing`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.withClassLoader(FilteredClassLoader(SchedulerFactoryBean::class.java))
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is enabled, does not create quartz config if sentry-quartz lib missing`() {
adinauer marked this conversation as resolved.
Show resolved Hide resolved
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.withClassLoader(FilteredClassLoader(SentryJobListener::class.java))
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is disabled, does not create quartz config`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=false")
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins option is skipped, does not create quartz config`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Configuration(proxyBeanMethods = false)
open class CustomOptionsConfigurationConfiguration {

Expand Down
2 changes: 2 additions & 0 deletions sentry-spring-boot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {

// tests
testImplementation(projects.sentryLogback)
testImplementation(projects.sentryQuartz)
testImplementation(projects.sentryApacheHttpClient5)
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
Expand All @@ -66,6 +67,7 @@ dependencies {
testImplementation(Config.Libs.springBootStarterWebflux)
testImplementation(Config.Libs.springBootStarterSecurity)
testImplementation(Config.Libs.springBootStarterAop)
testImplementation(Config.Libs.springBootStarterQuartz)
testImplementation(projects.sentryOpentelemetry.sentryOpentelemetryCore)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.sentry.checkEvent
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor
import io.sentry.protocol.SentryTransaction
import io.sentry.protocol.User
import io.sentry.quartz.SentryJobListener
import io.sentry.spring.ContextTagsEventProcessor
import io.sentry.spring.HttpServletRequestSentryUserProvider
import io.sentry.spring.SentryExceptionResolver
Expand All @@ -35,9 +36,11 @@ import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.quartz.core.QuartzScheduler
import org.slf4j.MDC
import org.springframework.aop.support.NameMatchMethodPointcut
import org.springframework.boot.autoconfigure.AutoConfigurations
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
import org.springframework.boot.context.annotation.UserConfigurations
import org.springframework.boot.info.GitProperties
Expand All @@ -50,6 +53,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.scheduling.quartz.SchedulerFactoryBean
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.client.RestTemplate
import org.springframework.web.reactive.function.client.WebClient
Expand Down Expand Up @@ -157,7 +161,9 @@ class SentryAutoConfigurationTest {
"sentry.ignored-exceptions-for-type=java.lang.RuntimeException,java.lang.IllegalStateException,io.sentry.Sentry",
"sentry.trace-propagation-targets=localhost,^(http|https)://api\\..*\$",
"sentry.enabled=false",
"sentry.send-modules=false"
"sentry.send-modules=false",
"sentry.enable-automatic-checkins=true",
"sentry.ignored-checkins=slug1,slugB"
).run {
val options = it.getBean(SentryProperties::class.java)
assertThat(options.readTimeoutMillis).isEqualTo(10)
Expand Down Expand Up @@ -188,6 +194,8 @@ class SentryAutoConfigurationTest {
assertThat(options.tracePropagationTargets).containsOnly("localhost", "^(http|https)://api\\..*\$")
assertThat(options.isEnabled).isEqualTo(false)
assertThat(options.isSendModules).isEqualTo(false)
assertThat(options.isEnableAutomaticCheckIns).isEqualTo(true)
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
}
}

Expand Down Expand Up @@ -724,6 +732,57 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `when auto checkins is enabled, creates quartz config`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.run {
assertThat(it).hasSingleBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is enabled, does not create quartz config if quartz lib missing`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.withClassLoader(FilteredClassLoader(QuartzScheduler::class.java))
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is enabled, does not create quartz config if spring-quartz lib missing`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.withClassLoader(FilteredClassLoader(SchedulerFactoryBean::class.java))
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is enabled, does not create quartz config if sentry-quartz lib missing`() {
adinauer marked this conversation as resolved.
Show resolved Hide resolved
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")
.withClassLoader(FilteredClassLoader(SentryJobListener::class.java))
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins is disabled, does not create quartz config`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=false")
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Test
fun `when auto checkins option is skipped, does not create quartz config`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.run {
assertThat(it).doesNotHaveBean(SchedulerFactoryBeanCustomizer::class.java)
}
}

@Configuration(proxyBeanMethods = false)
open class CustomOptionsConfigurationConfiguration {

Expand Down
13 changes: 13 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public final class io/sentry/ExternalOptions {
public fun getEnableUncaughtExceptionHandler ()Ljava/lang/Boolean;
public fun getEnvironment ()Ljava/lang/String;
public fun getIdleTimeout ()Ljava/lang/Long;
public fun getIgnoredCheckIns ()Ljava/util/List;
public fun getIgnoredExceptionsForType ()Ljava/util/Set;
public fun getInAppExcludes ()Ljava/util/List;
public fun getInAppIncludes ()Ljava/util/List;
Expand All @@ -335,19 +336,22 @@ public final class io/sentry/ExternalOptions {
public fun getTracePropagationTargets ()Ljava/util/List;
public fun getTracesSampleRate ()Ljava/lang/Double;
public fun getTracingOrigins ()Ljava/util/List;
public fun isEnableAutomaticCheckIns ()Ljava/lang/Boolean;
public fun isEnablePrettySerializationOutput ()Ljava/lang/Boolean;
public fun isEnabled ()Ljava/lang/Boolean;
public fun isSendModules ()Ljava/lang/Boolean;
public fun setDebug (Ljava/lang/Boolean;)V
public fun setDist (Ljava/lang/String;)V
public fun setDsn (Ljava/lang/String;)V
public fun setEnableAutomaticCheckIns (Ljava/lang/Boolean;)V
public fun setEnableDeduplication (Ljava/lang/Boolean;)V
public fun setEnablePrettySerializationOutput (Ljava/lang/Boolean;)V
public fun setEnableTracing (Ljava/lang/Boolean;)V
public fun setEnableUncaughtExceptionHandler (Ljava/lang/Boolean;)V
public fun setEnabled (Ljava/lang/Boolean;)V
public fun setEnvironment (Ljava/lang/String;)V
public fun setIdleTimeout (Ljava/lang/Long;)V
public fun setIgnoredCheckIns (Ljava/util/List;)V
public fun setMaxRequestBodySize (Lio/sentry/SentryOptions$RequestSize;)V
public fun setPrintUncaughtStackTrace (Ljava/lang/Boolean;)V
public fun setProfilesSampleRate (Ljava/lang/Double;)V
Expand Down Expand Up @@ -1929,6 +1933,7 @@ public class io/sentry/SentryOptions {
public fun getGestureTargetLocators ()Ljava/util/List;
public fun getHostnameVerifier ()Ljavax/net/ssl/HostnameVerifier;
public fun getIdleTimeout ()Ljava/lang/Long;
public fun getIgnoredCheckIns ()Ljava/util/List;
public fun getIgnoredExceptionsForType ()Ljava/util/Set;
public fun getInAppExcludes ()Ljava/util/List;
public fun getInAppIncludes ()Ljava/util/List;
Expand Down Expand Up @@ -1979,6 +1984,7 @@ public class io/sentry/SentryOptions {
public fun isAttachThreads ()Z
public fun isDebug ()Z
public fun isEnableAutoSessionTracking ()Z
public fun isEnableAutomaticCheckIns ()Z
public fun isEnableDeduplication ()Z
public fun isEnableExternalConfiguration ()Z
public fun isEnableNdk ()Z
Expand Down Expand Up @@ -2015,6 +2021,7 @@ public class io/sentry/SentryOptions {
public fun setDistinctId (Ljava/lang/String;)V
public fun setDsn (Ljava/lang/String;)V
public fun setEnableAutoSessionTracking (Z)V
public fun setEnableAutomaticCheckIns (Z)V
public fun setEnableDeduplication (Z)V
public fun setEnableExternalConfiguration (Z)V
public fun setEnableNdk (Z)V
Expand All @@ -2035,6 +2042,7 @@ public class io/sentry/SentryOptions {
public fun setGestureTargetLocators (Ljava/util/List;)V
public fun setHostnameVerifier (Ljavax/net/ssl/HostnameVerifier;)V
public fun setIdleTimeout (Ljava/lang/Long;)V
public fun setIgnoredCheckIns (Ljava/util/List;)V
public fun setInstrumenter (Lio/sentry/Instrumenter;)V
public fun setLogger (Lio/sentry/ILogger;)V
public fun setMainThreadChecker (Lio/sentry/util/thread/IMainThreadChecker;)V
Expand Down Expand Up @@ -4310,6 +4318,11 @@ public abstract class io/sentry/transport/TransportResult {
public static fun success ()Lio/sentry/transport/TransportResult;
}

public final class io/sentry/util/CheckInUtils {
public fun <init> ()V
public static fun isIgnored (Ljava/util/List;Ljava/lang/String;)Z
}

public final class io/sentry/util/ClassLoaderUtils {
public fun <init> ()V
public static fun classLoaderOrDefault (Ljava/lang/ClassLoader;)Ljava/lang/ClassLoader;
Expand Down
24 changes: 24 additions & 0 deletions sentry/src/main/java/io/sentry/ExternalOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public final class ExternalOptions {
private @Nullable Boolean enabled;
private @Nullable Boolean enablePrettySerializationOutput;

private @Nullable Boolean enableAutomaticCheckIns;
private @Nullable List<String> ignoredCheckIns;

private @Nullable Boolean sendModules;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -126,6 +129,11 @@ public final class ExternalOptions {

options.setSendModules(propertiesProvider.getBooleanProperty("send-modules"));

options.setEnableAutomaticCheckIns(
propertiesProvider.getBooleanProperty("enable-automatic-checkins"));

options.setIgnoredCheckIns(propertiesProvider.getList("ignored-checkins"));

for (final String ignoredExceptionType :
propertiesProvider.getList("ignored-exceptions-for-type")) {
try {
Expand Down Expand Up @@ -383,4 +391,20 @@ public void setEnablePrettySerializationOutput(
public void setSendModules(final @Nullable Boolean sendModules) {
this.sendModules = sendModules;
}

public @Nullable Boolean isEnableAutomaticCheckIns() {
return enableAutomaticCheckIns;
}

public void setEnableAutomaticCheckIns(final @Nullable Boolean enableAutomaticCheckIns) {
this.enableAutomaticCheckIns = enableAutomaticCheckIns;
}

public void setIgnoredCheckIns(final @Nullable List<String> ignoredCheckIns) {
this.ignoredCheckIns = ignoredCheckIns;
}

public @Nullable List<String> getIgnoredCheckIns() {
return ignoredCheckIns;
}
}