The Bugsnag client object has many configuration options that can be set to customize the content of events and sessions and how they are sent.
Configuration options can be set directly on the Bugsnag client after initialization:
Bugsnag bugsnag = new Bugsnag("your-api-key-here");
bugsnag.setAppVersion("1.0.0-alpha");
bugsnag.setReleaseStage("development");
If you are using the logback appender, configuration options can also be specified in your logback.xml file.
Declare a single feature flag or experiment with variant as an optional second parameter.
bugsnag.addFeatureFlag("Checkout button color", "Blue");
bugsnag.addFeatureFlag("New checkout flow");
See the Feature flags & experiments section for more information.
Declare multiple feature flags or experiments.
bugsnag.addFeatureFlags(Arrays.asList(
new FeatureFlag("Checkout button color", "Blue"),
new FeatureFlag("another example", "experiment 2"),
new FeatureFlag("New checkout flow")
));
Add callbacks to modify or discard error events before they are sent — see Customizing error reports for more information.
bugsnag.addOnError((event) -> {
event.addMetadata("account", "name", "Acme Co.");
event.addMetadata("account", "paying_customer", true);
return true;
});
If your app’s codebase contains different entry-points/processes, but reports to a single BugSnag project, you might want to add information denoting the type of process the error came from.
This information can be used in the dashboard to filter errors and to determine whether an error is limited to a subset of appTypes.
bugsnag.setAppType("gradleTask");
<appType>gradleTask</appType>
The version of the application. This is really useful for finding out when errors are introduced and fixed. Additionally closed errors are re-opened if a later version of the app has a regression.
bugsnag.setAppVersion("1.0.0");
<appVersion>1.0.0</appVersion>
By default, BugSnag will automatically detect and report unhandled exceptions using a Thread.UncaughtExceptionHandler. To disable this behavior, pass false as the second argument to the Bugsnag constructor:
Bugsnag bugsnag = new Bugsnag("your-api-key-here", false);
By default, session information from your application will be automatically captured. Use this flag to disable all automatic reporting.
BugSnag will automatically capture and report session information for each HTTP request which uses the Java Servlet API, including Spring MVC requests.
To disable automatic session capturing:
bugsnag.setAutoCaptureSessions(false);
If you want control over what is deemed a session, you can switch off automatic session tracking with the setAutoCaptureSessions option, and call startSession() when appropriate for your application.
bugsnag.startSession();
Remove a single feature flag or experiment.
bugsnag.clearFeatureFlag("Checkout button color");
Remove all feature flags and experiments.
bugsnag.clearFeatureFlags();
The Delivery implementation used to make network calls to the Error Reporting and Sessions API.
This may be useful if you have requirements such as certificate pinning and rotation, which are not supported by the default implementation.
By default BugSnag will send reports asynchronously using a thread pool. A different delivery mechanism can be provided by implementing the Delivery interface.
bugsnag.setDelivery(new Delivery() {
@Override
public void deliver(Serializer serializer,
Object object,
Map<String, String> headers) {
// Implement deliver to send reports
}
@Override
public void close() {
// Clean up any resources
}
});
To send reports synchronously you can use SyncHttpDelivery:
bugsnag.setDelivery(new SyncHttpDelivery());
Allows you to specify which events should be automatically discarded based on their errorClass.
The library performs a regex pattern match against the fully-qualified exception class name.
bugsnag.setDiscardClasses(
Pattern.compile("java.io.IOException", Pattern.LITERAL),
Pattern.compile("com\\.example\\.ignored.*")
);
<discardClasses>java.io.IOException,com.example.Custom</discardClasses>
By default, events that happen in any releaseStage will be sent. Set this option if you would like to change which release stages notify BugSnag.
bugsnag.setEnabledReleaseStages("production", "development");
<enabledReleaseStages>production,development</enabledReleaseStages>
By default we will send error reports to the address of our hosted notify and sessions endpoints.
If you are using On-premise services you’ll need to set these to your Event Server
and Session Server endpoints. If the notify endpoint is set but the sessions endpoint is not, session tracking
will be disabled automatically to avoid leaking session information outside of your server configuration, and a warning will be logged.
bugsnag.setEndpoints(new EndpointConfiguration("https://notify.example.com", "https://sessions.example.com"));
<endpoint>https://notify.example.com</endpoint>
Sets which package names BugSnag should consider as a part of the running application. We mark stacktrace lines as in-project if they originate from any of these packages and this allows us to improve the visual display of the stacktrace on the dashboard.
bugsnag.setProjectPackages("com.company.package1", "com.company.package2");
<projectPackages>com.company.package1,com.company.package2</projectPackages>
Sets the proxy to use when sending errors and sessions to BugSnag.
bugsnag.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("example.com", 80)));
<proxy>
<type>HTTP</type>
<hostname>example.com</hostname>
<port>80</port>
</proxy>
Sets which values should be removed from any metadata before an event is sent. Use this if you want to ensure you don’t transmit sensitive data such as passwords and credit card numbers.
Any property whose key matches a redacted key will be filtered and replaced with [REDACTED]. By default, any key that contains “password” will be redacted. Be aware that if you set this configuration option, it will replace the default, so you may want to replace “password” in your own set if you want to filter that.
bugsnag.setRedactedKeys("password", "credit_card_number", "authorization");
<redactedKeys>password,credit_card_number,authorization</redactedKeys>
By default, redactedKeys is set to ["password", "secret", "Authorization", "Cookie"].
Allows you to distinguish between errors that happen in different stages of the application release process (development, production, etc).
bugsnag.setReleaseStage("development");
<releaseStage>development</releaseStage>
Controls whether we should capture and serialize the state of all threads at the time of an exception.
bugsnag.setSendThreads(ThreadSendPolicy.ALWAYS);
<sendThreads>true</sendThreads>
By default sendThreads is set to ThreadSendPolicy.NEVER.
By default BugSnag will send sessions asynchronously using a thread pool. A different delivery mechanism can be provided by implementing the Delivery interface.
bugsnag.setSessionDelivery(new Delivery() {
@Override
public void deliver(Serializer serializer,
Object object,
Map<String, String> headers) {
// Implement deliver to send sessions
}
});
To send sessions synchronously you can use SyncHttpDelivery:
bugsnag.setSessionDelivery(new SyncHttpDelivery());
Sets a timeout (in milliseconds) to use when delivering BugSnag error reports and sessions. This is a convenient shorthand for setting the timeout on both the error delivery and session delivery mechanisms.
bugsnag.setTimeout(5000); // 5 seconds
<timeout>5000</timeout>
This method only works if you are using the default HttpDelivery or AsyncHttpDelivery delivery mechanisms. If you have set a custom Delivery, you will need to configure the timeout on your custom implementation.