Skip to content

Commit c887a5d

Browse files
committed
Logging Sentry
Fixes #3985
1 parent 195f934 commit c887a5d

File tree

14 files changed

+399
-1
lines changed

14 files changed

+399
-1
lines changed

bom/runtime/pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<mongo-reactivestreams-client.version>1.11.0</mongo-reactivestreams-client.version>
154154
<artemis.version>2.10.1</artemis.version>
155155
<okhttp.version>3.12.6</okhttp.version>
156+
<sentry.version>1.7.28</sentry.version>
156157
<!-- Used for integration tests, to make sure webjars work-->
157158
<bootstrap.version>3.1.0</bootstrap.version>
158159
<subethasmtp.version>3.1.7</subethasmtp.version>
@@ -710,6 +711,11 @@
710711
<artifactId>quarkus-logging-json</artifactId>
711712
<version>${project.version}</version>
712713
</dependency>
714+
<dependency>
715+
<groupId>io.quarkus</groupId>
716+
<artifactId>quarkus-logging-sentry</artifactId>
717+
<version>${project.version}</version>
718+
</dependency>
713719

714720
<!-- Quarkus test dependencies -->
715721
<dependency>
@@ -1335,7 +1341,11 @@
13351341
<artifactId>okhttp</artifactId>
13361342
<version>${okhttp.version}</version>
13371343
</dependency>
1338-
1344+
<dependency>
1345+
<groupId>io.sentry</groupId>
1346+
<artifactId>sentry</artifactId>
1347+
<version>${sentry.version}</version>
1348+
</dependency>
13391349
<dependency>
13401350
<groupId>org.apache.maven.plugin-tools</groupId>
13411351
<artifactId>maven-plugin-annotations</artifactId>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.quarkus</groupId>
8+
<artifactId>quarkus-logging-sentry-parent</artifactId>
9+
<version>999-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>quarkus-logging-sentry-deployment</artifactId>
14+
<name>Quarkus - Logging - Sentry - Deployment</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.quarkus</groupId>
19+
<artifactId>quarkus-core-deployment</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>io.quarkus</groupId>
23+
<artifactId>quarkus-logging-sentry</artifactId>
24+
</dependency>
25+
<!-- test dependencies -->
26+
<dependency>
27+
<groupId>io.quarkus</groupId>
28+
<artifactId>quarkus-junit5-internal</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.quarkus</groupId>
33+
<artifactId>quarkus-junit5</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.assertj</groupId>
38+
<artifactId>assertj-core</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.quarkus</groupId>
43+
<artifactId>quarkus-arc-deployment</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<configuration>
54+
<annotationProcessorPaths>
55+
<path>
56+
<groupId>io.quarkus</groupId>
57+
<artifactId>quarkus-extension-processor</artifactId>
58+
<version>${quarkus.version}</version>
59+
</path>
60+
</annotationProcessorPaths>
61+
</configuration>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.quarkus.logging.sentry.deployment;
2+
3+
import io.quarkus.deployment.annotations.BuildStep;
4+
import io.quarkus.deployment.annotations.ExecutionTime;
5+
import io.quarkus.deployment.annotations.Record;
6+
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
7+
import io.quarkus.deployment.builditem.FeatureBuildItem;
8+
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
9+
import io.quarkus.logging.sentry.SentryConfig;
10+
import io.quarkus.logging.sentry.SentryHandlerValueFactory;
11+
12+
class SentryProcessor {
13+
14+
private static final String FEATURE = "sentry";
15+
16+
@BuildStep
17+
FeatureBuildItem feature() {
18+
return new FeatureBuildItem(FEATURE);
19+
}
20+
21+
@BuildStep
22+
@Record(ExecutionTime.RUNTIME_INIT)
23+
LogHandlerBuildItem addSentryLogHandler(final SentryConfig sentryConfig,
24+
final SentryHandlerValueFactory sentryHandlerValueFactory) {
25+
return new LogHandlerBuildItem(sentryHandlerValueFactory.create(sentryConfig));
26+
}
27+
28+
@BuildStep
29+
ExtensionSslNativeSupportBuildItem activateSslNativeSupport() {
30+
return new ExtensionSslNativeSupportBuildItem(FEATURE);
31+
}
32+
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.quarkus.logging.sentry;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.Arrays;
6+
import java.util.logging.Handler;
7+
import java.util.logging.Level;
8+
import java.util.logging.LogManager;
9+
import java.util.logging.Logger;
10+
11+
import org.jboss.logmanager.handlers.DelayedHandler;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.extension.RegisterExtension;
14+
15+
import io.quarkus.runtime.logging.InitialConfigurator;
16+
import io.quarkus.test.QuarkusUnitTest;
17+
import io.sentry.jul.SentryHandler;
18+
import io.sentry.jvmti.FrameCache;
19+
20+
public class SentryLoggerCustomTest {
21+
22+
@RegisterExtension
23+
static final QuarkusUnitTest config = new QuarkusUnitTest()
24+
.withConfigurationResource("application-sentry-logger-custom.properties");
25+
26+
@Test
27+
public void sentryLoggerCustomTest() {
28+
LogManager logManager = LogManager.getLogManager();
29+
assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class);
30+
31+
DelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
32+
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
33+
assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL);
34+
35+
Handler handler = Arrays.stream(delayedHandler.getHandlers())
36+
.filter(h -> (h instanceof SentryHandler))
37+
.findFirst().orElse(null);
38+
SentryHandler sentryHandler = (SentryHandler) handler;
39+
assertThat(sentryHandler).isNotNull();
40+
assertThat(sentryHandler.getLevel()).isEqualTo(org.jboss.logmanager.Level.TRACE);
41+
assertThat(FrameCache.shouldCacheThrowable(new IllegalStateException("Test frame"), 1)).isTrue();
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.quarkus.logging.sentry;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.Arrays;
6+
import java.util.logging.Handler;
7+
import java.util.logging.Level;
8+
import java.util.logging.LogManager;
9+
import java.util.logging.Logger;
10+
11+
import org.jboss.logmanager.handlers.DelayedHandler;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.extension.RegisterExtension;
14+
15+
import io.quarkus.runtime.logging.InitialConfigurator;
16+
import io.quarkus.test.QuarkusUnitTest;
17+
import io.sentry.jul.SentryHandler;
18+
import io.sentry.jvmti.FrameCache;
19+
20+
public class SentryLoggerTest {
21+
22+
@RegisterExtension
23+
static final QuarkusUnitTest config = new QuarkusUnitTest()
24+
.withConfigurationResource("application-sentry-logger-default.properties");
25+
26+
@Test
27+
public void sentryLoggerDefaultTest() {
28+
LogManager logManager = LogManager.getLogManager();
29+
assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class);
30+
31+
DelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
32+
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
33+
assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL);
34+
35+
Handler handler = Arrays.stream(delayedHandler.getHandlers())
36+
.filter(h -> (h instanceof SentryHandler))
37+
.findFirst().orElse(null);
38+
SentryHandler sentryHandler = (SentryHandler) handler;
39+
assertThat(sentryHandler).isNotNull();
40+
assertThat(sentryHandler.getLevel()).isEqualTo(org.jboss.logmanager.Level.WARN);
41+
assertThat(FrameCache.shouldCacheThrowable(new IllegalStateException("Test frame"), 1)).isFalse();
42+
}
43+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
quarkus.sentry.dsn=https://[email protected]/22222
2+
quarkus.sentry.level=TRACE
3+
quarkus.sentry.in-app-packages=io.quarkus.logging.sentry,org.test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quarkus.sentry.dsn=https://[email protected]/22222

