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

Setup Airbrake for your Java application #1

Open
HDZ12 opened this issue Mar 10, 2024 · 0 comments
Open

Setup Airbrake for your Java application #1

HDZ12 opened this issue Mar 10, 2024 · 0 comments
Labels

Comments

@HDZ12
Copy link
Owner

HDZ12 commented Mar 10, 2024

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.3.0</version>
</dependency>

Install option 2: Gradle

Add javabrake to your Gradle dependencies:

compile 'io.airbrake:javabrake:0.3.0'

Install option 3: Ivy

Add javabrake to your Ivy dependencies:

<dependency org='io.airbrake' name='javabrake' rev='0.3.0'>
  <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.

@HDZ12 HDZ12 added the airbrake label Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant