-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #3985
- Loading branch information
Showing
16 changed files
with
421 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
33 changes: 33 additions & 0 deletions
33
...sentry/deployment/src/main/java/io/quarkus/logging/sentry/deployment/SentryProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...ing-sentry/deployment/src/test/java/io/quarkus/logging/sentry/SentryLoggerCustomTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...s/logging-sentry/deployment/src/test/java/io/quarkus/logging/sentry/SentryLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
extensions/logging-sentry/deployment/src/test/java/io/sentry/jvmti/ResetFrameCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../logging-sentry/deployment/src/test/resources/application-sentry-logger-custom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
...logging-sentry/deployment/src/test/resources/application-sentry-logger-default.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
50 changes: 50 additions & 0 deletions
50
extensions/logging-sentry/runtime/src/main/java/io/quarkus/logging/sentry/SentryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.