extensions/logging-sentry/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<artifactId>quarkus-build-parent</artifactId>
8+
<groupId>io.quarkus</groupId>
9+
<version>999-SNAPSHOT</version>
10+
<relativePath>../../build-parent/pom.xml</relativePath>
11+
</parent>
12+
<artifactId>quarkus-logging-sentry-parent</artifactId>
13+
<name>Quarkus - Logging - Sentry</name>
14+
15+
<packaging>pom</packaging>
16+
17+
<properties>
18+
<quarkus.version>999-SNAPSHOT</quarkus.version>
19+
<sentry.version>1.7.5</sentry.version>
20+
</properties>
21+
22+
<modules>
23+
<module>deployment</module>
24+
<module>runtime</module>
25+
</modules>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>io.quarkus</groupId>
31+
<artifactId>quarkus-maven-plugin</artifactId>
32+
<version>${quarkus.version}</version>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.quarkus</groupId>
8+
<artifactId>quarkus-logging-sentry-parent</artifactId>
9+
<version>999-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>quarkus-logging-sentry</artifactId>
14+
<name>Quarkus - Logging - Sentry - Runtime</name>
15+
<description>Self-hosted and cloud-based error monitoring that helps software teams discover, triage, and prioritize errors in real-time.</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>io.quarkus</groupId>
20+
<artifactId>quarkus-core</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>io.sentry</groupId>
24+
<artifactId>sentry</artifactId>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>io.quarkus</groupId>
32+
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
33+
<version>${quarkus.version}</version>
34+
<executions>
35+
<execution>
36+
<goals>
37+
<goal>extension-descriptor</goal>
38+
</goals>
39+
<phase>compile</phase>
40+
<configuration>
41+
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
42+
</deployment>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-compiler-plugin</artifactId>
49+
<configuration>
50+
<annotationProcessorPaths>
51+
<path>
52+
<groupId>io.quarkus</groupId>
53+
<artifactId>quarkus-extension-processor</artifactId>
54+
<version>${quarkus.version}</version>
55+
</path>
56+
</annotationProcessorPaths>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.quarkus.logging.sentry;
2+
3+
import java.util.Optional;
4+
import java.util.logging.Level;
5+
6+
import io.quarkus.runtime.annotations.ConfigItem;
7+
import io.quarkus.runtime.annotations.ConfigPhase;
8+
import io.quarkus.runtime.annotations.ConfigRoot;
9+
10+
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
11+
public class SentryConfig {
12+
13+
/**
14+
* Sentry DSN
15+
*
16+
* The DSN is the first and most important thing to configure because it tells the SDK where to send events. You can find
17+
* your project’s DSN in the “Client Keys” section of your “Project Settings” in Sentry.
18+
*/
19+
@ConfigItem
20+
public String dsn;
21+
22+
/**
23+
* The sentry log level.
24+
*/
25+
@ConfigItem(defaultValue = "WARN")
26+
public Level level;
27+
28+
/**
29+
* Sentry differentiates stack frames that are directly related to your application (“in application”) from stack frames
30+
* that come from other packages such as the standard library, frameworks, or other dependencies. The difference is visible
31+
* in the Sentry web interface where only the “in application” frames are displayed by default.
32+
*
33+
* You can configure which package prefixes your application uses with this option, which takes a comma separated list.
34+
*
35+
* This option is highly recommended as it affects stacktrace grouping and display on Sentry. See documentation:
36+
* https://docs.sentry.io/clients/java/config/#in-application-stack-frames
37+
*/
38+
@ConfigItem
39+
public Optional<String> inAppPackages;
40+
}

0 commit comments

Comments
 (0)