Raven is the Java client for Sentry. Raven relies on the most popular logging libraries to capture and convert logs before sending details to a Sentry instance.
java.util.loggingsupport is provided by the main project raven
- log4j support is provided in raven-log4j
- log4j2 can be used with raven-log4j2
- logback support is provided in raven-logback
While it's strongly recommended to use one of the supported logging frameworks to capture and send messages to Sentry, a it is possible to do so manually with the main project raven.
Raven supports both HTTP(S) and UDP as transport protocols to the Sentry instance.
Due to GetSentry.com using a certificate provided by StartCom and StartCom not being in the list of the CAcerts of Oracle JDK 6 it isn't possible to establish an HTTPS connection to GetSentry.com out of the box.
The said certificate might be available out of the box with Java 8 but in the mean time, you can use the raven-getsentry module which embeds the certificate and allows SSL connections to GetSentry.com
Since 2.0, the major version of raven matches the version of the Sentry protocol.
|Raven version||Protocol version||Sentry version|
|Raven 2.x||V2||>= 2.0|
|Raven 3.x||V3||>= 5.1|
|Raven 4.x||V4||>= 6.0|
|Raven 5.x(dev)||V5||>= 6.4|
Each release of Sentry supports the last two version of the protocol (i.e. Sentry 6.4.2 supports both the protocol V5 and V4), for this reason, only the two last stable versions of Raven are actively maintained.
While the stable versions of raven are available on the central Maven Repository, newer (but less stable) versions (AKA snapshots) are available in Sonatype's snapshot repository.
To use it with maven, add the following repository:
<repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository>
Raven works on Android, and relies on the
system which uses the content of
This is used to declare the
RavenFactory implementations (to allow more
control over the automatically generated instances of
Unfortunately, when the APK is build, the content of
the dependencies is lost, this prevent Raven to work properly.
Solutions exist for that problem:
- Use maven-android-plugin which has already solved this problem
- Create manually a
META-INF/services/net.kencochrane.raven.RavenFactoryfor the project which will contain the canonical name of of implementation of
Register manually the
RavenFactorywhen the application starts:
It is possible to send events to Sentry over different protocols, depending on the security and performance requirements. So far Sentry accepts HTTP(S) and UDP which are both fully supported by Raven.
The most common way send events to Sentry is through HTTP, this can be done by using a DSN of this form:
If not provided, the port will default to
It is possible to use an encrypted connection to Sentry using HTTPS:
If not provided, the port will default to
If the certificate used over HTTPS is a wildcard certificate (which is not handled by every version of Java), and the certificate isn't added to the truststore, it is possible to add a protocol setting to tell the client to be naive and ignore the hostname verification:
It is possible to use a DSN with the UDP protocol:
If not provided the port will default to
While being faster because there is no TCP and HTTP overhead, UDP doesn't wait for a reply, and if a connection problem occurs, there will be no notification.
It is possible to enable some options by adding data to the query string of the DSN:
Some options do not require a value, just being declared signifies that the option is enabled.
In order to avoid performance issues due to a large amount of logs being generated or a slow connection to the Sentry server, an asynchronous connection is set up, using a low priority thread pool to submit events to Sentry.
To disable the async mode, add
raven.async=false to the DSN:
The default queue used to store the not yet processed events doesn't have a limit. Depending on the environment (if the memory is sparse) it is important to be able to control the size of that queue to avoid memory issues.
It is possible to set a maximum with the option
This means that if the connection to the Sentry server is down, only the first 100 events will be stored and be processed as soon as the server is back up.
By default the thread pool used by the async connection contains one thread per processor available to the JVM (more threads wouldn't be useful).
It's possible to manually set the number of threads (for example if you want
only one thread) with the option
As in most cases sending logs to Sentry isn't as important as an application running smoothly, the threads have a minimal priority.
It is possible to customise this value to increase the priority of those threads
with the option
in_app stack frames (which are directly related to your application)
and the "not
This difference is visible in the Sentry web interface where only the
frames are displayed by default.
Raven can use the
in_app system to hide frames in the context of chained exceptions.
Usually when a StackTrace is printed, the result looks like this:
HighLevelException: MidLevelException: LowLevelException at Main.a(Main.java:13) at Main.main(Main.java:4) Caused by: MidLevelException: LowLevelException at Main.c(Main.java:23) at Main.b(Main.java:17) at Main.a(Main.java:11) ... 1 more Caused by: LowLevelException at Main.e(Main.java:30) at Main.d(Main.java:27) at Main.c(Main.java:21) ... 3 more
Some frames are replaced by the
... N more line as they are the same frames
as in the enclosing exception.
To enable a similar behaviour from raven use the
Raven can also mark some frames as
in_app based on the name of the class.
This can be used to hide parts of the stacktrace that are irrelevant to the problem
for example the stack frames in the
java.util package will not help determining
what the problem was and will just create a longer stacktrace.
Currently this is not configurable (see #49) and some packages are ignored by default:
By default the content sent to Sentry is compressed and encoded in base64 before being sent. This operation allows to send a smaller amount of data for each event. However compressing and encoding the data adds a CPU and memory overhead which might not be useful if the connection to Sentry is fast and reliable.
Depending on the limitations of the project (ie: a mobile application with a limited connection, Sentry hosted on an external network), it can be interesting to compress the data beforehand or not.
It's possible to manually enable/disable the compression with the option
To avoid blocking the thread because of a connection taking too much time, a timeout can be set by the connection.
By default the connection will set up its own timeout, but it's possible to
manually set one with
raven.timeout (in milliseconds):