Skip to content

Commit

Permalink
Merge pull request #44 from toweroy/update-sentry-dep
Browse files Browse the repository at this point in the history
Update SentryAppender to use sentry-logback dependency
  • Loading branch information
caesar-ralf authored Jul 10, 2023
2 parents 250b9a7 + 17c06ee commit d3623db
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
<version>0.6</version>
</dependency>
<dependency>
<groupId>com.getsentry.raven</groupId>
<artifactId>raven-logback</artifactId>
<version>7.8.2</version>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>6.11.0</version>
</dependency>

<!--test scope-->
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/spotify/logging/LoggingConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import com.getsentry.raven.logback.SentryAppender;
import com.spotify.logging.logback.CustomLogstashEncoder;
import com.spotify.logging.logback.MillisecondPrecisionSyslogAppender;
import io.sentry.SentryOptions;
import io.sentry.logback.SentryAppender;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -341,7 +342,9 @@ public static SentryAppender addSentryAppender(final String dsn, Level logLevelT
final LoggerContext context = rootLogger.getLoggerContext();

SentryAppender appender = new SentryAppender();
appender.setDsn(dsn);
SentryOptions sentryOptions = new SentryOptions();
sentryOptions.setDsn(dsn);
appender.setOptions(sentryOptions);

appender.setContext(context);
ThresholdFilter levelFilter = new ThresholdFilter();
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/spotify/logging/LoggingConfiguratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

package com.spotify.logging;

import static com.spotify.logging.LoggingConfigurator.addSentryAppender;
import static com.spotify.logging.LoggingConfigurator.getSyslogAppender;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -47,8 +48,10 @@
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.net.SyslogAppender;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.status.Status;
import com.google.common.collect.FluentIterable;
import com.spotify.logging.logback.CustomLogstashEncoder;
import io.sentry.logback.SentryAppender;
import net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -107,6 +110,31 @@ public void testGetSyslogAppenderRespectsNewLineReplacement() {
appender.getSuffixPattern());
}

@Test
public void testGetSentryAppenderNoErrorsWithDsnOption() {
SentryAppender sentryAppender =
addSentryAppender(
"https://[email protected]/0", LoggingConfigurator.Level.ERROR);

assertEquals(
0,
sentryAppender.getContext().getStatusManager().getCopyOfStatusList().stream()
.filter(
status -> {
if (status.getLevel() == Status.WARN
&& status
.getMessage()
.contains(
"Failed to init Sentry during appender initialization: DSN is "
+ "required. Use empty string to disable SDK.")) {
return true;
}

return false;
})
.count());
}

private String getLoggingContextHostnameProperty() {
final Logger accessPointLogger = (Logger) LoggerFactory.getLogger("logger");
final LoggerContext loggerContext = accessPointLogger.getLoggerContext();
Expand Down

0 comments on commit d3623db

Please sign in to comment.