Configuration options

All available options for configuring your integration with BugSnag.

addCallback

Adds a callback which will be invoked directly before the notifier sends the error to BugSnag. This callback has full read/write access to the error object, so it has the opportunity to cancel the error to prevent it being sent all together.

The callback does not get invoked if the Exception name has been set to ignored via setIgnoreClasses.

By calling report.cancel() in a callback, the BugSnag notifier will prevent sending the error to the BugSnag. The first callback to call cancel() will prevent all other subsequent callbacks from being invoked.

bugsnag.addCallback((report) -> {
    // Sets the groupingHash option
    report.setGroupingHash("hello");

    // Overrides the severity
    report.setSeverity(Severity.WARNING);

    // Adds some metadata
    report.addToTab("State", "memory", 12345);

    // Prevent the report from being sent
    report.cancel();
});

Or without using the Java 8 lambda syntax:

bugsnag.addCallback(new Callback() {
    @Override
    public void beforeNotify(Report report) {
        // Sets the groupingHash option
        report.setGroupingHash("hello");

        // Overrides the severity
        report.setSeverity(Severity.WARNING);

        // Adds some metadata
        report.addToTab("State", "memory", 12345);

        // Prevent the report from being sent
        report.cancel();
    }
});

setAppType

Set the type of the application, for example spring, gradleTask.

bugsnag.setAppType("gradleTask");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<appType>gradleTask</appType>

setAppVersion

Set your application’s version to be able to see which version each error was introduced in, or seen in.

bugsnag.setAppVersion("1.0.0");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<appVersion>1.0.0</appVersion>

setAutoCaptureSessions

BugSnag will automatically capture and report session information for each HTTP request which uses the Java Servlet API, including Spring MVC requests.

If the notify endpoint is changed and the sessions endpoint is not, this option will be set to false and session tracking will be disabled.

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();

setDelivery

By default we’ll send reports asynchronously using a thread pool but 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
    }
});

To send reports synchronously you can use SyncHttpDelivery:

bugsnag.setDelivery(new SyncHttpDelivery());

setEndpoints

By default we will send error reports to notify.bugsnag.com and sessions to sessions.bugsnag.com.

If you are using BugSnag On-premise 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("https://notify.example.com", "https://sessions.example.com");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<endpoint>https://notify.example.com</endpoint>

setFilters

Sets the strings to filter out from the maps before sending them to BugSnag. Use this if you want to ensure you don’t send sensitive data such as passwords, and credit card numbers to our servers. Any keys which contain these strings will be filtered and displayed in the dashboard as key - [FILTERED].

bugsnag.setFilters("password", "credit_card_number");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<filteredProperty>password</filteredProperty>
<filteredProperty>credit_card_number</filteredProperty>

or

<filteredProperties>password,credit_card_number</filteredProperties>

By default, filters is set to "password"

setIgnoreClasses

Sets for which exception classes we should not send exceptions to BugSnag.

bugsnag.setIgnoreClasses("java.io.IOException", "com.example.Custom");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<ignoredClass>java.io.IOException</ignoredClass>
<ignoredClass>com.example.Custom</ignoredClass>

or

<ignoredClasses>java.io.IOException,com.example.Custom</ignoredClasses>

setNotifyReleaseStages

By default, we will notify BugSnag of exceptions that happen in any releaseStage. If you would like to change which release stages notify BugSnag of exceptions you can call setNotifyReleaseStages. Also see setReleaseStage.

bugsnag.setNotifyReleaseStages("production", "development");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<notifyReleaseStage>production</notifyReleaseStage>
<notifyReleaseStage>development</notifyReleaseStage>

or

<notifyReleaseStages>production,development</notifyReleaseStages>

setProjectPackages

Sets which package names BugSnag should consider as “in project”. We mark stacktrace lines as in-project if they originate from any of these packages.

bugsnag.setProjectPackages("com.company.package1", "com.company.package2");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<projectPackage>com.company.package1</projectPackage>
<projectPackage>com.company.package2</projectPackage>

or

<projectPackages>com.company.package1,com.company.package2</projectPackages>

setProxy

Sets the proxy to use when sending errors to BugSnag.

bugsnag.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("example.com", 80));

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<proxy>
    <type>HTTP</type>
    <hostname>example.com</hostname>
    <port>80</port>
</proxy>

setReleaseStage

To distinguish between errors that happen in different stages of the application release process (development, production, etc) you can set the releaseStage that is reported to BugSnag. Also see setNotifyReleaseStages.

bugsnag.setReleaseStage("development");

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<releaseStage>development</releaseStage>

Defaults to production.

setSessionDelivery

By default BugSnag will send sessions asynchronously using a thread pool but 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());

setSendThreads

Sets if we should collect and send thread state along with errors.

bugsnag.setSendThreads(true);

If you are using the logback appender then add the following into the <appender> section of your logback.xml file:

<sendThreads>true</sendThreads>

By default sendThreads is set to false.