Skip to content

Commit 599bc3e

Browse files
adinauerclaude
andcommitted
ref(logging)!: Add opt-in flags to existing constructors
Add the Logs opt-in directly to the existing Log4j2 and Timber constructor signatures instead of retaining compatibility overloads. Document the intentional v9 API changes in the changelog. BREAKING CHANGE: Log4j2 and Timber callers using explicit constructor signatures must pass the new Logs opt-in argument. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9bb89b8 commit 599bc3e

9 files changed

Lines changed: 23 additions & 100 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
### Breaking Changes
6+
7+
- Add a `logsEnabled` argument to the preferred Log4j2 `SentryAppender` constructor and
8+
`createAppender` factory. Pass `true` to opt in to Sentry Logs capture or `false` to keep it
9+
disabled. ([#5941](https://github.com/getsentry/sentry-java/pull/5941))
10+
- Add a `logsEnabled` argument to the `SentryTimberIntegration` and `SentryTimberTree` JVM
11+
constructors. It defaults to `false` for Kotlin callers; Java callers using the explicit level
12+
constructors must pass the new argument. ([#5943](https://github.com/getsentry/sentry-java/pull/5943))
13+
514
### Features
615

716
- Remove the aggregate Sentry Metrics enable flag; `Sentry.metrics()` calls now capture Metrics by default ([#5953](https://github.com/getsentry/sentry-java/pull/5953))

‎sentry-android-timber/api/sentry-android-timber.api‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ public final class io/sentry/android/timber/BuildConfig {
99

1010
public final class io/sentry/android/timber/SentryTimberIntegration : io/sentry/Integration, java/io/Closeable {
1111
public fun <init> ()V
12-
public fun <init> (Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;)V
13-
public synthetic fun <init> (Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
1412
public fun <init> (Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;Z)V
15-
public fun <init> (Lio/sentry/util/LazyEvaluator$Evaluator;)V
16-
public fun <init> (Z)V
13+
public synthetic fun <init> (Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
1714
public fun close ()V
1815
public final fun getLogsEnabled ()Z
1916
public final fun getMinBreadcrumbLevel ()Lio/sentry/SentryLevel;
@@ -23,9 +20,8 @@ public final class io/sentry/android/timber/SentryTimberIntegration : io/sentry/
2320
}
2421

2522
public final class io/sentry/android/timber/SentryTimberTree : timber/log/Timber$Tree {
26-
public fun <init> (Lio/sentry/IScopes;Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;)V
27-
public synthetic fun <init> (Lio/sentry/IScopes;Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2823
public fun <init> (Lio/sentry/IScopes;Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;Z)V
24+
public synthetic fun <init> (Lio/sentry/IScopes;Lio/sentry/SentryLevel;Lio/sentry/SentryLevel;Lio/sentry/SentryLogLevel;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
2925
public fun d (Ljava/lang/String;[Ljava/lang/Object;)V
3026
public fun d (Ljava/lang/Throwable;)V
3127
public fun d (Ljava/lang/Throwable;Ljava/lang/String;[Ljava/lang/Object;)V

‎sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberIntegration.kt‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,14 @@ public class SentryTimberIntegration(
1818
public val minEventLevel: SentryLevel = SentryLevel.ERROR,
1919
public val minBreadcrumbLevel: SentryLevel = SentryLevel.INFO,
2020
public val minLogsLevel: SentryLogLevel = SentryLogLevel.INFO,
21+
logsEnabled: Boolean = false,
2122
) : Integration, Closeable {
2223
public val logsEnabled: Boolean
2324
get() = logsEnabledProvider.evaluate()
2425

25-
private var logsEnabledProvider: Evaluator<Boolean> = Evaluator { false }
26+
private var logsEnabledProvider: Evaluator<Boolean> = Evaluator { logsEnabled }
2627

27-
public constructor(logsEnabled: Boolean) : this() {
28-
logsEnabledProvider = Evaluator { logsEnabled }
29-
}
30-
31-
public constructor(
32-
minEventLevel: SentryLevel,
33-
minBreadcrumbLevel: SentryLevel,
34-
minLogsLevel: SentryLogLevel,
35-
logsEnabled: Boolean,
36-
) : this(minEventLevel, minBreadcrumbLevel, minLogsLevel) {
37-
logsEnabledProvider = Evaluator { logsEnabled }
38-
}
39-
40-
public constructor(logsEnabledProvider: Evaluator<Boolean>) : this() {
28+
internal constructor(logsEnabledProvider: Evaluator<Boolean>) : this() {
4129
this.logsEnabledProvider = logsEnabledProvider
4230
}
4331

‎sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberTree.kt‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,8 @@ public class SentryTimberTree(
1919
private val minEventLevel: SentryLevel,
2020
private val minBreadcrumbLevel: SentryLevel,
2121
private val minLogLevel: SentryLogLevel = SentryLogLevel.INFO,
22+
private val logsEnabled: Boolean = false,
2223
) : Timber.Tree() {
23-
private var logsEnabled: Boolean = false
24-
25-
public constructor(
26-
scopes: IScopes,
27-
minEventLevel: SentryLevel,
28-
minBreadcrumbLevel: SentryLevel,
29-
minLogLevel: SentryLogLevel,
30-
logsEnabled: Boolean,
31-
) : this(scopes, minEventLevel, minBreadcrumbLevel, minLogLevel) {
32-
this.logsEnabled = logsEnabled
33-
}
34-
3524
private val pendingTag = ThreadLocal<String?>()
3625

3726
private fun retrieveTag(): String? {

‎sentry-log4j2/api/sentry-log4j2.api‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ public final class io/sentry/log4j2/BuildConfig {
66
public class io/sentry/log4j2/SentryAppender : org/apache/logging/log4j/core/appender/AbstractAppender {
77
public static final field MECHANISM_TYPE Ljava/lang/String;
88
public fun <init> (Ljava/lang/String;Lorg/apache/logging/log4j/core/Filter;Ljava/lang/String;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Ljava/lang/Boolean;Lio/sentry/ITransportFactory;Lio/sentry/IScopes;[Ljava/lang/String;)V
9-
public fun <init> (Ljava/lang/String;Lorg/apache/logging/log4j/core/Filter;Ljava/lang/String;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Ljava/lang/Boolean;Lio/sentry/ITransportFactory;Lio/sentry/IScopes;[Ljava/lang/String;)V
109
public fun <init> (Ljava/lang/String;Lorg/apache/logging/log4j/core/Filter;Ljava/lang/String;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;ZLjava/lang/Boolean;Lio/sentry/ITransportFactory;Lio/sentry/IScopes;[Ljava/lang/String;)V
1110
public fun append (Lorg/apache/logging/log4j/core/LogEvent;)V
1211
protected fun captureLog (Lorg/apache/logging/log4j/core/LogEvent;)V
1312
public static fun createAppender (Ljava/lang/String;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Boolean;Lorg/apache/logging/log4j/core/Filter;Ljava/lang/String;)Lio/sentry/log4j2/SentryAppender;
14-
public static fun createAppender (Ljava/lang/String;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/Level;Ljava/lang/String;Ljava/lang/Boolean;Lorg/apache/logging/log4j/core/Filter;Ljava/lang/String;)Lio/sentry/log4j2/SentryAppender;
1513
protected fun createBreadcrumb (Lorg/apache/logging/log4j/core/LogEvent;)Lio/sentry/Breadcrumb;
1614
protected fun createEvent (Lorg/apache/logging/log4j/core/LogEvent;)Lio/sentry/SentryEvent;
1715
public fun getMinimumBreadcrumbLevel ()Lorg/apache/logging/log4j/Level;

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

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public class SentryAppender extends AbstractAppender {
6767

6868
/**
6969
* @deprecated This constructor is deprecated. Please use {@link #SentryAppender(String, Filter,
70-
* String, Level, Level, Level, Boolean, ITransportFactory, IScopes, String[])} instead.
70+
* String, Level, Level, Level, boolean, Boolean, ITransportFactory, IScopes, String[])}
71+
* instead.
7172
*/
7273
@Deprecated
7374
@SuppressWarnings("InlineMeSuggester")
@@ -88,30 +89,6 @@ public SentryAppender(
8889
minimumBreadcrumbLevel,
8990
minimumEventLevel,
9091
null,
91-
debug,
92-
transportFactory,
93-
scopes,
94-
contextTags);
95-
}
96-
97-
public SentryAppender(
98-
final @NotNull String name,
99-
final @Nullable Filter filter,
100-
final @Nullable String dsn,
101-
final @Nullable Level minimumBreadcrumbLevel,
102-
final @Nullable Level minimumEventLevel,
103-
final @Nullable Level minimumLevel,
104-
final @Nullable Boolean debug,
105-
final @Nullable ITransportFactory transportFactory,
106-
final @NotNull IScopes scopes,
107-
final @Nullable String[] contextTags) {
108-
this(
109-
name,
110-
filter,
111-
dsn,
112-
minimumBreadcrumbLevel,
113-
minimumEventLevel,
114-
minimumLevel,
11592
false,
11693
debug,
11794
transportFactory,
@@ -156,32 +133,12 @@ public SentryAppender(
156133
* @param minimumBreadcrumbLevel The min. level of the breadcrumb.
157134
* @param minimumEventLevel The min. level of the event.
158135
* @param minimumLevel The min. level of the log event.
136+
* @param logsEnabled Whether to capture log events as Sentry Logs.
159137
* @param dsn the Sentry DSN.
160138
* @param debug if Sentry debug mode should be on
161139
* @param filter The filter, if any, to use.
162140
* @return The SentryAppender.
163141
*/
164-
public static @Nullable SentryAppender createAppender(
165-
final @Nullable String name,
166-
final @Nullable Level minimumBreadcrumbLevel,
167-
final @Nullable Level minimumEventLevel,
168-
final @Nullable Level minimumLevel,
169-
final @Nullable String dsn,
170-
final @Nullable Boolean debug,
171-
final @Nullable Filter filter,
172-
final @Nullable String contextTags) {
173-
return createAppender(
174-
name,
175-
minimumBreadcrumbLevel,
176-
minimumEventLevel,
177-
minimumLevel,
178-
false,
179-
dsn,
180-
debug,
181-
filter,
182-
contextTags);
183-
}
184-
185142
@PluginFactory
186143
public static @Nullable SentryAppender createAppender(
187144
@Nullable @PluginAttribute("name") final String name,

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class SentryAppenderTest {
310310
}
311311

312312
@Test
313-
fun `existing constructors default logs to disabled`() {
313+
fun `constructors can opt out of logs capture`() {
314314
val scopes = mock<IScopes>()
315315
val event = mock<LogEvent>()
316316
whenever(event.level).thenReturn(Level.INFO)
@@ -335,6 +335,7 @@ class SentryAppenderTest {
335335
Level.OFF,
336336
Level.OFF,
337337
Level.INFO,
338+
false,
338339
null,
339340
null,
340341
scopes,
@@ -348,24 +349,9 @@ class SentryAppenderTest {
348349
}
349350

350351
@Test
351-
fun `existing factory and plugin attribute default logs to disabled`() {
352+
fun `plugin attribute defaults logs to disabled`() {
352353
val event = mock<LogEvent>()
353354
whenever(event.level).thenReturn(Level.INFO)
354-
val existingAppender =
355-
spy(
356-
assertNotNull(
357-
SentryAppender.createAppender(
358-
"existing",
359-
Level.OFF,
360-
Level.OFF,
361-
Level.INFO,
362-
null,
363-
null,
364-
null,
365-
null,
366-
)
367-
)
368-
)
369355
val pluginDefaultAppender =
370356
spy(
371357
assertNotNull(
@@ -383,10 +369,8 @@ class SentryAppenderTest {
383369
)
384370
)
385371

386-
existingAppender.append(event)
387372
pluginDefaultAppender.append(event)
388373

389-
verify(existingAppender, never()).captureLog(event)
390374
verify(pluginDefaultAppender, never()).captureLog(event)
391375
}
392376

‎sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryLog4j2AppenderAutoConfigurationTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class SentryLog4j2AppenderAutoConfigurationTest {
238238
null,
239239
null,
240240
null,
241+
false,
241242
null,
242243
null,
243244
io.sentry.ScopesAdapter.getInstance(),

‎sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryLog4j2AppenderAutoConfigurationTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class SentryLog4j2AppenderAutoConfigurationTest {
238238
null,
239239
null,
240240
null,
241+
false,
241242
null,
242243
null,
243244
io.sentry.ScopesAdapter.getInstance(),

0 commit comments

Comments
 (0)