Skip to content

Commit c3b9cf7

Browse files
Set "debug" through external properties. (#1186)
1 parent d69532c commit c3b9cf7

16 files changed

+96
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Enhancement: Add overload for `transaction/span.finish(SpanStatus)` (#1182)
99
* Fix: Bring back support for setting transaction name without ongoing transaction (#1183)
1010
* Enhancement: Simplify registering traces sample callback in Spring integration (#1184)
11+
* Enhancement: Set "debug" through external properties (#1186)
1112

1213
# 4.0.0-alpha.3
1314

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class AndroidOptionsInitializerTest {
163163
val mockContext = ContextUtilsTest.mockMetaData(metaData = createBundleWithDsn())
164164
val logger = mock<ILogger>()
165165
val sentryOptions = SentryAndroidOptions().apply {
166-
isDebug = true
166+
setDebug(true)
167167
}
168168

169169
AndroidOptionsInitializer.init(sentryOptions, mockContext, logger, createBuildInfo(), createClassMock())
@@ -180,7 +180,7 @@ class AndroidOptionsInitializerTest {
180180
val mockContext = ContextUtilsTest.mockMetaData(metaData = createBundleWithDsn())
181181
val logger = mock<ILogger>()
182182
val sentryOptions = SentryAndroidOptions().apply {
183-
isDebug = true
183+
setDebug(true)
184184
}
185185

186186
AndroidOptionsInitializer.init(sentryOptions, mockContext, logger, createBuildInfo(14), createClassMock())
@@ -197,7 +197,7 @@ class AndroidOptionsInitializerTest {
197197
val mockContext = ContextUtilsTest.mockMetaData(metaData = createBundleWithDsn())
198198
val logger = mock<ILogger>()
199199
val sentryOptions = SentryAndroidOptions().apply {
200-
isDebug = true
200+
setDebug(true)
201201
}
202202

203203
AndroidOptionsInitializer.init(sentryOptions, mockContext, logger, createBuildInfo(), createClassMockThrows(UnsatisfiedLinkError()))
@@ -213,7 +213,7 @@ class AndroidOptionsInitializerTest {
213213
val mockContext = ContextUtilsTest.mockMetaData(metaData = createBundleWithDsn())
214214
val logger = mock<ILogger>()
215215
val sentryOptions = SentryAndroidOptions().apply {
216-
isDebug = true
216+
setDebug(true)
217217
}
218218

219219
AndroidOptionsInitializer.init(sentryOptions, mockContext, logger, createBuildInfo(), createClassMockThrows(ClassNotFoundException()))
@@ -229,7 +229,7 @@ class AndroidOptionsInitializerTest {
229229
val mockContext = ContextUtilsTest.mockMetaData(metaData = createBundleWithDsn())
230230
val logger = mock<ILogger>()
231231
val sentryOptions = SentryAndroidOptions().apply {
232-
isDebug = true
232+
setDebug(true)
233233
}
234234

235235
AndroidOptionsInitializer.init(sentryOptions, mockContext, logger, createBuildInfo(), createClassMockThrows(RuntimeException()))

sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DefaultAndroidEventProcessorTest {
4343
private class Fixture {
4444
val buildInfo = mock<IBuildInfoProvider>()
4545
val options = SentryOptions().apply {
46-
isDebug = true
46+
setDebug(true)
4747
setLogger(mock())
4848
sdkVersion = SdkVersion().apply {
4949
name = "test"

sentry-android-core/src/test/java/io/sentry/android/core/EnvelopeFileObserverTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class EnvelopeFileObserverTest {
3333
val envelopeSender = mock<IEnvelopeSender>()
3434
val logger = mock<ILogger>()
3535
val options = SentryOptions().apply {
36-
isDebug = true
36+
setDebug(true)
3737
setLogger(logger)
3838
}
3939

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ManifestMetadataReaderTest {
3636

3737
@Test
3838
fun `isAutoInit won't throw exception and is enabled by default`() {
39-
fixture.options.isDebug = true
39+
fixture.options.setDebug(true)
4040
val context = fixture.getContext()
4141

4242
assertTrue(ManifestMetadataReader.isAutoInit(context, fixture.logger))
@@ -53,7 +53,7 @@ class ManifestMetadataReaderTest {
5353

5454
@Test
5555
fun `applyMetadata won't throw exception`() {
56-
fixture.options.isDebug = true
56+
fixture.options.setDebug(true)
5757
val context = fixture.getContext()
5858

5959
ManifestMetadataReader.applyMetadata(context, fixture.options)

sentry-android-core/src/test/java/io/sentry/android/core/NdkIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class NdkIntegrationTest {
122122
private fun getOptions(enableNdk: Boolean = true, logger: ILogger = mock(), cacheDir: String? = "abc"): SentryAndroidOptions {
123123
return SentryAndroidOptions().apply {
124124
setLogger(logger)
125-
isDebug = true
125+
setDebug(true)
126126
isEnableNdk = enableNdk
127127
cacheDirPath = cacheDir
128128
}

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ public class io/sentry/SentryOptions {
735735
public fun setCacheDirPath (Ljava/lang/String;)V
736736
public fun setCacheDirSize (I)V
737737
public fun setConnectionTimeoutMillis (I)V
738-
public fun setDebug (Z)V
738+
public fun setDebug (Ljava/lang/Boolean;)V
739739
public fun setDiagnosticLevel (Lio/sentry/SentryLevel;)V
740740
public fun setDist (Ljava/lang/String;)V
741741
public fun setDistinctId (Ljava/lang/String;)V

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class SentryOptions {
6666
* Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging
6767
* information if something goes wrong. Default is disabled.
6868
*/
69-
private boolean debug;
69+
private @Nullable Boolean debug;
7070

7171
/** Turns NDK on or off. Default is enabled. */
7272
private boolean enableNdk = true;
@@ -270,6 +270,7 @@ public class SentryOptions {
270270
options.setEnableUncaughtExceptionHandler(
271271
propertiesProvider.getBooleanProperty("uncaught.handler.enabled"));
272272
options.setTracesSampleRate(propertiesProvider.getDoubleProperty("traces-sample-rate"));
273+
options.setDebug(propertiesProvider.getBooleanProperty("debug"));
273274
final Map<String, String> tags = propertiesProvider.getMap("tags");
274275
for (final Map.Entry<String, String> tag : tags.entrySet()) {
275276
options.setTag(tag.getKey(), tag.getValue());
@@ -353,18 +354,27 @@ public void setDsn(@Nullable String dsn) {
353354
* @return true if ON or false otherwise
354355
*/
355356
public boolean isDebug() {
356-
return debug;
357+
return Boolean.TRUE.equals(debug);
357358
}
358359

359360
/**
360361
* Sets the debug mode to ON or OFF Default is OFF
361362
*
362363
* @param debug true if ON or false otherwise
363364
*/
364-
public void setDebug(boolean debug) {
365+
public void setDebug(final @Nullable Boolean debug) {
365366
this.debug = debug;
366367
}
367368

369+
/**
370+
* Check if debug mode is ON, OFF or not set.
371+
*
372+
* @return true if ON or false otherwise
373+
*/
374+
private @Nullable Boolean getDebug() {
375+
return debug;
376+
}
377+
368378
/**
369379
* Returns the Logger interface
370380
*
@@ -1305,6 +1315,9 @@ void merge(final @NotNull SentryOptions options) {
13051315
if (options.getTracesSampleRate() != null) {
13061316
setTracesSampleRate(options.getTracesSampleRate());
13071317
}
1318+
if (options.getDebug() != null) {
1319+
setDebug(options.getDebug());
1320+
}
13081321
final Map<String, String> tags = new HashMap<>(options.getTags());
13091322
for (final Map.Entry<String, String> tag : tags.entrySet()) {
13101323
this.tags.put(tag.getKey(), tag.getValue());

sentry/src/test/java/io/sentry/DiagnosticLoggerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DiagnosticLoggerTest {
1010

1111
private class Fixture {
1212
val options = SentryOptions().apply {
13-
isDebug = true
13+
setDebug(true)
1414
setLogger(logger)
1515
}
1616
var logger: ILogger? = mock()
@@ -79,7 +79,7 @@ class DiagnosticLoggerTest {
7979

8080
@Test
8181
fun `when debug is false and option level is fatal, a call to log and level error is not logged`() {
82-
fixture.options.isDebug = false
82+
fixture.options.setDebug(false)
8383
val sut = fixture.getSut()
8484
val expectedLevel = SentryLevel.FATAL
8585
sut.log(expectedLevel, expectedMessage)
@@ -106,7 +106,7 @@ class DiagnosticLoggerTest {
106106

107107
@Test
108108
fun `when debug is false option level is debug, a call to log with throwable and level info is not logged`() {
109-
fixture.options.isDebug = false
109+
fixture.options.setDebug(false)
110110
fixture.options.setDiagnosticLevel(SentryLevel.DEBUG)
111111
val sut = fixture.getSut()
112112
val expectedLevel = SentryLevel.INFO
@@ -143,7 +143,7 @@ class DiagnosticLoggerTest {
143143

144144
@Test
145145
fun `when debug is false option level is fatal, a call to log with throwable and level error is not logged`() {
146-
fixture.options.isDebug = false
146+
fixture.options.setDebug(false)
147147
fixture.options.setDiagnosticLevel(SentryLevel.FATAL)
148148
val sut = fixture.getSut()
149149
val expectedLevel = SentryLevel.ERROR

sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DirectoryProcessorTest {
2929
var options = SentryOptions().noFlushTimeout()
3030

3131
init {
32-
options.isDebug = true
32+
options.setDebug(true)
3333
options.setLogger(logger)
3434
}
3535

0 commit comments

Comments
 (0)