Setup Airbrake for your Java application
Opened this issue · 0 comments
noubarijou commented
Installation
Install option 1: Maven
Add the javabrake dependency through your IDE or directly to your pom.xml
file:
<dependency>
<groupId>io.airbrake</groupId>
<artifactId>javabrake</artifactId>
<version>0.2.4</version>
</dependency>
Install option 2: Gradle
Add javabrake to your Gradle dependencies:
compile 'io.airbrake:javabrake:0.2.4'
Install option 3: Ivy
Add javabrake to your Ivy dependencies:
<dependency org='io.airbrake' name='javabrake' rev='0.2.4'>
<artifact name='javabrake' ext='pom'></artifact>
</dependency>
Configuration
Import the Airbrake library, configure it, and then use it to report errors to Airbrake. Airbrake also integrates with libraries like log4j2 and logback.
(You can find your project ID and API key in your project's settings)
import io.airbrake.javabrake.Notifier;
import io.airbrake.javabrake.Config;
Config config = new Config();
config.projectId = <Your project ID>;
config.projectKey = "<Your project API KEY>";
Notifier notifier = new Notifier(config);
notifier.addFilter(
(Notice notice) -> {
notice.setContext("environment", "production");
return notice;
});
Example of reporting a caught exception using notifier
directly:
try {
do();
} catch (IOException e) {
notifier.report(e);
}
Example using the Airbrake
proxy class:
try {
do();
} catch (IOException e) {
Airbrake.report(e);
}
Full documentation
Visit our official GitHub repo for advanced information and integrations like log4j, log4j2, and logback.