Skip to content

Commit 34f7d0f

Browse files
authored
Merge pull request #5970 from getsentry/ref/logs-enabled-naming
ref(logging): [Logs and Metrics Enable Flags 14] Rename Logs opt-ins
2 parents 7cd057f + ee3eeb9 commit 34f7d0f

65 files changed

Lines changed: 314 additions & 387 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.cursor/rules/options.mdc‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Allows setting options via `AndroidManifest.xml` `<meta-data>` tags.
7676
- Add a `static final String` constant for the key
7777
- Read it in `applyMetadata()` using `readBool(metadata, logger, CONSTANT, defaultValue)`
7878
- Apply automatic-source options directly, for example
79-
`options.setEnableLogcatLogs(...)` for `io.sentry.logcat.logs.enabled`
79+
`options.setLogcatLogCaptureEnabled(...)` for `io.sentry.logcat.log-capture.enabled`
8080
- Do not add or restore `io.sentry.logs.enabled` or `io.sentry.metrics.enabled`; those aggregate
8181
keys are obsolete.
8282

@@ -89,8 +89,8 @@ Allows setting options via `AndroidManifest.xml` `<meta-data>` tags.
8989

9090
`SentryProperties` extends `SentryOptions`, so bindable namespaced behavior options are available
9191
through the `SentryOptions` class hierarchy. Spring-owned integration controls belong to a Spring
92-
namespace instead. For example, `SentryProperties.Logging.enableLogs` binds to
93-
`sentry.logging.enable-logs` and controls Logs forwarding from the auto-configured Logback
92+
namespace instead. For example, `SentryProperties.Logging.logsEnabled` binds to
93+
`sentry.logging.logs-enabled` and controls Logs forwarding from the auto-configured Logback
9494
appender. `sentry.logging.enabled` separately controls whether that appender is installed.
9595

9696
Do not add or restore `sentry.logs.enabled` or `sentry.metrics.enabled`; those aggregate properties
@@ -110,12 +110,12 @@ They capture whenever their scopes are enabled, then apply signal behavior such
110110

111111
Automatic integrations must check their source-local opt-in without affecting their existing event
112112
or breadcrumb paths. Current Logs controls are:
113-
- Logback: appender `enableLogs`
114-
- Log4j2: appender `enableLogs`
115-
- JUL: handler `enableLogs`
116-
- Spring Boot Logback: `sentry.logging.enable-logs`
117-
- Timber: `enableTimberLogs` / `io.sentry.timber.logs.enabled`
118-
- Logcat: `enableLogcatLogs` / `io.sentry.logcat.logs.enabled`
113+
- Logback: appender `logsEnabled`
114+
- Log4j2: appender `logsEnabled`
115+
- JUL: handler `logsEnabled`
116+
- Spring Boot Logback: `sentry.logging.logs-enabled`
117+
- Timber: `timberLogCaptureEnabled` / `io.sentry.timber.log-capture.enabled`
118+
- Logcat: `logcatLogCaptureEnabled` / `io.sentry.logcat.log-capture.enabled`
119119

120120
All source-local options default to `false` and gate only Sentry Logs forwarding.
121121

‎CHANGELOG.md‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
## Unreleased
44

