Skip to content

Commit 0a41b97

Browse files
adinauerclaude
andcommitted
feat(core): Remove Metrics enable flag
Capture manual Metrics without an aggregate option and always create the configured batch processor. Keep legacy external and Android keys only for subsequent migration warnings. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fb91733 commit 0a41b97

10 files changed

Lines changed: 28 additions & 97 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Remove the aggregate Sentry Metrics enable flag; `Sentry.metrics()` calls now capture Metrics by default ([#5953](https://github.com/getsentry/sentry-java/pull/5953))
78
- Remove the aggregate Sentry Logs enable flag; manual `Sentry.logger()` calls now capture Logs by default ([#5947](https://github.com/getsentry/sentry-java/pull/5947))
89
- Add an explicit Logs opt-in to Spring Boot logging auto-configuration ([#5946](https://github.com/getsentry/sentry-java/pull/5946))
910
- Add an explicit Logs opt-in to the Android Logcat integration ([#5945](https://github.com/getsentry/sentry-java/pull/5945))

‎sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,6 @@ static void applyMetadata(
729729
options.setEnableLogcatLogs(
730730
readBool(metadata, logger, ENABLE_LOGCAT_LOGS, options.isEnableLogcatLogs()));
731731

732-
options
733-
.getMetrics()
734-
.setEnabled(
735-
readBool(metadata, logger, ENABLE_METRICS, options.getMetrics().isEnabled()));
736-
737732
final @NotNull SentryFeedbackOptions feedbackOptions = options.getFeedbackOptions();
738733
feedbackOptions.setNameRequired(
739734
readBool(metadata, logger, FEEDBACK_NAME_REQUIRED, feedbackOptions.isNameRequired()));

‎sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt‎

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import io.sentry.ProfileLifecycle
1111
import io.sentry.SentryLevel
1212
import io.sentry.SentryReplayOptions
1313
import io.sentry.TransactionOptions
14+
import io.sentry.test.createSentryClientMock
15+
import io.sentry.test.createTestScopes
1416
import kotlin.test.BeforeTest
1517
import kotlin.test.Test
1618
import kotlin.test.assertEquals
@@ -20,6 +22,7 @@ import kotlin.test.assertNull
2022
import kotlin.test.assertTrue
2123
import org.junit.runner.RunWith
2224
import org.mockito.kotlin.any
25+
import org.mockito.kotlin.anyOrNull
2326
import org.mockito.kotlin.eq
2427
import org.mockito.kotlin.mock
2528
import org.mockito.kotlin.never
@@ -2051,41 +2054,17 @@ class ManifestMetadataReaderTest {
20512054
}
20522055

20532056
@Test
2054-
fun `applyMetadata reads metrics enabled and keep default value if not found`() {
2055-
// Arrange
2056-
val context = fixture.getContext()
2057-
2058-
// Act
2059-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2060-
2061-
// Assert
2062-
assertTrue(fixture.options.metrics.isEnabled)
2063-
}
2064-
2065-
@Test
2066-
fun `applyMetadata reads metrics enabled to options`() {
2067-
// Arrange
2057+
fun `legacy metrics metadata does not disable capture`() {
20682058
val bundle = bundleOf(ManifestMetadataReader.ENABLE_METRICS to false)
20692059
val context = fixture.getContext(metaData = bundle)
2060+
val client = createSentryClientMock()
20702061

2071-
// Act
20722062
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2063+
fixture.options.dsn = "https://key@sentry.io/proj"
2064+
val scopes = createTestScopes(fixture.options).also { it.bindClient(client) }
2065+
scopes.metrics().count("metric name")
20732066

2074-
// Assert
2075-
assertFalse(fixture.options.metrics.isEnabled)
2076-
}
2077-
2078-
@Test
2079-
fun `applyMetadata reads metrics enabled to options when set to true`() {
2080-
// Arrange
2081-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_METRICS to true)
2082-
val context = fixture.getContext(metaData = bundle)
2083-
2084-
// Act
2085-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2086-
2087-
// Assert
2088-
assertTrue(fixture.options.metrics.isEnabled)
2067+
verify(client).captureMetric(any(), anyOrNull(), anyOrNull())
20892068
}
20902069

20912070
@Test

‎sentry/api/sentry.api‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,9 +3976,7 @@ public final class io/sentry/SentryOptions$Metrics {
39763976
public fun <init> ()V
39773977
public fun getBeforeSend ()Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;
39783978
public fun getMetricsBatchProcessorFactory ()Lio/sentry/metrics/IMetricsBatchProcessorFactory;
3979-
public fun isEnabled ()Z
39803979
public fun setBeforeSend (Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;)V
3981-
public fun setEnabled (Z)V
39823980
public fun setMetricsBatchProcessorFactory (Lio/sentry/metrics/IMetricsBatchProcessorFactory;)V
39833981
}
39843982

‎sentry/src/main/java/io/sentry/SentryClient.java‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import io.sentry.hints.TransactionEnd;
1111
import io.sentry.logger.ILoggerBatchProcessor;
1212
import io.sentry.metrics.IMetricsBatchProcessor;
13-
import io.sentry.metrics.NoOpMetricsBatchProcessor;
1413
import io.sentry.protocol.Contexts;
1514
import io.sentry.protocol.DebugMeta;
1615
import io.sentry.protocol.FeatureFlags;
@@ -62,12 +61,8 @@ public SentryClient(final @NotNull SentryOptions options) {
6261
final RequestDetailsResolver requestDetailsResolver = new RequestDetailsResolver(options);
6362
transport = transportFactory.create(options, requestDetailsResolver.resolve());
6463
loggerBatchProcessor = options.getLogs().getLoggerBatchProcessorFactory().create(options, this);
65-
if (options.getMetrics().isEnabled()) {
66-
metricsBatchProcessor =
67-
options.getMetrics().getMetricsBatchProcessorFactory().create(options, this);
68-
} else {
69-
metricsBatchProcessor = NoOpMetricsBatchProcessor.getInstance();
70-
}
64+
metricsBatchProcessor =
65+
options.getMetrics().getMetricsBatchProcessorFactory().create(options, this);
7166
}
7267

7368
private boolean shouldApplyScopeData(

‎sentry/src/main/java/io/sentry/SentryOptions.java‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,10 +3748,6 @@ public void merge(final @NotNull ExternalOptions options) {
37483748
}
37493749
}
37503750

3751-
if (options.isEnableMetrics() != null) {
3752-
getMetrics().setEnabled(options.isEnableMetrics());
3753-
}
3754-
37553751
if (options.getProfileSessionSampleRate() != null) {
37563752
setProfileSessionSampleRate(options.getProfileSessionSampleRate());
37573753
}
@@ -4023,9 +4019,6 @@ public interface BeforeSendLogCallback {
40234019

40244020
public static final class Metrics {
40254021

4026-
/** Whether Sentry Metrics feature is enabled and metrics are sent to Sentry. */
4027-
private boolean enable = true;
4028-
40294022
/**
40304023
* This function is called with a metric key and tags and can return false to skip sending the
40314024
* metric
@@ -4035,24 +4028,6 @@ public static final class Metrics {
40354028
private @NotNull IMetricsBatchProcessorFactory metricsBatchProcessorFactory =
40364029
new DefaultMetricsBatchProcessorFactory();
40374030

4038-
/**
4039-
* Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
4040-
*
4041-
* @return true if Sentry Metrics should be enabled
4042-
*/
4043-
public boolean isEnabled() {
4044-
return enable;
4045-
}
4046-
4047-
/**
4048-
* Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
4049-
*
4050-
* @param enableMetrics true if Sentry Metrics should be enabled
4051-
*/
4052-
public void setEnabled(final boolean enableMetrics) {
4053-
this.enable = enableMetrics;
4054-
}
4055-
40564031
/**
40574032
* Returns the BeforeSendMetric callback
40584033
*

‎sentry/src/main/java/io/sentry/metrics/MetricsApi.java‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ private void captureMetrics(
118118
return;
119119
}
120120

121-
if (!options.getMetrics().isEnabled()) {
122-
options
123-
.getLogger()
124-
.log(
125-
SentryLevel.WARNING,
126-
"Sentry Metrics is disabled and this 'metrics' call is a no-op.");
127-
return;
128-
}
129-
130121
if (name == null) {
131122
return;
132123
}

‎sentry/src/test/java/io/sentry/ScopesTest.kt‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,11 +3290,15 @@ class ScopesTest {
32903290
}
32913291

32923292
@Test
3293-
fun `when metrics is not enabled, do nothing`() {
3294-
val (sut, mockClient) = getEnabledScopes { it.metrics.isEnabled = false }
3293+
fun `legacy external metrics configuration does not disable capture`() {
3294+
val (sut, mockClient) =
3295+
getEnabledScopes { options ->
3296+
options.merge(ExternalOptions().also { it.isEnableMetrics = false })
3297+
}
32953298

32963299
sut.metrics().count("metric name")
3297-
verify(mockClient, never()).captureMetric(any(), anyOrNull(), anyOrNull())
3300+
3301+
verify(mockClient).captureMetric(any(), anyOrNull(), anyOrNull())
32983302
}
32993303

33003304
@Test
@@ -4226,7 +4230,7 @@ class ScopesTest {
42264230

42274231
@Test
42284232
fun `metric event has spanId from active span`() {
4229-
val (sut, mockClient) = getEnabledScopes { it.metrics.isEnabled = true }
4233+
val (sut, mockClient) = getEnabledScopes()
42304234

42314235
val transaction =
42324236
sut.startTransaction(
@@ -4253,7 +4257,7 @@ class ScopesTest {
42534257

42544258
@Test
42554259
fun `metric event has spanId from propagation context when no active span`() {
4256-
val (sut, mockClient) = getEnabledScopes { it.metrics.isEnabled = true }
4260+
val (sut, mockClient) = getEnabledScopes()
42574261

42584262
var propagationContext: PropagationContext? = null
42594263
sut.configureScope { propagationContext = it.propagationContext }

‎sentry/src/test/java/io/sentry/SentryClientTest.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ class SentryClientTest {
153153
assertTrue(sut.isEnabled)
154154
}
155155

156+
@Test
157+
fun `when client is created, metrics batch processor is created`() {
158+
val sut = fixture.getSut()
159+
160+
verify(fixture.metricsBatchProcessorFactory).create(fixture.sentryOptions, sut)
161+
}
162+
156163
@Test
157164
fun `when dsn is an invalid string, client throws`() {
158165
fixture.sentryOptions.dsn = "invalid-dsn"

‎sentry/src/test/java/io/sentry/SentryOptionsTest.kt‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ class SentryOptionsTest {
485485
assertTrue(options.isEnableSpotlight)
486486
assertEquals("http://local.sentry.io:1234", options.spotlightConnectionUrl)
487487
assertTrue(options.isGlobalHubMode!!)
488-
assertFalse(options.metrics.isEnabled)
489488
assertEquals(0.8, options.profileSessionSampleRate)
490489
assertEquals("/profiling-traces${File.separator}${hash}", options.profilingTracesDirPath)
491490
assertEquals(ProfileLifecycle.TRACE, options.profileLifecycle)
@@ -499,14 +498,6 @@ class SentryOptionsTest {
499498
assertTrue(options.isEnableUncaughtExceptionHandler)
500499
}
501500

502-
@Test
503-
fun `merging options when enableMetrics is not set preserves the default value`() {
504-
val externalOptions = ExternalOptions()
505-
val options = SentryOptions()
506-
options.merge(externalOptions)
507-
assertTrue(options.metrics.isEnabled)
508-
}
509-
510501
@Test
511502
fun `merging options does not warn when legacy logs configuration is absent`() {
512503
val logger = mock<ILogger>()
@@ -804,11 +795,6 @@ class SentryOptionsTest {
804795
assertFalse(SentryOptions().isEnableQueueTracing)
805796
}
806797

807-
@Test
808-
fun `when options are initialized, metrics is enabled by default`() {
809-
assertTrue(SentryOptions().metrics.isEnabled)
810-
}
811-
812798
@Test
813799
fun `when options are initialized, enableSpotlight is set to false by default`() {
814800
assertFalse(SentryOptions().isEnableSpotlight)

0 commit comments

Comments
 (0)