Skip to content

Commit

Permalink
Logging Sentry
Browse files Browse the repository at this point in the history
Fixes #3985
  • Loading branch information
ia3andy committed Dec 3, 2019
1 parent d5eff14 commit 7ed9669
Show file tree
Hide file tree
Showing 16 changed files with 421 additions and 2 deletions.
5 changes: 5 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@
<artifactId>quarkus-logging-json-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-sentry-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
12 changes: 11 additions & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<mongo-reactivestreams-client.version>1.11.0</mongo-reactivestreams-client.version>
<artemis.version>2.10.1</artemis.version>
<okhttp.version>3.12.6</okhttp.version>
<sentry.version>1.7.28</sentry.version>
<!-- Used for integration tests, to make sure webjars work-->
<bootstrap.version>3.1.0</bootstrap.version>
<subethasmtp.version>3.1.7</subethasmtp.version>
Expand Down Expand Up @@ -710,6 +711,11 @@
<artifactId>quarkus-logging-json</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-sentry</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Quarkus test dependencies -->
<dependency>
Expand Down Expand Up @@ -1345,7 +1351,11 @@
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>

<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>${sentry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
65 changes: 65 additions & 0 deletions extensions/logging-sentry/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-sentry-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-logging-sentry-deployment</artifactId>
<name>Quarkus - Logging - Sentry - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-sentry</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.logging.sentry.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
import io.quarkus.logging.sentry.SentryConfig;
import io.quarkus.logging.sentry.SentryHandlerValueFactory;

class SentryProcessor {

private static final String FEATURE = "sentry";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
LogHandlerBuildItem addSentryLogHandler(final SentryConfig sentryConfig,
final SentryHandlerValueFactory sentryHandlerValueFactory) {
return new LogHandlerBuildItem(sentryHandlerValueFactory.create(sentryConfig));
}

@BuildStep
ExtensionSslNativeSupportBuildItem activateSslNativeSupport() {
return new ExtensionSslNativeSupportBuildItem(FEATURE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.quarkus.logging.sentry;

import static io.sentry.jvmti.ResetFrameCache.resetFrameCache;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.jboss.logmanager.handlers.DelayedHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.logging.InitialConfigurator;
import io.quarkus.test.QuarkusUnitTest;
import io.sentry.jul.SentryHandler;
import io.sentry.jvmti.FrameCache;

public class SentryLoggerCustomTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withConfigurationResource("application-sentry-logger-custom.properties");

@Test
public void sentryLoggerCustomTest() {
LogManager logManager = LogManager.getLogManager();
assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class);

DelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL);

Handler handler = Arrays.stream(delayedHandler.getHandlers())
.filter(h -> (h instanceof SentryHandler))
.findFirst().orElse(null);
SentryHandler sentryHandler = (SentryHandler) handler;
assertThat(sentryHandler).isNotNull();
assertThat(sentryHandler.getLevel()).isEqualTo(org.jboss.logmanager.Level.TRACE);
assertThat(FrameCache.shouldCacheThrowable(new IllegalStateException("Test frame"), 1)).isTrue();
}

@AfterAll
static void reset() {
resetFrameCache();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.quarkus.logging.sentry;

import static io.sentry.jvmti.ResetFrameCache.resetFrameCache;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.jboss.logmanager.handlers.DelayedHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.logging.InitialConfigurator;
import io.quarkus.test.QuarkusUnitTest;
import io.sentry.jul.SentryHandler;
import io.sentry.jvmti.FrameCache;

public class SentryLoggerTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withConfigurationResource("application-sentry-logger-default.properties");

@Test
public void sentryLoggerDefaultTest() {
LogManager logManager = LogManager.getLogManager();
assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class);

DelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL);

Handler handler = Arrays.stream(delayedHandler.getHandlers())
.filter(h -> (h instanceof SentryHandler))
.findFirst().orElse(null);
SentryHandler sentryHandler = (SentryHandler) handler;
assertThat(sentryHandler).isNotNull();
assertThat(sentryHandler.getLevel()).isEqualTo(org.jboss.logmanager.Level.WARN);
assertThat(FrameCache.shouldCacheThrowable(new IllegalStateException("Test frame"), 1)).isFalse();
}

@AfterAll
static void reset() {
resetFrameCache();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.sentry.jvmti;

public class ResetFrameCache {

public static void resetFrameCache() {
FrameCache.reset();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkus.log.sentry=true
quarkus.log.sentry.dsn=https://[email protected]/22222
quarkus.log.sentry.level=TRACE
quarkus.log.sentry.in-app-packages=io.quarkus.logging.sentry,org.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkus.log.sentry=true
quarkus.log.sentry.dsn=https://[email protected]/22222
21 changes: 21 additions & 0 deletions extensions/logging-sentry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
</parent>
<artifactId>quarkus-logging-sentry-parent</artifactId>
<name>Quarkus - Logging - Sentry</name>

<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
48 changes: 48 additions & 0 deletions extensions/logging-sentry/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-sentry-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-logging-sentry</artifactId>
<name>Quarkus - Logging - Sentry - Runtime</name>
<description>Self-hosted and cloud-based error monitoring that helps software teams discover, triage, and prioritize errors in real-time.</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.quarkus.logging.sentry;

import java.util.List;
import java.util.Optional;
import java.util.logging.Level;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

/**
* Configuration for Sentry logging.
*/
@ConfigRoot(phase = ConfigPhase.RUN_TIME, name = "log.sentry")
public class SentryConfig {

/**
* Determine whether to enable the Sentry logging extension.
*/
@ConfigItem(name = ConfigItem.PARENT)
boolean enable;

/**
* Sentry DSN
*
* The DSN is the first and most important thing to configure because it tells the SDK where to send events. You can find
* your project’s DSN in the “Client Keys” section of your “Project Settings” in Sentry.
*/
@ConfigItem
public String dsn;

/**
* The sentry log level.
*/
@ConfigItem(defaultValue = "WARN")
public Level level;

/**
* Sentry differentiates stack frames that are directly related to your application (“in application”) from stack frames
* that come from other packages such as the standard library, frameworks, or other dependencies. The difference is visible
* in the Sentry web interface where only the “in application” frames are displayed by default.
*
* You can configure which package prefixes your application uses with this option.
*
* This option is highly recommended as it affects stacktrace grouping and display on Sentry. See documentation:
* https://docs.sentry.io/clients/java/config/#in-application-stack-frames
*/
@ConfigItem
public Optional<List<String>> inAppPackages;
}
Loading

0 comments on commit 7ed9669

Please sign in to comment.