Skip to content

Commit 3a3da5c

Browse files
authored
Merge pull request #5947 from getsentry/feat/remove-logs-enable-flag
feat(core): [Logs and Metrics Enable Flags 7] Remove Logs enable flag
2 parents df083ba + 67e11cc commit 3a3da5c

44 files changed

Lines changed: 49 additions & 255 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.

‎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 Logs enable flag; manual `Sentry.logger()` calls now capture Logs by default ([#5947](https://github.com/getsentry/sentry-java/pull/5947))
78
- Add an explicit Logs opt-in to Spring Boot logging auto-configuration ([#5946](https://github.com/getsentry/sentry-java/pull/5946))
89
- Add an explicit Logs opt-in to the Android Logcat integration ([#5945](https://github.com/getsentry/sentry-java/pull/5945))
910
- Add an explicit Logs opt-in to the Android Timber integration ([#5943](https://github.com/getsentry/sentry-java/pull/5943))

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

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

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

195-
static final String ENABLE_LOGS = "io.sentry.logs.enabled";
196-
197195
static final String ENABLE_TIMBER_LOGS = "io.sentry.timber.logs.enabled";
198196

199197
static final String ENABLE_LOGCAT_LOGS = "io.sentry.logcat.logs.enabled";
@@ -754,10 +752,6 @@ static void applyMetadata(
754752
}
755753
}
756754

757-
options
758-
.getLogs()
759-
.setEnabled(readBool(metadata, logger, ENABLE_LOGS, options.getLogs().isEnabled()));
760-
761755
options.setEnableTimberLogs(
762756
readBool(metadata, logger, ENABLE_TIMBER_LOGS, options.isEnableTimberLogs()));
763757

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +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()
59-
|| !options.getLogs().isEnabled()) {
58+
|| !((SentryAndroidOptions) options).isEnableLogcatLogs()) {
6059
return;
6160
}
6261
final @Nullable String trMessage = tr != null ? tr.getMessage() : null;

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,31 +2175,6 @@ class ManifestMetadataReaderTest {
21752175
assertTrue(fixture.options.inAppExcludes.isEmpty())
21762176
}
21772177

2178-
@Test
2179-
fun `applyMetadata reads logs enabled and keep default value if not found`() {
2180-
// Arrange
2181-
val context = fixture.getContext()
2182-
2183-
// Act
2184-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2185-
2186-
// Assert
2187-
assertFalse(fixture.options.logs.isEnabled)
2188-
}
2189-
2190-
@Test
2191-
fun `applyMetadata reads logs enabled to options`() {
2192-
// Arrange
2193-
val bundle = bundleOf(ManifestMetadataReader.ENABLE_LOGS to true)
2194-
val context = fixture.getContext(metaData = bundle)
2195-
2196-
// Act
2197-
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
2198-
2199-
// Assert
2200-
assertTrue(fixture.options.logs.isEnabled)
2201-
}
2202-
22032178
@Test
22042179
fun `applyMetadata keeps Timber logs disabled if not found`() {
22052180
val context = fixture.getContext()

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import java.lang.RuntimeException
1414
import kotlin.test.AfterTest
1515
import kotlin.test.Test
1616
import kotlin.test.assertEquals
17-
import kotlin.test.assertTrue
1817
import org.junit.runner.RunWith
1918
import org.robolectric.shadows.ShadowLog
2019

@@ -40,7 +39,6 @@ class SentryLogcatAdapterTest {
4039
breadcrumbs.add(breadcrumb)
4140
breadcrumb
4241
}
43-
it.logs.isEnabled = true
4442
if (enableLogcatLogs != null) {
4543
it.isEnableLogcatLogs = enableLogcatLogs
4644
}
@@ -205,26 +203,6 @@ class SentryLogcatAdapterTest {
205203
.assert("$commonMsg wtf exception\n${throwable.message}", SentryLogLevel.FATAL)
206204
}
207205

208-
@Test
209-
fun `do not send logs if logs is disabled`() {
210-
fixture.initSut { it.logs.isEnabled = false }
211-
212-
SentryLogcatAdapter.v(tag, "$commonMsg verbose")
213-
SentryLogcatAdapter.i(tag, "$commonMsg info")
214-
SentryLogcatAdapter.d(tag, "$commonMsg debug")
215-
SentryLogcatAdapter.w(tag, "$commonMsg warning")
216-
SentryLogcatAdapter.e(tag, "$commonMsg error")
217-
SentryLogcatAdapter.wtf(tag, "$commonMsg wtf")
218-
SentryLogcatAdapter.e(tag, "$commonMsg error exception", throwable)
219-
SentryLogcatAdapter.v(tag, "$commonMsg verbose exception", throwable)
220-
SentryLogcatAdapter.i(tag, "$commonMsg info exception", throwable)
221-
SentryLogcatAdapter.d(tag, "$commonMsg debug exception", throwable)
222-
SentryLogcatAdapter.w(tag, "$commonMsg warning exception", throwable)
223-
SentryLogcatAdapter.wtf(tag, "$commonMsg wtf exception", throwable)
224-
225-
assertTrue(fixture.logs.isEmpty())
226-
}
227-
228206
@Test
229207
fun `logs add correct number of breadcrumb`() {
230208
fixture.initSut()

‎sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ public void publish(final @NotNull LogRecord record) {
114114
return;
115115
}
116116
try {
117-
if (enableLogs
118-
&& ScopesAdapter.getInstance().getOptions().getLogs().isEnabled()
119-
&& record.getLevel().intValue() >= minimumLevel.intValue()) {
117+
if (enableLogs && record.getLevel().intValue() >= minimumLevel.intValue()) {
120118
captureLog(record);
121119
}
122120
if (record.getLevel().intValue() >= minimumEventLevel.intValue()) {

‎sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class SentryHandlerTest {
4242
contextTags: List<String>? = null,
4343
printfStyle: Boolean? = null,
4444
enableLogs: Boolean? = true,
45-
enableGlobalLogs: Boolean = true,
4645
) {
4746
var logger: Logger
4847
var handler: SentryHandler
@@ -51,7 +50,6 @@ class SentryHandlerTest {
5150
val options = SentryOptions()
5251
options.dsn = "http://key@localhost/proj"
5352
options.setTransportFactory { _, _ -> transport }
54-
options.logs.isEnabled = enableGlobalLogs
5553
options.logs.loggerBatchProcessorFactory = ILoggerBatchProcessorFactory { options, client ->
5654
LoggerBatchProcessor(options, client, ImmediateExecutorService())
5755
}
@@ -438,7 +436,7 @@ class SentryHandlerTest {
438436

439437
@Test
440438
fun `does not capture logs by default`() {
441-
fixture = Fixture(enableLogs = null, enableGlobalLogs = true)
439+
fixture = Fixture(enableLogs = null)
442440

443441
assertFalse(fixture.handler.isEnableLogs)
444442
fixture.logger.info("this should not be captured as a log")
@@ -449,7 +447,7 @@ class SentryHandlerTest {
449447

450448
@Test
451449
fun `captures logs when enabled through Java`() {
452-
fixture = Fixture(enableLogs = true, enableGlobalLogs = true)
450+
fixture = Fixture(enableLogs = true)
453451

454452
assertTrue(fixture.handler.isEnableLogs)
455453
fixture.logger.info("this should be captured as a log")
@@ -470,7 +468,6 @@ class SentryHandlerTest {
470468
minimumBreadcrumbLevel = Level.INFO,
471469
minimumEventLevel = Level.SEVERE,
472470
enableLogs = false,
473-
enableGlobalLogs = true,
474471
)
475472

476473
fixture.logger.info("this should be a breadcrumb")
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
release=release from sentry.properties
2-
logs.enabled=true

‎sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ void start(final @NotNull Sentry.OptionsConfiguration<SentryOptions> optionsConf
269269

270270
@Override
271271
public void append(final @NotNull LogEvent eventObject) {
272-
if (enableLogs
273-
&& scopes.getOptions().getLogs().isEnabled()
274-
&& eventObject.getLevel().isMoreSpecificThan(minimumLevel)) {
272+
if (enableLogs && eventObject.getLevel().isMoreSpecificThan(minimumLevel)) {
275273
captureLog(eventObject);
276274
}
277275
if (eventObject.getLevel().isMoreSpecificThan(minimumEventLevel)) {

‎sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class SentryAppenderTest {
6363
debug: Boolean? = null,
6464
contextTags: List<String>? = null,
6565
enableLogs: Boolean = true,
66-
enableGlobalLogs: Boolean = true,
6766
): ExtendedLogger {
6867
if (transportFactory != null) {
6968
this.transportFactory = transportFactory
@@ -106,7 +105,6 @@ class SentryAppenderTest {
106105

107106
appender.start(
108107
appender.getOptionsConfiguration { options ->
109-
options.logs.isEnabled = enableGlobalLogs
110108
options.logs.loggerBatchProcessorFactory =
111109
ILoggerBatchProcessorFactory { options, client ->
112110
LoggerBatchProcessor(options, client, ImmediateExecutorService())
@@ -264,7 +262,7 @@ class SentryAppenderTest {
264262

265263
@Test
266264
fun `does not capture logs when local logs are disabled`() {
267-
val logger = fixture.getSut(enableLogs = false, enableGlobalLogs = true)
265+
val logger = fixture.getSut(enableLogs = false)
268266

269267
logger.info("this should not be captured as a log")
270268
Sentry.flush(10)
@@ -273,8 +271,8 @@ class SentryAppenderTest {
273271
}
274272

275273
@Test
276-
fun `captures logs when local and aggregate logs are enabled`() {
277-
val logger = fixture.getSut(enableLogs = true, enableGlobalLogs = true)
274+
fun `captures logs when local logs are enabled`() {
275+
val logger = fixture.getSut(enableLogs = true)
278276

279277
logger.info("this should be captured as a log")
280278
Sentry.flush(10)
@@ -294,7 +292,6 @@ class SentryAppenderTest {
294292
minimumBreadcrumbLevel = Level.INFO,
295293
minimumEventLevel = Level.ERROR,
296294
enableLogs = false,
297-
enableGlobalLogs = true,
298295
)
299296

300297
logger.info("this should be a breadcrumb")
@@ -397,7 +394,6 @@ class SentryAppenderTest {
397394
fun `plugin attribute enables logs with explicit opt in`() {
398395
initForTest {
399396
it.dsn = "http://key@localhost/proj"
400-
it.logs.isEnabled = true
401397
}
402398
val event = mock<LogEvent>()
403399
whenever(event.level).thenReturn(Level.INFO)

0 commit comments

Comments
 (0)