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
13 changes: 13 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3748,6 +3748,19 @@ public void merge(final @NotNull ExternalOptions options) {
}
}

if (options.isEnableMetrics() != null) {
if (options.isEnableMetrics()) {
logger.log(
SentryLevel.WARNING,
"The 'metrics.enabled' option is no longer supported. Manual Sentry.metrics() calls no "
+ "longer require it.");
} else {
logger.log(
SentryLevel.WARNING,
"The 'metrics.enabled' option no longer disables manual Sentry.metrics() calls.");
}
}

if (options.getProfileSessionSampleRate() != null) {
setProfileSessionSampleRate(options.getProfileSessionSampleRate());
}
Expand Down
66 changes: 66 additions & 0 deletions sentry/src/test/java/io/sentry/SentryOptionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.sentry
import io.sentry.SentryOptions.RequestSize
import io.sentry.logger.ILoggerBatchProcessorFactory
import io.sentry.logger.LoggerApi
import io.sentry.metrics.MetricsApi
import io.sentry.test.createSentryClientMock
import io.sentry.test.createTestScopes
import io.sentry.util.StringUtils
Expand Down Expand Up @@ -564,6 +565,71 @@ class SentryOptionsTest {
verify(client).captureLog(any(), anyOrNull())
}

@Test
fun `merging options does not warn when legacy metrics configuration is absent`() {
val logger = mock<ILogger>()
val options =
SentryOptions().also {
it.isDebug = true
it.setLogger(logger)
}

options.merge(ExternalOptions())

verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>())
}

@Test
fun `merging options warns when legacy metrics configuration is true`() {
val logger = mock<ILogger>()
val options =
SentryOptions().also {
it.isDebug = true
it.setLogger(logger)
}

options.merge(ExternalOptions().apply { isEnableMetrics = true })

verify(logger)
.log(
SentryLevel.WARNING,
"The 'metrics.enabled' option is no longer supported. Manual Sentry.metrics() calls no " +
"longer require it.",
*emptyArray(),
)
assertLegacyMetricsConfigurationDoesNotDisableCapture(options)
}

@Test
fun `merging options warns when legacy metrics configuration is false`() {
val logger = mock<ILogger>()
val options =
SentryOptions().also {
it.isDebug = true
it.setLogger(logger)
}

options.merge(ExternalOptions().apply { isEnableMetrics = false })

verify(logger)
.log(
SentryLevel.WARNING,
"The 'metrics.enabled' option no longer disables manual Sentry.metrics() calls.",
*emptyArray(),
)
assertLegacyMetricsConfigurationDoesNotDisableCapture(options)
}

private fun assertLegacyMetricsConfigurationDoesNotDisableCapture(options: SentryOptions) {
options.dsn = "https://key@sentry.io/proj"
val client = createSentryClientMock()
val scopes = createTestScopes(options).apply { bindClient(client) }

MetricsApi(scopes).count("test metric")

verify(client).captureMetric(any(), anyOrNull(), anyOrNull())
}

@Test
fun `merging options merges and overwrites existing tag values`() {
val externalOptions = ExternalOptions()
Expand Down
Loading