Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support logging to Sentry #5881

Merged
merged 3 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
80 changes: 80 additions & 0 deletions docs/src/main/asciidoc/logging-sentry.adoc
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
----
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,3 @@
quarkus.log.sentry=true
quarkus.log.sentry.dsn=https://[email protected]/22222
quarkus.log.sentry.in-app-packages=*
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>
Loading