5+
### Breaking Changes
6+
7+
- Remove the deprecated Log4j2 `SentryAppender` constructor without `minimumLevel`, and add a
8+
`logsEnabled` argument to the remaining constructor and `createAppender` factory. Pass `true` to
9+
opt in to Sentry Logs capture or `false` to keep it disabled.
10+
([#5941](https://github.com/getsentry/sentry-java/pull/5941))
11+
- Require a `logsEnabled` argument when manually constructing `SentryTimberIntegration` or
12+
`SentryTimberTree`. Replace `SentryTimberIntegration()` with
13+
`SentryTimberIntegration(logsEnabled = false)` in Kotlin or `new SentryTimberIntegration(false)`
14+
in Java to keep Sentry Logs disabled. ([#5943](https://github.com/getsentry/sentry-java/pull/5943))
15+
- Remove the obsolete aggregate Sentry Metrics options `metrics.enabled` and
16+
`options.getMetrics().setEnabled(...)`. Direct `Sentry.metrics()` calls continue to capture
17+
Metrics whenever the SDK is enabled. ([#5953](https://github.com/getsentry/sentry-java/pull/5953))
18+
- Remove the obsolete aggregate Sentry Logs options `logs.enabled` and
19+
`options.getLogs().setEnabled(...)`. ([#5947](https://github.com/getsentry/sentry-java/pull/5947))
20+
Direct `Sentry.logger()` calls continue to capture Logs whenever the SDK is enabled. Sentry Logs
21+
capture is disabled by default for every automatic logging integration. Set the applicable
22+
integration-specific option to `true` to opt in:
23+
- Logback appender: `logsEnabled`
24+
- Log4j2 appender: `logsEnabled`
25+
- JUL handler: `io.sentry.jul.SentryHandler.logsEnabled`
26+
- Spring Boot logging auto-configuration: `sentry.logging.logs-enabled`
27+
- Auto-installed Timber integration: `timberLogCaptureEnabled` or
28+
`io.sentry.timber.log-capture.enabled` manifest metadata
29+
- Manually installed Timber integration: `logsEnabled` constructor argument
30+
- Logcat: `logcatLogCaptureEnabled` or `io.sentry.logcat.log-capture.enabled` manifest metadata
31+
532
### Features
633

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))
8-
- 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))
934
- Add an explicit Logs opt-in to Spring Boot logging auto-configuration ([#5946](https://github.com/getsentry/sentry-java/pull/5946))
1035
- Add an explicit Logs opt-in to the Android Logcat integration ([#5945](https://github.com/getsentry/sentry-java/pull/5945))
1136
- Add an explicit Logs opt-in to the Android Timber integration ([#5943](https://github.com/getsentry/sentry-java/pull/5943))

‎sentry-android-core/api/sentry-android-core.api‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,14 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
429429
public fun getBeforeViewHierarchyCaptureCallback ()Lio/sentry/android/core/SentryAndroidOptions$BeforeCaptureCallback;
430430
public fun getDebugImagesLoader ()Lio/sentry/android/core/IDebugImagesLoader;
431431
public fun getFrameMetricsCollector ()Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;
432+
public fun getLogcatLogCaptureEnabled ()Z
432433
public fun getMonotonicTicker ()Lio/sentry/time/MonotonicTicker;
433434
public fun getNativeSdkName ()Ljava/lang/String;
434435
public fun getNdkAppHangTimeoutIntervalMillis ()J
435436
public fun getNdkHandlerStrategy ()I
436437
public fun getScreenshot ()Lio/sentry/android/core/SentryScreenshotOptions;
437438
public fun getStartupCrashDurationThresholdMillis ()J
439+
public fun getTimberLogCaptureEnabled ()Z
438440
public fun getTombstoneMergeTimeThresholdMillis ()J
439441
public fun isAnrEnabled ()Z
440442
public fun isAnrProfilingEnabled ()Z
@@ -453,7 +455,6 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
453455
public fun isEnableAutoActivityLifecycleTracing ()Z
454456
public fun isEnableAutoTraceIdGeneration ()Z
455457
public fun isEnableFramesTracking ()Z
456-
public fun isEnableLogcatLogs ()Z
457458
public fun isEnableNdk ()Z
458459
public fun isEnableNdkAppHangTracking ()Z
459460
public fun isEnableNetworkEventBreadcrumbs ()Z
@@ -463,7 +464,6 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
463464
public fun isEnableStandaloneAppStartTracing ()Z
464465
public fun isEnableSystemEventBreadcrumbs ()Z
465466
public fun isEnableSystemEventBreadcrumbsExtras ()Z
466-
public fun isEnableTimberLogs ()Z
467467
public fun isMemoryLimiterEnabled ()Z
468468
public fun isReportHistoricalAnrs ()Z
469469
public fun isReportHistoricalMemoryLimiterExits ()Z
@@ -490,7 +490,6 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
490490
public fun setEnableAutoActivityLifecycleTracing (Z)V
491491
public fun setEnableAutoTraceIdGeneration (Z)V
492492
public fun setEnableFramesTracking (Z)V
493-
public fun setEnableLogcatLogs (Z)V
494493
public fun setEnableNdk (Z)V
495494
public fun setEnableNdkAppHangTracking (Z)V
496495
public fun setEnableNetworkEventBreadcrumbs (Z)V
@@ -500,15 +499,16 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
500499
public fun setEnableStandaloneAppStartTracing (Z)V
501500
public fun setEnableSystemEventBreadcrumbs (Z)V
502501
public fun setEnableSystemEventBreadcrumbsExtras (Z)V
503-
public fun setEnableTimberLogs (Z)V
504502
public fun setFrameMetricsCollector (Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V
503+
public fun setLogcatLogCaptureEnabled (Z)V
505504
public fun setMemoryLimiterEnabled (Z)V
506505
public fun setNativeHandlerStrategy (Lio/sentry/android/core/NdkHandlerStrategy;)V
507506
public fun setNativeSdkName (Ljava/lang/String;)V
508507
public fun setNdkAppHangTimeoutIntervalMillis (J)V
509508
public fun setReportHistoricalAnrs (Z)V
510509
public fun setReportHistoricalMemoryLimiterExits (Z)V
511510
public fun setReportHistoricalTombstones (Z)V
511+
public fun setTimberLogCaptureEnabled (Z)V
512512
public fun setTombstoneEnabled (Z)V
513513
public fun setTombstoneMergeTimeThresholdMillis (J)V
514514
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ static void installDefaultIntegrations(
479479
}
480480

481481
if (isTimberAvailable) {
482-
options.addIntegration(new SentryTimberIntegration(() -> options.isEnableTimberLogs()));
482+
options.addIntegration(
483+
new SentryTimberIntegration(() -> options.getTimberLogCaptureEnabled()));
483484
}
484485
options.addIntegration(new AppComponentsBreadcrumbsIntegration(context));
485486
options.addIntegration(new SystemEventsBreadcrumbsIntegration(context));

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ final class ManifestMetadataReader {
192192

193193
static final String IN_APP_EXCLUDES = "io.sentry.in-app-excludes";
194194

195-
static final String ENABLE_TIMBER_LOGS = "io.sentry.timber.logs.enabled";
195+
static final String TIMBER_LOG_CAPTURE_ENABLED = "io.sentry.timber.log-capture.enabled";
196196

197-
static final String ENABLE_LOGCAT_LOGS = "io.sentry.logcat.logs.enabled";
197+
static final String LOGCAT_LOG_CAPTURE_ENABLED = "io.sentry.logcat.log-capture.enabled";
198198

199199
static final String ENABLE_AUTO_TRACE_ID_GENERATION =
200200
"io.sentry.traces.enable-auto-id-generation";
@@ -750,11 +750,19 @@ static void applyMetadata(
750750
}
751751
}
752752

753-
options.setEnableTimberLogs(
754-
readBool(metadata, logger, ENABLE_TIMBER_LOGS, options.isEnableTimberLogs()));
753+
options.setTimberLogCaptureEnabled(
754+
readBool(
755+
metadata,
756+
logger,
757+
TIMBER_LOG_CAPTURE_ENABLED,
758+
options.getTimberLogCaptureEnabled()));
755759

756-
options.setEnableLogcatLogs(
757-
readBool(metadata, logger, ENABLE_LOGCAT_LOGS, options.isEnableLogcatLogs()));
760+
options.setLogcatLogCaptureEnabled(
761+
readBool(
762+
metadata,
763+
logger,
764+
LOGCAT_LOG_CAPTURE_ENABLED,
765+
options.getLogcatLogCaptureEnabled()));
758766

759767
final @NotNull SentryFeedbackOptions feedbackOptions = options.getFeedbackOptions();
760768
feedbackOptions.setNameRequired(

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public final class SentryAndroidOptions extends SentryOptions {
7676
private boolean enableNetworkEventBreadcrumbs = true;
7777

7878
/** Enable or disable automatic Sentry Logs capture from Timber. Default is disabled. */
79-
private boolean enableTimberLogs = false;
79+
private boolean timberLogCaptureEnabled = false;
8080

8181
/** Enable or disable automatic Sentry Logs capture from Logcat. Default is disabled. */
82-
private boolean enableLogcatLogs = false;
82+
private boolean logcatLogCaptureEnabled = false;
8383

8484
/**
8585
* Enables the Auto instrumentation for Activity lifecycle tracing.
@@ -511,20 +511,20 @@ public void setEnableNetworkEventBreadcrumbs(boolean enableNetworkEventBreadcrum
511511
this.enableNetworkEventBreadcrumbs = enableNetworkEventBreadcrumbs;
512512
}
513513

514-
public boolean isEnableTimberLogs() {
515-
return enableTimberLogs;
514+
public boolean getTimberLogCaptureEnabled() {
515+
return timberLogCaptureEnabled;
516516
}
517517

518-
public void setEnableTimberLogs(boolean enableTimberLogs) {
519-
this.enableTimberLogs = enableTimberLogs;
518+
public void setTimberLogCaptureEnabled(boolean timberLogCaptureEnabled) {
519+
this.timberLogCaptureEnabled = timberLogCaptureEnabled;
520520
}
521521

522-
public boolean isEnableLogcatLogs() {
523-
return enableLogcatLogs;
522+
public boolean getLogcatLogCaptureEnabled() {
523+
return logcatLogCaptureEnabled;
524524
}
525525

526-
public void setEnableLogcatLogs(boolean enableLogcatLogs) {
527-
this.enableLogcatLogs = enableLogcatLogs;
526+
public void setLogcatLogCaptureEnabled(boolean logcatLogCaptureEnabled) {
527+
this.logcatLogCaptureEnabled = logcatLogCaptureEnabled;
528528
}
529529

530530
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static void addAsLog(
5555
final @NotNull ScopesAdapter scopes = ScopesAdapter.getInstance();
5656
final @NotNull SentryOptions options = scopes.getOptions();
5757
if (!(options instanceof SentryAndroidOptions)
58-
|| !((SentryAndroidOptions) options).isEnableLogcatLogs()) {
58+
|| !((SentryAndroidOptions) options).getLogcatLogCaptureEnabled()) {
5959
return;
6060
}
6161
final @Nullable String trMessage = tr != null ? tr.getMessage() : null;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,18 +709,18 @@ class AndroidOptionsInitializerTest {
709709
val actual =
710710
fixture.sentryOptions.integrations.firstOrNull { it is SentryTimberIntegration }
711711
as SentryTimberIntegration
712-
assertFalse(actual.enableLogs)
712+
assertFalse(actual.logsEnabled)
713713
}
714714

715715
@Test
716-
fun `SentryTimberIntegration receives Timber logs option`() {
717-
fixture.sentryOptions.isEnableTimberLogs = true
716+
fun `SentryTimberIntegration receives Timber log capture option`() {
717+
fixture.sentryOptions.timberLogCaptureEnabled = true
718718
fixture.initSutWithClassLoader(isTimberAvailable = true)
719719

720720
val actual =
721721
fixture.sentryOptions.integrations.firstOrNull { it is SentryTimberIntegration }
722722
as SentryTimberIntegration
723-
assertTrue(actual.enableLogs)
723+
assertTrue(actual.logsEnabled)
724724
}
725725

726726
@Test

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,52 +2176,52 @@ class ManifestMetadataReaderTest {
21762176
}
21772177

21782178
@Test
2179-
fun `applyMetadata keeps Timber logs disabled if not found`() {
2179+
fun `applyMetadata keeps Timber log capture disabled if not found`() {
21802180
val context = fixture.getContext()
21812181

21822182
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
21832183

2184-
assertFalse(fixture.options.isEnableTimberLogs)
2184+
assertFalse(fixture.options.timberLogCaptureEnabled)
21852185
}
21862186

21872187
@Test
2188-
fun `applyMetadata reads Timber logs enabled to options`() {
2189-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_TIMBER_LOGS to true)
2188+
fun `applyMetadata reads Timber log capture enabled to options`() {
2189+
val bundle = bundleOf(ManifestMetadataReader.TIMBER_LOG_CAPTURE_ENABLED to true)
21902190
val context = fixture.getContext(metaData = bundle)
21912191

21922192
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
21932193

2194-
assertTrue(fixture.options.isEnableTimberLogs)
2194+
assertTrue(fixture.options.timberLogCaptureEnabled)
21952195
}
21962196

21972197
@Test
2198-
fun `applyMetadata keeps Logcat logs disabled if not found`() {
2198+
fun `applyMetadata keeps Logcat log capture disabled if not found`() {
21992199
val context = fixture.getContext()
22002200

22012201
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
22022202

2203-
assertThat(fixture.options.isEnableLogcatLogs).isFalse()
2203+
assertThat(fixture.options.logcatLogCaptureEnabled).isFalse()
22042204
}
22052205

22062206
@Test
2207-
fun `applyMetadata reads Logcat logs enabled to options`() {
2208-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_LOGCAT_LOGS to true)
2207+
fun `applyMetadata reads Logcat log capture enabled to options`() {
2208+
val bundle = bundleOf(ManifestMetadataReader.LOGCAT_LOG_CAPTURE_ENABLED to true)
22092209
val context = fixture.getContext(metaData = bundle)
22102210

22112211
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
22122212

2213-
assertThat(fixture.options.isEnableLogcatLogs).isTrue()
2213+
assertThat(fixture.options.logcatLogCaptureEnabled).isTrue()
22142214
}
22152215

22162216
@Test
2217-
fun `applyMetadata reads Logcat logs disabled to options`() {
2218-
fixture.options.isEnableLogcatLogs = true
2219-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_LOGCAT_LOGS to false)
2217+
fun `applyMetadata reads Logcat log capture disabled to options`() {
2218+
fixture.options.logcatLogCaptureEnabled = true
2219+
val bundle = bundleOf(ManifestMetadataReader.LOGCAT_LOG_CAPTURE_ENABLED to false)
22202220
val context = fixture.getContext(metaData = bundle)
22212221

22222222
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
22232223

2224-
assertThat(fixture.options.isEnableLogcatLogs).isFalse()
2224+
assertThat(fixture.options.logcatLogCaptureEnabled).isFalse()
22252225
}
22262226

22272227
@Test

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,31 @@ class SentryAndroidOptionsTest {
9595
}
9696

9797
@Test
98-
fun `Timber logs are disabled by default`() {
98+
fun `Timber log capture is disabled by default`() {
9999
val sentryOptions = SentryAndroidOptions()
100100

101-
assertFalse(sentryOptions.isEnableTimberLogs)
101+
assertFalse(sentryOptions.timberLogCaptureEnabled)
102102
}
103103

104104
@Test
105-
fun `Timber logs can be enabled`() {
105+
fun `Timber log capture can be enabled`() {
106106
val sentryOptions = SentryAndroidOptions()
107-
sentryOptions.isEnableTimberLogs = true
107+
sentryOptions.timberLogCaptureEnabled = true
108108

109-
assertTrue(sentryOptions.isEnableTimberLogs)
109+
assertTrue(sentryOptions.timberLogCaptureEnabled)
110110
}
111111

112112
@Test
113-
fun `Logcat logs are disabled by default`() {
114-
assertThat(SentryAndroidOptions().isEnableLogcatLogs).isFalse()
113+
fun `Logcat log capture is disabled by default`() {
114+
assertThat(SentryAndroidOptions().logcatLogCaptureEnabled).isFalse()
115115
}
116116

117117
@Test
118-
fun `Logcat logs can be enabled`() {
118+
fun `Logcat log capture can be enabled`() {
119119
val sentryOptions = SentryAndroidOptions()
120-
sentryOptions.isEnableLogcatLogs = true
120+
sentryOptions.logcatLogCaptureEnabled = true
121121

122-
assertThat(sentryOptions.isEnableLogcatLogs).isTrue()
122+
assertThat(sentryOptions.logcatLogCaptureEnabled).isTrue()
123123
}
124124

125125
@Test

0 commit comments

Comments
 (0)