From 06c8bea34c0c9b64be4fe601456c10b5cef7b656 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Tue, 27 Feb 2024 17:09:03 +0100 Subject: [PATCH 1/3] check for spring boot version and show warning on startup if incompatible --- .../jakarta/SentrySpringVersionChecker.java | 30 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + .../boot/SentrySpringVersionChecker.java | 30 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 2 ++ 4 files changed, 63 insertions(+) create mode 100644 sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpringVersionChecker.java create mode 100644 sentry-spring-boot-jakarta/src/main/resources/META-INF/spring.factories create mode 100644 sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentrySpringVersionChecker.java diff --git a/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpringVersionChecker.java b/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpringVersionChecker.java new file mode 100644 index 0000000000..7fb6d1ce23 --- /dev/null +++ b/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpringVersionChecker.java @@ -0,0 +1,30 @@ +package io.sentry.spring.boot.jakarta; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.boot.SpringBootVersion; +import org.springframework.boot.context.event.ApplicationContextInitializedEvent; +import org.springframework.context.ApplicationListener; + +final class SentrySpringVersionChecker + implements ApplicationListener { + + private static final Log logger = LogFactory.getLog(SentrySpringVersionChecker.class); + + @Override + public void onApplicationEvent(ApplicationContextInitializedEvent event) { + + if (!SpringBootVersion.getVersion().startsWith("3")) { + logger.warn("############################### WARNING ###############################"); + logger.warn("## ##"); + logger.warn("## !Incompatible Spring Boot Version detected! ##"); + logger.warn("## Please see the sentry docs linked below ##"); + logger.warn("## Choose your Spring Boot version and ##"); + logger.warn("## install the matching dependency ##"); + logger.warn("## ##"); + logger.warn("## https://docs.sentry.io/platforms/java/guides/spring-boot/#install ##"); + logger.warn("## ##"); + logger.warn("#######################################################################"); + } + } +} diff --git a/sentry-spring-boot-jakarta/src/main/resources/META-INF/spring.factories b/sentry-spring-boot-jakarta/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..4002cb6ed5 --- /dev/null +++ b/sentry-spring-boot-jakarta/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.context.ApplicationListener=io.sentry.spring.boot.jakarta.SentrySpringVersionChecker diff --git a/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentrySpringVersionChecker.java b/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentrySpringVersionChecker.java new file mode 100644 index 0000000000..1cbcb4f090 --- /dev/null +++ b/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentrySpringVersionChecker.java @@ -0,0 +1,30 @@ +package io.sentry.spring.boot; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.boot.SpringBootVersion; +import org.springframework.boot.context.event.ApplicationContextInitializedEvent; +import org.springframework.context.ApplicationListener; + +final class SentrySpringVersionChecker + implements ApplicationListener { + + private static final Log logger = LogFactory.getLog(SentrySpringVersionChecker.class); + + @Override + public void onApplicationEvent(ApplicationContextInitializedEvent event) { + + if (!SpringBootVersion.getVersion().startsWith("2")) { + logger.warn("############################### WARNING ###############################"); + logger.warn("## ##"); + logger.warn("## !Incompatible Spring Boot Version detected! ##"); + logger.warn("## Please see the sentry docs linked below ##"); + logger.warn("## Choose your Spring Boot version and ##"); + logger.warn("## install the matching dependency ##"); + logger.warn("## ##"); + logger.warn("## https://docs.sentry.io/platforms/java/guides/spring-boot/#install ##"); + logger.warn("## ##"); + logger.warn("#######################################################################"); + } + } +} diff --git a/sentry-spring-boot/src/main/resources/META-INF/spring.factories b/sentry-spring-boot/src/main/resources/META-INF/spring.factories index 0d71d6cad7..9712f4b407 100644 --- a/sentry-spring-boot/src/main/resources/META-INF/spring.factories +++ b/sentry-spring-boot/src/main/resources/META-INF/spring.factories @@ -2,3 +2,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ io.sentry.spring.boot.SentryAutoConfiguration,\ io.sentry.spring.boot.SentryLogbackAppenderAutoConfiguration,\ io.sentry.spring.boot.SentryWebfluxAutoConfiguration + +org.springframework.context.ApplicationListener=io.sentry.spring.boot.SentrySpringVersionChecker From 9100886cbf0e258c420f2c623fc974036920b95a Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Tue, 27 Feb 2024 17:18:29 +0100 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09417cf844..8d5eea909a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Add `enableScopePersistence` option to disable `PersistingScopeObserver` used for ANR reporting which may increase performance overhead. Defaults to `true` ([#3218](https://github.com/getsentry/sentry-java/pull/3218)) - When disabled, the SDK will not enrich ANRv2 events with scope data (e.g. breadcrumbs, user, tags, etc.) +- Show warning if incompatible spring boot version is detected ([#3233](https://github.com/getsentry/sentry-java/pull/3233)) ### Fixes From f0e2eff7294679ea0be78df07f587569c9d87248 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Thu, 29 Feb 2024 08:55:10 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Alexander Dinauer --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f23d26a37c..df1223a460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - Add support for measurements at span level ([#3219](https://github.com/getsentry/sentry-java/pull/3219)) - Add `enableScopePersistence` option to disable `PersistingScopeObserver` used for ANR reporting which may increase performance overhead. Defaults to `true` ([#3218](https://github.com/getsentry/sentry-java/pull/3218)) - When disabled, the SDK will not enrich ANRv2 events with scope data (e.g. breadcrumbs, user, tags, etc.) -- Show warning if incompatible spring boot version is detected ([#3233](https://github.com/getsentry/sentry-java/pull/3233)) +- We now display a warning on startup if an incompatible version of Spring Boot is detected ([#3233](https://github.com/getsentry/sentry-java/pull/3233)) + - This should help notice a mismatching Sentry dependency, especially when upgrading a Spring Boot application ### Fixes