Skip to content

Commit

Permalink
Show warning if incompatible spring boot version is detected (#3233)
Browse files Browse the repository at this point in the history
* check for spring boot version and show warning on startup if incompatible

* add changelog

* Update CHANGELOG.md

Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>

---------

Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>
  • Loading branch information
lbloder and adinauer authored Feb 29, 2024
1 parent a816b3f commit c7addb9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- 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.)
- Configurable defaults for Cron - MonitorConfig ([#3195](https://github.com/getsentry/sentry-java/pull/3195))
- 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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ApplicationContextInitializedEvent> {

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("#######################################################################");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.context.ApplicationListener=io.sentry.spring.boot.jakarta.SentrySpringVersionChecker
Original file line number Diff line number Diff line change
@@ -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<ApplicationContextInitializedEvent> {

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("#######################################################################");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c7addb9

Please sign in to comment.