Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,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://examplePublicKey@o0.ingest.sentry.io/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