Skip to content

Commit

Permalink
Fix: Initialize Sentry in Logback appender when DSN is not set in XML…
Browse files Browse the repository at this point in the history
… config (#1296)

* Fix: Start Logback appender when DSN is not set in XML config

Fixes #1295

* changelog.
  • Loading branch information
maciejwalkowiak authored Feb 26, 2021
1 parent 17db034 commit 87afadb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# vNext

* Fix: Fix setting in-app-includes from external properties (#1291)
* Fix: Initialize Sentry in Logback appender when DSN is not set in XML config (#1296)
* Fix: Fix JUL integration SDK name (#1293)

# 4.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class SentryAppender extends UnsynchronizedAppenderBase<ILoggingEve
@Override
public void start() {
if (!Sentry.isEnabled()) {
if (options.getDsn() != null && !options.getDsn().endsWith("_IS_UNDEFINED")) {
if (options.getDsn() == null || !options.getDsn().endsWith("_IS_UNDEFINED")) {
options.setEnableExternalConfiguration(true);
options.setSentryClientName(BuildConfig.SENTRY_LOGBACK_SDK_NAME);
options.setSdkVersion(createSdkVersion(options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,19 @@ class SentryAppenderTest {
}

@Test
fun `does not initialize Sentry when environment variable with DSN is not set`() {
fun `does not initialize Sentry when environment variable with DSN is passed through environment variable that is not set`() {
// environment variables referenced in the logback.xml that are not set in the OS, have value "ENV_NAME_IS_UNDEFINED"
fixture = Fixture(dsn = "DSN_IS_UNDEFINED", minimumEventLevel = Level.DEBUG)

assertTrue(fixture.loggerContext.statusManager.copyOfStatusList.none { it.level == Status.WARN })
}

@Test
fun `does initialize Sentry when DSN is not set`() {
System.setProperty("sentry.dsn", "http://key@localhost/proj")
fixture = Fixture(dsn = null, minimumEventLevel = Level.DEBUG)

assertTrue(Sentry.isEnabled())
System.clearProperty("sentry.dsn")
}
}

0 comments on commit 87afadb

Please sign in to comment.