Skip to content

Commit 562204d

Browse files
bruno-garciamarandanetomaciejwalkowiak
authored
feat: init overload dsn (#1195)
Co-authored-by: Manoel Aranda Neto <[email protected]> Co-authored-by: Maciej Walkowiak <[email protected]>
1 parent b668630 commit 562204d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Enhancement: Polish Performance API (#1165)
1313
* Enhancement: Set "debug" through external properties (#1186)
1414
* Enhancement: Simplify Spring integration (#1188)
15+
* Enhancement: Init overload with dsn (#1195)
1516
* Enhancement: Enable Kotlin map-like access on CustomSamplingContext (#1192)
1617
* Enhancement: Auto register custom ITransportFactory in Spring integration (#1194)
1718
* Enhancement: Improve Kotlin property access in Performance API (#1193)

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ public static void init() {
5959
init(options -> options.setEnableExternalConfiguration(true), GLOBAL_HUB_DEFAULT_MODE);
6060
}
6161

62+
/**
63+
* Initializes the SDK
64+
*
65+
* @param dsn The Sentry DSN
66+
*/
67+
public static void init(final @NotNull String dsn) {
68+
init(options -> options.setDsn(dsn));
69+
}
70+
6271
/**
6372
* Initializes the SDK
6473
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ class SentryTest {
105105
verify(logger).log(eq(SentryLevel.WARNING), eq("Sentry has been already initialized. Previous configuration will be overwritten."))
106106
}
107107

108+
@Test
109+
fun `warns about multiple Sentry initializations with string overload`() {
110+
val logger = mock<ILogger>()
111+
Sentry.init(dsn)
112+
Sentry.init {
113+
it.dsn = dsn
114+
it.setDebug(true)
115+
it.setLogger(logger)
116+
}
117+
verify(logger).log(eq(SentryLevel.WARNING), eq("Sentry has been already initialized. Previous configuration will be overwritten."))
118+
}
119+
108120
@Test
109121
fun `initializes Sentry using external properties`() {
110122
// create a sentry.properties file in temporary folder

0 commit comments

Comments
 (0)