Skip to content

Commit 67b18e0

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

File tree

24 files changed

+743
-1
lines changed

24 files changed

+743
-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.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.sentry.SentryConfig;
10+
import io.quarkus.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.json;
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 io.sentry.jvmti.FrameCache;
12+
import org.jboss.logmanager.handlers.DelayedHandler;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.extension.RegisterExtension;
15+
16+
import io.quarkus.runtime.logging.InitialConfigurator;
17+
import io.quarkus.test.QuarkusUnitTest;
18+
import io.sentry.jul.SentryHandler;
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 sentryHandle = (SentryHandler) handler;
39+
assertThat(sentryHandle).isNotNull();
40+
assertThat(sentryHandle.getLevel()).isEqualTo(Level.SEVERE);
41+
assertThat(FrameCache.shouldCacheThrowable(new IllegalStateException("Test frame"), 1)).isTrue();
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
19+
public class SentryLoggerTest {
20+
21+
@RegisterExtension
22+
static final QuarkusUnitTest config = new QuarkusUnitTest()
23+
.withConfigurationResource("application-sentry-logger-default.properties");
24+
25+
@Test
26+
public void sentryLoggerDefaultTest() {
27+
LogManager logManager = LogManager.getLogManager();
28+
assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class);
29+
30+
DelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
31+
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
32+
assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL);
33+
34+
Handler handler = Arrays.stream(delayedHandler.getHandlers())
35+
.filter(h -> (h instanceof SentryHandler))
36+
.findFirst().orElse(null);
37+
SentryHandler sentryHandle = (SentryHandler) handler;
38+
assertThat(sentryHandle).isNotNull();
39+
assertThat(sentryHandle.getLevel()).isEqualTo(Level.WARNING);
40+
41+
}
42+
}
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
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings/
5+
bin/
6+
7+
# IntelliJ
8+
.idea
9+
*.ipr
10+
*.iml
11+
*.iws
12+
13+
# NetBeans
14+
nb-configuration.xml
15+
16+
# Visual Studio Code
17+
.vscode
18+
19+
# OSX
20+
.DS_Store
21+
22+
# Vim
23+
*.swp
24+
*.swo
25+
26+
# patch
27+
*.orig
28+
*.rej
29+
30+
# Maven
31+
target/
32+
pom.xml.tag
33+
pom.xml.releaseBackup
34+
pom.xml.versionsBackup
35+
release.properties
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.5";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

0 commit comments

Comments
 (0)