
airbrake.AirbrakeNoticeBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of airbrake-java Show documentation
Show all versions of airbrake-java Show documentation
This is the official library to notify exception to Airbrake.io
// Modified or written by Luca Marrocco for inclusion with airbrake.
// Copyright (c) 2009 Luca Marrocco.
// Licensed under the Apache License, Version 2.0 (the "License")
package airbrake;
import static java.util.Arrays.*;
import java.util.*;
import java.util.Map.Entry;
public class AirbrakeNoticeBuilder {
private String apiKey;
private String projectRoot;
private String environmentName;
private String errorMessage;
private Backtrace backtrace = new Backtrace(asList("backtrace is empty"));
private final Map environment = new TreeMap();
private Map request = new TreeMap();
private Map session = new TreeMap();
private final List environmentFilters = new LinkedList();
private Backtrace backtraceBuilder = new Backtrace();
private String errorClass;
private boolean hasRequest = false;
private String url;
private String component;
public AirbrakeNoticeBuilder(final String apiKey, final Backtrace backtraceBuilder, final Throwable throwable, final String env) {
this(apiKey, throwable.getMessage(), env);
this.backtraceBuilder = backtraceBuilder;
errorClass(throwable);
backtrace(throwable);
}
public AirbrakeNoticeBuilder(final String apiKey, final String errorMessage) {
this(apiKey, errorMessage, "test");
}
public AirbrakeNoticeBuilder(final String apiKey, final String errorMessage, final String env) {
apiKey(apiKey);
errorMessage(errorMessage);
env(env);
}
public AirbrakeNoticeBuilder(final String apiKey, final Throwable throwable) {
this(apiKey, new Backtrace(), throwable, "test");
}
public AirbrakeNoticeBuilder(final String apiKey, final Throwable throwable, final String env) {
this(apiKey, new Backtrace(), throwable, env);
}
public AirbrakeNoticeBuilder(final String apiKey, final Throwable throwable, final String projectRoot, final String env) {
this(apiKey, new Backtrace(), throwable, env);
projectRoot(projectRoot);
}
protected void addSessionKey(String key, Object value) {
session.put(key, value);
}
private void apiKey(final String apiKey) {
if (notDefined(apiKey)) {
error("The API key for the project this error is from (required). Get this from the project's page in airbrake.");
}
this.apiKey = apiKey;
}
/**
* An array where each element is a line of the backtrace (required, but can
* be empty).
*/
protected void backtrace(final Backtrace backtrace) {
this.backtrace = backtrace;
}
private void backtrace(final Throwable throwable) {
backtrace(backtraceBuilder.newBacktrace(throwable));
}
protected void ec2EnvironmentFilters() {
environmentFilter("AWS_SECRET");
environmentFilter("EC2_PRIVATE_KEY");
environmentFilter("AWS_ACCESS");
environmentFilter("EC2_CERT");
}
private void env(final String env) {
environmentName = env;
}
/**
* A hash of the environment data that existed when the error occurred
* (required, but can be empty).
*/
protected void environment(final Map environment) {
this.environment.putAll(environment);
}
protected void environment(Properties properties) {
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy