Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That string is duplicated all over the place, should we create a constant for it?

+ "Sentry.metrics() calls no longer require it.");
} else {
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.metrics.enabled' property no longer disables manual "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That string is duplicated all over the place, should we create a constant for it?

+ "Sentry.metrics() calls.");
}
}
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(MDC.class)
@Open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,52 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `legacy metrics property emits no warning when absent`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
}

@Test
fun `legacy metrics property true emits migration warning`() {
val logger = mock<ILogger>()
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<ILogger>()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,52 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `legacy metrics property emits no warning when absent`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
}

@Test
fun `legacy metrics property true emits migration warning`() {
val logger = mock<ILogger>()
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<ILogger>()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,52 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `legacy metrics property emits no warning when absent`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
}

@Test
fun `legacy metrics property true emits migration warning`() {
val logger = mock<ILogger>()
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<ILogger>()
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
Expand Down
Loading