diff --git a/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java b/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java index 62052497f1..41726cf60c 100644 --- a/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java +++ b/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java @@ -188,6 +188,7 @@ static class OpenTelemetryNoAgentConfiguration {} options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it)); Sentry.init(options); warnForLegacyLogsConfiguration(environment, options); + warnForLegacyMetricsConfiguration(environment, options); return ScopesAdapter.getInstance(); } @@ -216,6 +217,29 @@ private void warnForLegacyLogsConfiguration( } } + private void warnForLegacyMetricsConfiguration( + final @NotNull Environment environment, final @NotNull SentryOptions options) { + if (environment.containsProperty("sentry.metrics.enabled")) { + final boolean enableMetrics = + Boolean.TRUE.equals(environment.getProperty("sentry.metrics.enabled", Boolean.class)); + if (enableMetrics) { + options + .getLogger() + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property is no longer supported. Manual " + + "Sentry.metrics() calls no longer require it."); + } else { + options + .getLogger() + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property no longer disables manual " + + "Sentry.metrics() calls."); + } + } + } + @Configuration(proxyBeanMethods = false) @ConditionalOnClass(MDC.class) @Open diff --git a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt index c3a7556e3e..5aabbdef92 100644 --- a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt @@ -247,6 +247,52 @@ class SentryAutoConfigurationTest { } } + @Test + fun `legacy metrics property emits no warning when absent`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } + } + + @Test + fun `legacy metrics property true emits migration warning`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=true") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { + verify(logger) + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property is no longer supported. Manual " + + "Sentry.metrics() calls no longer require it.", + *emptyArray(), + ) + } + } + + @Test + fun `legacy metrics property false emits migration warning`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=false") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { + verify(logger) + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property no longer disables manual " + + "Sentry.metrics() calls.", + *emptyArray(), + ) + } + } + @Test fun `properties are applied to SentryOptions`() { contextRunner diff --git a/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java b/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java index 555f2dcbe3..b215e05c7a 100644 --- a/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java +++ b/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java @@ -190,6 +190,7 @@ static class OpenTelemetryNoAgentConfiguration {} options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it)); Sentry.init(options); warnForLegacyLogsConfiguration(environment, options); + warnForLegacyMetricsConfiguration(environment, options); return ScopesAdapter.getInstance(); } @@ -218,6 +219,29 @@ private void warnForLegacyLogsConfiguration( } } + private void warnForLegacyMetricsConfiguration( + final @NotNull Environment environment, final @NotNull SentryOptions options) { + if (environment.containsProperty("sentry.metrics.enabled")) { + final boolean enableMetrics = + Boolean.TRUE.equals(environment.getProperty("sentry.metrics.enabled", Boolean.class)); + if (enableMetrics) { + options + .getLogger() + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property is no longer supported. Manual " + + "Sentry.metrics() calls no longer require it."); + } else { + options + .getLogger() + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property no longer disables manual " + + "Sentry.metrics() calls."); + } + } + } + @Configuration(proxyBeanMethods = false) @ConditionalOnClass(MDC.class) @Open diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt index 1ce6c8071e..df99445940 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt @@ -250,6 +250,52 @@ class SentryAutoConfigurationTest { } } + @Test + fun `legacy metrics property emits no warning when absent`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } + } + + @Test + fun `legacy metrics property true emits migration warning`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=true") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { + verify(logger) + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property is no longer supported. Manual " + + "Sentry.metrics() calls no longer require it.", + *emptyArray(), + ) + } + } + + @Test + fun `legacy metrics property false emits migration warning`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=false") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { + verify(logger) + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property no longer disables manual " + + "Sentry.metrics() calls.", + *emptyArray(), + ) + } + } + @Test fun `properties are applied to SentryOptions`() { contextRunner diff --git a/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java b/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java index 0d63b68629..37872b02fe 100644 --- a/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java +++ b/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java @@ -185,6 +185,7 @@ static class OpenTelemetryNoAgentConfiguration {} options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it)); Sentry.init(options); warnForLegacyLogsConfiguration(environment, options); + warnForLegacyMetricsConfiguration(environment, options); return ScopesAdapter.getInstance(); } @@ -213,6 +214,29 @@ private void warnForLegacyLogsConfiguration( } } + private void warnForLegacyMetricsConfiguration( + final @NotNull Environment environment, final @NotNull SentryOptions options) { + if (environment.containsProperty("sentry.metrics.enabled")) { + final boolean enableMetrics = + Boolean.TRUE.equals(environment.getProperty("sentry.metrics.enabled", Boolean.class)); + if (enableMetrics) { + options + .getLogger() + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property is no longer supported. Manual " + + "Sentry.metrics() calls no longer require it."); + } else { + options + .getLogger() + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property no longer disables manual " + + "Sentry.metrics() calls."); + } + } + } + @Configuration(proxyBeanMethods = false) @ConditionalOnClass(MDC.class) @Open diff --git a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index b0ee03d657..2315a616d2 100644 --- a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -248,6 +248,52 @@ class SentryAutoConfigurationTest { } } + @Test + fun `legacy metrics property emits no warning when absent`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } + } + + @Test + fun `legacy metrics property true emits migration warning`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=true") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { + verify(logger) + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property is no longer supported. Manual " + + "Sentry.metrics() calls no longer require it.", + *emptyArray(), + ) + } + } + + @Test + fun `legacy metrics property false emits migration warning`() { + val logger = mock() + dsnEnabledRunner + .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=false") + .withBean(ILogger::class.java, { logger }) + .withUserConfiguration(LoggerConfiguration::class.java) + .run { + verify(logger) + .log( + SentryLevel.WARNING, + "The 'sentry.metrics.enabled' property no longer disables manual " + + "Sentry.metrics() calls.", + *emptyArray(), + ) + } + } + @Test fun `properties are applied to SentryOptions`() { contextRunner