-
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.
Merge pull request #5881 from ia3andy/logging-sentry
Logging Sentry
- Loading branch information
Showing
17 changed files
with
507 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,80 @@ | ||
//// | ||
This guide is maintained in the main Quarkus repository | ||
and pull requests should be submitted there: | ||
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc | ||
//// | ||
= Quarkus - Configuring Sentry Logging | ||
|
||
include::./attributes.adoc[] | ||
|
||
This guide explains sentry logging and how to configure it. | ||
|
||
== Run Time Configuration | ||
|
||
Run time configuration of logging is done through the normal `application.properties` file. | ||
|
||
include::{generated-dir}/config/quarkus-logging-sentry.adoc[opts=optional, leveloffset=+1] | ||
|
||
== Description | ||
|
||
Sentry is a really easy way to be notified of errors happening on you Quarkus application. | ||
|
||
It is a Open Source, Self-hosted and cloud-based error monitoring that helps software teams discover, triage, and prioritize errors in real-time. | ||
|
||
They offer a free starter price for cloud-based or you can self host it for free. | ||
|
||
== Configuration | ||
|
||
To start of, you need to get a Sentry DSN either by https://sentry.io/signup/[creating a Sentry account] or https://docs.sentry.io/server/[installing your self-hosted Sentry]. | ||
|
||
In order to configure Sentry logging, the `quarkus-logging-sentry` extension should be employed. Add this extension to your | ||
application POM as the following snippet illustrates. | ||
|
||
.Modifications to POM file to add the Sentry logging extension | ||
[source,xml] | ||
---- | ||
<build> | ||
<dependencies> | ||
<!-- ... your other dependencies are here ... --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-logging-sentry</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</build> | ||
---- | ||
|
||
[id="in-app-packages"] | ||
=== “In Application” Stack Frames | ||
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 the stacktrace.app.packages option, which takes a comma separated list. | ||
[source, properties] | ||
---- | ||
quarkus.log.sentry.in-app-packages=com.mycompany,com.other.name | ||
---- | ||
If you don’t want to use this feature but want to disable the warning, simply set it to "*": | ||
|
||
[source, properties] | ||
---- | ||
quarkus.log.sentry.in-app-packages=* | ||
---- | ||
|
||
== Example | ||
|
||
.All errors and warnings occuring in any the packages will be sent to Sentry with DSN `https://[email protected]/1234` | ||
[source, properties] | ||
` | ||
quarkus.log.sentry=true | ||
quarkus.log.sentry.dsn=https://[email protected]/1234 | ||
quarkus.log.sentry.in-app-packages=* | ||
---- | ||
.All errors occuring in the package `org.example` will be sent to Sentry with DSN `https://[email protected]/1234` | ||
[source, properties] | ||
---- | ||
quarkus.log.sentry=true | ||
quarkus.log.sentry.dsn=https://[email protected]/1234 | ||
quarkus.log.sentry.level=ERROR | ||
quarkus.log.sentry.in-app-packages=org.example | ||
---- |
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 |
3 changes: 3 additions & 0 deletions
3
...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,3 @@ | ||
quarkus.log.sentry=true | ||
quarkus.log.sentry.dsn=https://[email protected]/22222 | ||
quarkus.log.sentry.in-app-packages=* |
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> |
Oops, something went wrong.