Skip to content

Commit

Permalink
[server] add sentry log collect (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilou242 authored Jan 22, 2024
1 parent 7540260 commit 52646db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@
<artifactId>sentry</artifactId>
<version>${sentry.version}</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>${sentry.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
4 changes: 4 additions & 0 deletions thirdeye-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import ai.startree.thirdeye.service.ResourcesBootstrapService;
import ai.startree.thirdeye.spi.json.ThirdEyeSerialization;
import ai.startree.thirdeye.worker.task.TaskDriver;
import ch.qos.logback.classic.Level;
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.dropwizard.Application;
Expand All @@ -58,6 +59,7 @@
import io.sentry.Hint;
import io.sentry.Sentry;
import io.sentry.SentryLevel;
import io.sentry.logback.SentryAppender;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
Expand All @@ -75,7 +77,7 @@

public class ThirdEyeServer extends Application<ThirdEyeServerConfiguration> {

private static final Logger log = LoggerFactory.getLogger(ThirdEyeServer.class);
private static Logger log = LoggerFactory.getLogger(ThirdEyeServer.class);
private static final String SENTRY_MAIN_THREAD_HINT_KEY = "IS_MAIN_THREAD_ERROR";

private Injector injector;
Expand Down Expand Up @@ -287,6 +289,16 @@ private void initSentry(final BackendSentryConfiguration config, final JerseyEnv
});
// intercept exceptions caught by dropwizard/jersey
jersey.register(new ExceptionSentryLogger());

// enable sentry log collect - see https://docs.sentry.io/platforms/java/guides/logback/
final SentryAppender appender = new SentryAppender();
appender.setMinimumEventLevel(Level.ERROR);
appender.setMinimumBreadcrumbLevel(Level.DEBUG);
appender.start();
final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(appender);
// re-instantiate the logger of this class now that the Sentry appender has been injected
log = LoggerFactory.getLogger(ThirdEyeServer.class);
log.info("Sentry.io collect is enabled.");
} else {
log.info("Sentry.io collect is not enabled.");
Expand Down

0 comments on commit 52646db

Please sign in to comment.