Quarkus Logging Sentry
This guide explains how to configure Quarkus to log to Sentry.
Description
Sentry is a really easy way to be notified of errors happening in your Quarkus application.
It is a 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.
Sentry’s Java SDK is open source, but recently sentry.io changed the license for their backend to the non-open source BSL license. This might or might not be an issue for your project and product. |
Configuration
To start with, you need to get a Sentry DSN either by creating a Sentry account or installing your own self-hosted Sentry.
In order to configure Sentry logging, add the logging-sentry
extension
to your project by running the following command in your project base directory:
./mvnw quarkus:add-extension -Dextensions="logging-sentry"
This will add the following to your pom.xml
:
<dependency>
<groupId>io.quarkiverse.loggingsentry</groupId>
<artifactId>quarkus-logging-sentry</artifactId>
<version>2.0.7</version>
</dependency>
“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 in-app-packages
option, which takes a comma separated list of packages:
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 *
:
quarkus.log.sentry.in-app-packages=*
Example
https://abcd@sentry.io/1234
quarkus.log.sentry=true
quarkus.log.sentry.dsn=https://abcd@sentry.io/1234
quarkus.log.sentry.in-app-packages=*
org.example
will be sent to Sentry with DSN https://abcd@sentry.io/1234
quarkus.log.sentry=true
quarkus.log.sentry.dsn=https://abcd@sentry.io/1234
quarkus.log.sentry.level=ERROR
quarkus.log.sentry.in-app-packages=org.example
BeforeSend callbacks
Sentry events can be customised before transmission using Sentry’s builtin BeforeSendCallback
interface.
Any application-scoped bean marked with the interface will be called. This can be used to add data to the event as well as completely suppressing the event.
Make sure to mark beans as unremovable.
@ApplicationScoped
@Unremovable
public class SentryCallbackHandler implements SentryOptions.BeforeSendCallback {
@Override
public SentryEvent execute(SentryEvent sentryEvent, Hint hint) {
return sentryEvent; // event unchanged
}
}
Configuration Reference
This extension is configured through the standard application.properties
file.
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
Determine whether to enable the Sentry logging extension. Environment variable: |
boolean |
|
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. Environment variable: |
string |
|
The sentry log level. Environment variable: |
|
|
The minimum event level. Every log statement that is greater than minimum event level is turned into Sentry event. Environment variable: |
|
|
The minimum breadcrumb level. Every log statement that is greater than minimum breadcrumb level is added to Sentry scope as a breadcrumb, which can be later attached to SentryEvent if one is triggered. Environment variable: |
|
|
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://quarkus.io/guides/logging-sentry#in-app-packages Environment variable: |
list of string |
|
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. You can configure which package prefixes you want to exclude from logging. Environment variable: |
list of string |
|
You can use this option to set exceptions that will be filtered out before sending to Sentry by adding the names of the exception.(e.g. java.lang.RuntimeException) Environment variable: |
list of string |
|
Environment With Sentry you can easily filter issues, releases, and user feedback by environment. The environment filter on sentry affects all issue-related metrics like count of users affected, times series graphs, and event count. By setting the environment option, an environment tag will be added to each new issue sent to Sentry. There are a few restrictions: → the environment name cannot contain newlines or spaces, cannot be the string “None” or exceed 64 characters. Environment variable: |
string |
|
Release A release is a version of your code that is deployed to an environment. When you give Sentry information about your releases, you unlock a number of new features: - Determine the issues and regressions introduced in a new release - Predict which commit caused an issue and who is likely responsible - Resolve issues by including the issue number in your commit message - Receive email notifications when your code gets deployed Environment variable: |
string |
|
Server name Sets the server name that will be sent with each event. Environment variable: |
string |
|
Debug Enables Sentry debug mode. Environment variable: |
boolean |
|
This should be a float/double between 0.0 and 1.0 (inclusive) and represents the percentage chance that any given transaction will be sent to Sentry. So, barring outside influence, 0.0 is a 0% chance (none will be sent) and 1.0 is a 100% chance (all will be sent). This rate applies equally to all transactions. Environment variable: |
double |
|
Context Tags Specifics the MDC tags that are used as Sentry tags Environment variable: |
list of string |
|
Static tags Static tags that are sent to Sentry with every event. Environment variable: |
Map<String,String> |
|
Determine whether to enable a Proxy for all Sentry outbound requests. This is also used for HTTPS requests. Environment variable: |
boolean |
|
Sets the host name of the proxy server. Environment variable: |
string |
|
Sets the port number of the proxy server Environment variable: |
int |
|
Sets the username to authenticate on the proxy server Environment variable: |
string |
|
Sets the password to authenticate on the proxy server Environment variable: |
string |