Skip to content

Commit

Permalink
Merge 372a2f0 into a709a40
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Sep 20, 2023
2 parents a709a40 + 372a2f0 commit 025e762
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 2 deletions.
1 change: 1 addition & 0 deletions sentry-quartz/api/sentry-quartz.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class io/sentry/quartz/SentryJobListener : org/quartz/JobListener {
public static final field SENTRY_CHECK_IN_ID_KEY Ljava/lang/String;
public static final field SENTRY_CHECK_IN_SLUG_KEY Ljava/lang/String;
public fun <init> ()V
public fun <init> (Lio/sentry/IHub;)V
public fun getName ()Ljava/lang/String;
public fun jobExecutionVetoed (Lorg/quartz/JobExecutionContext;)V
public fun jobToBeExecuted (Lorg/quartz/JobExecutionContext;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import io.sentry.BuildConfig;
import io.sentry.CheckIn;
import io.sentry.CheckInStatus;
import io.sentry.HubAdapter;
import io.sentry.IHub;
import io.sentry.MonitorConfig;
import io.sentry.MonitorSchedule;
import io.sentry.MonitorScheduleUnit;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.util.Objects;
import java.util.List;
import java.util.TimeZone;
import org.jetbrains.annotations.NotNull;
Expand All @@ -31,7 +34,14 @@ public final class SentryJobListener implements JobListener {
public static final String SENTRY_CHECK_IN_ID_KEY = "sentry-checkin-id";
public static final String SENTRY_CHECK_IN_SLUG_KEY = "sentry-checkin-slug";

private final @NotNull IHub hub;

public SentryJobListener() {
this(HubAdapter.getInstance());
}

public SentryJobListener(final @NotNull IHub hub) {
this.hub = Objects.requireNonNull(hub, "hub is required");
SentryIntegrationPackageStorage.getInstance().addIntegration("Quartz");
SentryIntegrationPackageStorage.getInstance()
.addPackage("maven:io.sentry:sentry-quartz", BuildConfig.VERSION_NAME);
Expand All @@ -45,6 +55,9 @@ public String getName() {
@Override
public void jobToBeExecuted(JobExecutionContext context) {
try {
if (isDisabled()) {
return;
}
final @NotNull String slug = getSlug(context.getJobDetail());
final @NotNull CheckIn checkIn = new CheckIn(slug, CheckInStatus.IN_PROGRESS);

Expand Down Expand Up @@ -184,6 +197,10 @@ public void jobExecutionVetoed(JobExecutionContext context) {
@Override
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
try {
if (isDisabled()) {
return;
}

final @Nullable Object checkInIdObjectFromContext = context.get(SENTRY_CHECK_IN_ID_KEY);
final @Nullable Object slugObjectFromContext = context.get(SENTRY_CHECK_IN_SLUG_KEY);
final @NotNull SentryId checkInId =
Expand All @@ -204,4 +221,8 @@ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jo
.log(SentryLevel.ERROR, "Unable to capture check-in in jobWasExecuted.", t);
}
}

private boolean isDisabled() {
return !hub.getOptions().isEnableAutomaticCheckIns();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sentry.logging.minimum-breadcrumb-level=debug
# Performance configuration
sentry.traces-sample-rate=1.0
sentry.enable-tracing=true
#sentry.enable-automatic-checkins=true
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 @@ -174,6 +174,7 @@ static class GraphqlConfiguration {}
@Configuration(proxyBeanMethods = false)
@Import(SentryQuartzConfiguration.class)
@Open
@ConditionalOnProperty(name = "sentry.enable-automatic-checkins")
@ConditionalOnClass({
SentryJobListener.class,
QuartzScheduler.class,
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,41 @@ 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`() {
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)
}
}

@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 @@ -174,6 +174,7 @@ static class GraphqlConfiguration {}
@Configuration(proxyBeanMethods = false)
@Import(SentryQuartzConfiguration.class)
@Open
@ConditionalOnProperty(name = "sentry.enable-automatic-checkins")
@ConditionalOnClass({
SentryJobListener.class,
QuartzScheduler.class,
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,41 @@ 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`() {
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)
}
}

@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

0 comments on commit 025e762

Please sign in to comment.