Airbrake notifier for Java
Switch branches/tags
Clone or download
thompiler Merge pull request #31 from airbrake/update/stated-version
Update version number for notices and readme
Latest commit 2c33014 Jun 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper Upgrade gradlew Sep 11, 2017
src Update version number for notices and readme Jun 4, 2018
.gitignore Initial commit Aug 15, 2017
.travis.yml Initial commit Aug 15, 2017
LICENSE Add license Aug 24, 2017
README.md Update version number for notices and readme Jun 4, 2018
build.gradle v0.1.6 Apr 25, 2018
gradlew Initial commit Aug 15, 2017
gradlew.bat Initial commit Aug 15, 2017
pom.xml Update version number for notices and readme Jun 4, 2018
settings.gradle

README.md

Java notifier for Airbrake

Build Status

Installation

Gradle:

compile 'io.airbrake:javabrake:0.1.6'

Maven:

<dependency>
  <groupId>io.airbrake</groupId>
  <artifactId>javabrake</artifactId>
  <version>0.1.6</version>
</dependency>

Ivy:

<dependency org='io.airbrake' name='javabrake' rev='0.1.6'>
  <artifact name='javabrake' ext='pom'></artifact>
</dependency>

Quickstart

Configuration:

import io.airbrake.javabrake.Notifier;

int projectId = 12345;
String projectKey = "FIXME";
Notifier notifier = new Notifier(projectId, projectKey);

notifier.addFilter(
    (Notice notice) -> {
      notice.setContext("environment", "production");
      return notice;
    });

Using notifier directly:

try {
  do();
} catch (IOException e) {
  notifier.report(e);
}

Using Airbrake proxy class:

import io.airbrake.javabrake.Airbrake;

try {
  do();
} catch (IOException e) {
  Airbrake.report(e);
}

By default report sends errors asynchronously returning a Future, but synchronous API is also available:

import io.airbrake.javabrake.Notice;

Notice notice = Airbrake.reportSync(e);
if (notice.exception != null) {
    logger.info(notice.exception);
} else {
    logger.info(notice.id);
}

To set custom params you can build and send notice in separate steps:

import io.airbrake.javabrake.Notice;

Notice notice = Airbrake.buildNotice(e);
notice.setContext("component", "mycomponent");
notice.setParam("param1", "value1");
Airbrake.send(notice);

You can also set custom params on all reported notices:

notifier.addFilter(
    (Notice notice) -> {
      notice.setParam("myparam", "myvalue");
      return notice;
    });

Or ignore specific notice:

notifier.addFilter(
    (Notice notice) -> {
      if (notice.context.get("environment") == "development") {
          // Ignore notice.
          return null;
      }
      return notice;
    });

To debug why notices are not sent you can use onReportedNotice hook:

notifier.onReportedNotice(
    (notice) -> {
      if (notice.exception != null) {
        logger.info(notice.exception);
      } else {
        logger.info(String.format("notice id=%s url=%s", notice.id, notice.url));
      }
    });

log4j integration

See https://github.com/airbrake/log4javabrake

log4j2 integration

See https://github.com/airbrake/log4javabrake2

logback integration

See https://github.com/airbrake/logback

HTTP proxy

javabrake uses OkHttp as an HTTP client. So in order to use proxy all you have to do is to configure OkHttpClient:

import java.net.InetSocketAddress;

import okhttp3.OkHttpClient;
import okhttp3.Proxy;

import io.airbrake.javabrake.OkSender;

Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved("192.168.1.105", 8081);
OkHttpClient httpClient =
    new OkHttpClient.Builder()
        .connectTimeout(3000, TimeUnit.MILLISECONDS)
        .readTimeout(3000, TimeUnit.MILLISECONDS)
        .writeTimeout(3000, TimeUnit.MILLISECONDS)
        .proxy(proxy)
        .build();
OkSender.setOkHttpClient(httpClient);

Build

./gradlew build

Upload to JCentral:

./gradlew bintrayUpload

Upload to Maven Central:

./gradlew uploadArchives
./gradlew closeAndReleaseRepository

Usefull links: