Skip to content

Commit 98074e6

Browse files
authored
Merge pull request #5953 from getsentry/feat/remove-metrics-enable-flag
feat(core): [Logs and Metrics Enable Flags 9] Remove Metrics enable flag
2 parents 79e962f + a1e848a commit 98074e6

13 files changed

Lines changed: 12 additions & 184 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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ final class ManifestMetadataReader {
196196

197197
static final String ENABLE_LOGCAT_LOGS = "io.sentry.logcat.logs.enabled";
198198

199-
static final String ENABLE_METRICS = "io.sentry.metrics.enabled";
200-
201199
static final String ENABLE_AUTO_TRACE_ID_GENERATION =
202200
"io.sentry.traces.enable-auto-id-generation";
203201

@@ -758,11 +756,6 @@ static void applyMetadata(
758756
options.setEnableLogcatLogs(
759757
readBool(metadata, logger, ENABLE_LOGCAT_LOGS, options.isEnableLogcatLogs()));
760758

761-
options
762-
.getMetrics()
763-
.setEnabled(
764-
readBool(metadata, logger, ENABLE_METRICS, options.getMetrics().isEnabled()));
765-
766759
final @NotNull SentryFeedbackOptions feedbackOptions = options.getFeedbackOptions();
767760
feedbackOptions.setNameRequired(
768761
readBool(metadata, logger, FEEDBACK_NAME_REQUIRED, feedbackOptions.isNameRequired()));

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,44 +2224,6 @@ class ManifestMetadataReaderTest {
22242224
assertThat(fixture.options.isEnableLogcatLogs).isFalse()
22252225
}
22262226

2227-
@Test
2228-
fun `applyMetadata reads metrics enabled and keep default value if not found`() {
2229-
// Arrange
2230-
val context = fixture.getContext()
2231-
2232-
// Act
2233-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2234-
2235-
// Assert
2236-
assertTrue(fixture.options.metrics.isEnabled)
2237-
}
2238-
2239-
@Test
2240-
fun `applyMetadata reads metrics enabled to options`() {
2241-
// Arrange
2242-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_METRICS to false)
2243-
val context = fixture.getContext(metaData = bundle)
2244-
2245-
// Act
2246-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2247-
2248-
// Assert
2249-
assertFalse(fixture.options.metrics.isEnabled)
2250-
}
2251-
2252-
@Test
2253-
fun `applyMetadata reads metrics enabled to options when set to true`() {
2254-
// Arrange
2255-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_METRICS to true)
2256-
val context = fixture.getContext(metaData = bundle)
2257-
2258-
// Act
2259-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2260-
2261-
// Assert
2262-
assertTrue(fixture.options.metrics.isEnabled)
2263-
}
2264-
22652227
@Test
22662228
fun `applyMetadata reads feedback name required and keep default value if not found`() {
22672229
// Arrange

‎sentry/api/sentry.api‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ public final class io/sentry/ExternalOptions {
590590
public fun isEnableBackpressureHandling ()Ljava/lang/Boolean;
591591
public fun isEnableCacheTracing ()Ljava/lang/Boolean;
592592
public fun isEnableDatabaseTransactionTracing ()Ljava/lang/Boolean;
593-
public fun isEnableMetrics ()Ljava/lang/Boolean;
594593
public fun isEnablePrettySerializationOutput ()Ljava/lang/Boolean;
595594
public fun isEnableQueueTracing ()Ljava/lang/Boolean;
596595
public fun isEnableSpotlight ()Ljava/lang/Boolean;
@@ -610,7 +609,6 @@ public final class io/sentry/ExternalOptions {
610609
public fun setEnableCacheTracing (Ljava/lang/Boolean;)V
611610
public fun setEnableDatabaseTransactionTracing (Ljava/lang/Boolean;)V
612611
public fun setEnableDeduplication (Ljava/lang/Boolean;)V
613-
public fun setEnableMetrics (Ljava/lang/Boolean;)V
614612
public fun setEnablePrettySerializationOutput (Ljava/lang/Boolean;)V
615613
public fun setEnableQueueTracing (Ljava/lang/Boolean;)V
616614
public fun setEnableSpotlight (Ljava/lang/Boolean;)V
@@ -4110,9 +4108,7 @@ public final class io/sentry/SentryOptions$Metrics {
41104108
public fun <init> ()V
41114109
public fun getBeforeSend ()Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;
41124110
public fun getMetricsBatchProcessorFactory ()Lio/sentry/metrics/IMetricsBatchProcessorFactory;
4113-
public fun isEnabled ()Z
41144111
public fun setBeforeSend (Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;)V
4115-
public fun setEnabled (Z)V
41164112
public fun setMetricsBatchProcessorFactory (Lio/sentry/metrics/IMetricsBatchProcessorFactory;)V
41174113
}
41184114

@@ -5682,13 +5678,6 @@ public final class io/sentry/metrics/NoOpMetricsApi : io/sentry/metrics/IMetrics
56825678
public static fun getInstance ()Lio/sentry/metrics/NoOpMetricsApi;
56835679
}
56845680

5685-
public final class io/sentry/metrics/NoOpMetricsBatchProcessor : io/sentry/metrics/IMetricsBatchProcessor {
5686-
public fun add (Lio/sentry/SentryMetricsEvent;)V
5687-
public fun close (Z)V
5688-
public fun flush (J)V
5689-
public static fun getInstance ()Lio/sentry/metrics/NoOpMetricsBatchProcessor;
5690-
}
5691-
56925681
public final class io/sentry/metrics/SentryMetricsParameters {
56935682
public fun <init> ()V
56945683
public static fun create (Lio/sentry/SentryAttributes;)Lio/sentry/metrics/SentryMetricsParameters;

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public final class ExternalOptions {
4646
private @Nullable Boolean enabled;
4747
private @Nullable Boolean enablePrettySerializationOutput;
4848
private @Nullable Boolean enableSpotlight;
49-
private @Nullable Boolean enableMetrics;
5049
private @Nullable String spotlightConnectionUrl;
5150

5251
private @Nullable List<String> ignoredCheckIns;
@@ -177,8 +176,6 @@ public final class ExternalOptions {
177176
options.setCaptureOpenTelemetryEvents(
178177
propertiesProvider.getBooleanProperty("capture-open-telemetry-events"));
179178

180-
options.setEnableMetrics(propertiesProvider.getBooleanProperty("metrics.enabled"));
181-
182179
for (final String ignoredExceptionType :
183180
propertiesProvider.getList("ignored-exceptions-for-type")) {
184181
try {
@@ -714,14 +711,6 @@ public void setCaptureOpenTelemetryEvents(final @Nullable Boolean captureOpenTel
714711
return captureOpenTelemetryEvents;
715712
}
716713

717-
public void setEnableMetrics(final @Nullable Boolean enableMetrics) {
718-
this.enableMetrics = enableMetrics;
719-
}
720-
721-
public @Nullable Boolean isEnableMetrics() {
722-
return enableMetrics;
723-
}
724-
725714
public @Nullable Double getProfileSessionSampleRate() {
726715
return profileSessionSampleRate;
727716
}

‎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;
@@ -60,12 +59,8 @@ public SentryClient(final @NotNull SentryOptions options) {
6059
final RequestDetailsResolver requestDetailsResolver = new RequestDetailsResolver(options);
6160
transport = transportFactory.create(options, requestDetailsResolver.resolve());
6261
loggerBatchProcessor = options.getLogs().getLoggerBatchProcessorFactory().create(options, this);
63-
if (options.getMetrics().isEnabled()) {
64-
metricsBatchProcessor =
65-
options.getMetrics().getMetricsBatchProcessorFactory().create(options, this);
66-
} else {
67-
metricsBatchProcessor = NoOpMetricsBatchProcessor.getInstance();
68-
}
62+
metricsBatchProcessor =
63+
options.getMetrics().getMetricsBatchProcessorFactory().create(options, this);
6964
}
7065

7166
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
@@ -3834,10 +3834,6 @@ public void merge(final @NotNull ExternalOptions options) {
38343834
}
38353835
}
38363836

3837-
if (options.isEnableMetrics() != null) {
3838-
getMetrics().setEnabled(options.isEnableMetrics());
3839-
}
3840-
38413837
if (options.getProfileSessionSampleRate() != null) {
38423838
setProfileSessionSampleRate(options.getProfileSessionSampleRate());
38433839
}
@@ -4146,9 +4142,6 @@ public interface BeforeSendLogCallback {
41464142

41474143
public static final class Metrics {
41484144

4149-
/** Whether Sentry Metrics feature is enabled and metrics are sent to Sentry. */
4150-
private boolean enable = true;
4151-
41524145
/**
41534146
* This function is called with a metric key and tags and can return false to skip sending the
41544147
* metric
@@ -4158,24 +4151,6 @@ public static final class Metrics {
41584151
private @NotNull IMetricsBatchProcessorFactory metricsBatchProcessorFactory =
41594152
new DefaultMetricsBatchProcessorFactory();
41604153

4161-
/**
4162-
* Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
4163-
*
4164-
* @return true if Sentry Metrics should be enabled
4165-
*/
4166-
public boolean isEnabled() {
4167-
return enable;
4168-
}
4169-
4170-
/**
4171-
* Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
4172-
*
4173-
* @param enableMetrics true if Sentry Metrics should be enabled
4174-
*/
4175-
public void setEnabled(final boolean enableMetrics) {
4176-
this.enable = enableMetrics;
4177-
}
4178-
41794154
/**
41804155
* Returns the BeforeSendMetric callback
41814156
*

‎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/main/java/io/sentry/metrics/NoOpMetricsBatchProcessor.java‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -530,25 +530,6 @@ class ExternalOptionsTest {
530530
}
531531
}
532532

533-
@Test
534-
fun `creates options with enableMetrics set to true`() {
535-
withPropertiesFile("metrics.enabled=true") { options ->
536-
assertTrue(options.isEnableMetrics == true)
537-
}
538-
}
539-
540-
@Test
541-
fun `creates options with enableMetrics set to false`() {
542-
withPropertiesFile("metrics.enabled=false") { options ->
543-
assertTrue(options.isEnableMetrics == false)
544-
}
545-
}
546-
547-
@Test
548-
fun `creates options with enableMetrics set to null when not set`() {
549-
withPropertiesFile { assertNull(it.isEnableMetrics) }
550-
}
551-
552533
@Test
553534
fun `creates options with profileSessionSampleRate set to 0_8`() {
554535
withPropertiesFile("profile-session-sample-rate=0.8") { options ->

0 commit comments

Comments
 (0)