Package com.bugsnag

Class Bugsnag

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Bugsnag
    extends java.lang.Object
    implements java.io.Closeable
    • Constructor Summary

      Constructors 
      Constructor Description
      Bugsnag​(java.lang.String apiKey)
      Initialize a Bugsnag client and automatically send uncaught exceptions.
      Bugsnag​(java.lang.String apiKey, boolean sendUncaughtExceptions)
      Initialize a Bugsnag client.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addCallback​(Callback callback)
      Add a callback to execute code before/after every notification to Bugsnag.
      static void addThreadMetaData​(java.lang.String tabName, java.lang.String key, java.lang.Object value)
      Add a key value pair to a metadata tab just for this thread.
      Report buildReport​(java.lang.Throwable throwable)
      Build an Report object to send to Bugsnag.
      static void clearThreadMetaData()
      Clears all metadata added to the current thread
      static void clearThreadMetaData​(java.lang.String tabName)
      Clears all metadata added to a given tab on the current thread
      static void clearThreadMetaData​(java.lang.String tabName, java.lang.String key)
      Clears a metadata key/value pair from a tab on the current thread
      void close()
      Close the connection to Bugsnag and unlink the exception handler.
      Delivery getDelivery()
      Get the delivery to use to send reports.
      Delivery getSessionDelivery()
      Get the delivery to use to send sessions.
      boolean notify​(Report report)
      Notify Bugsnag of an exception and provide custom diagnostic data for this particular error report.
      boolean notify​(Report report, Callback reportCallback)
      Notify Bugsnag of an exception and provide custom diagnostic data for this particular error report.
      boolean notify​(java.lang.Throwable throwable)
      Notify Bugsnag of a handled exception.
      boolean notify​(java.lang.Throwable throwable, Callback callback)
      Notify Bugsnag of a handled exception.
      boolean notify​(java.lang.Throwable throwable, Severity severity)
      Notify Bugsnag of a handled exception - with a severity.
      boolean notify​(java.lang.Throwable throwable, Severity severity, Callback callback)
      Notify Bugsnag of a handled exception.
      void setAppType​(java.lang.String appType)
      Set the application type sent to Bugsnag.
      void setAppVersion​(java.lang.String appVersion)
      Set the application version sent to Bugsnag.
      void setAutoCaptureSessions​(boolean autoCaptureSessions)
      Sets whether or not Bugsnag should automatically capture and report User sessions for each request.
      void setDelivery​(Delivery delivery)
      Set the method of delivery for Bugsnag error report.
      void setEndpoint​(java.lang.String endpoint)
      void setEndpoints​(java.lang.String notify, java.lang.String sessions)
      Set the endpoints to send data to.
      void setFilters​(java.lang.String... filters)
      Set which keys should be filtered when sending metaData to Bugsnag.
      void setIgnoreClasses​(java.lang.String... ignoreClasses)
      Set which exception classes should be ignored (not sent) by Bugsnag.
      void setNotifyReleaseStages​(java.lang.String... notifyReleaseStages)
      Set for which releaseStages errors should be sent to Bugsnag.
      void setProjectPackages​(java.lang.String... projectPackages)
      Set which packages should be considered part of your application.
      void setProxy​(java.net.Proxy proxy)
      Set a proxy to use when delivering Bugsnag error reports and sessions.
      void setReleaseStage​(java.lang.String releaseStage)
      Set the current "release stage" of your application.
      void setSendThreads​(boolean sendThreads)
      Set whether Bugsnag should capture and report thread-state for all running threads.
      void setSessionDelivery​(Delivery delivery)
      Set the method of delivery for Bugsnag sessions.
      void setSessionEndpoint​(java.lang.String endpoint)
      void setTimeout​(int timeout)
      Set a timeout (in ms) to use when delivering Bugsnag error reports and sessions.
      boolean shouldAutoCaptureSessions()
      Retrieves whether or not Bugsnag should automatically capture and report User sessions for each request.
      void startSession()
      Manually starts tracking a new session.
      static java.util.Set<Bugsnag> uncaughtExceptionClients()
      Retrieves all instances of Bugsnag which are registered to catch uncaught exceptions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Bugsnag

        public Bugsnag​(java.lang.String apiKey)
        Initialize a Bugsnag client and automatically send uncaught exceptions.
        Parameters:
        apiKey - your Bugsnag API key from your Bugsnag dashboard
      • Bugsnag

        public Bugsnag​(java.lang.String apiKey,
                       boolean sendUncaughtExceptions)
        Initialize a Bugsnag client.
        Parameters:
        apiKey - your Bugsnag API key
        sendUncaughtExceptions - should we send uncaught exceptions to Bugsnag
    • Method Detail

      • addCallback

        public void addCallback​(Callback callback)
        Add a callback to execute code before/after every notification to Bugsnag.

        You can use this to add or modify information attached to an error before it is sent to your dashboard. You can also stop any reports being sent to Bugsnag completely.

        Parameters:
        callback - a callback to run before sending errors to Bugsnag
        See Also:
        Callback
      • getDelivery

        public Delivery getDelivery()
        Get the delivery to use to send reports.
        Returns:
        the delivery to use to send reports.
        See Also:
        Delivery
      • getSessionDelivery

        public Delivery getSessionDelivery()
        Get the delivery to use to send sessions.
        Returns:
        the delivery to use to send sessions.
        See Also:
        Delivery
      • setAppType

        public void setAppType​(java.lang.String appType)
        Set the application type sent to Bugsnag.
        Parameters:
        appType - the app type to send, eg. spring, gradleTask
      • setAppVersion

        public void setAppVersion​(java.lang.String appVersion)
        Set the application version sent to Bugsnag.
        Parameters:
        appVersion - the app version to send
      • setDelivery

        public void setDelivery​(Delivery delivery)
        Set the method of delivery for Bugsnag error report. By default we'll send reports asynchronously using a thread pool to https://notify.bugsnag.com, but you can override this to use a different sending technique or endpoint (for example, if you are using Bugsnag On-Premise).
        Parameters:
        delivery - the delivery mechanism to use
        See Also:
        Delivery
      • setSessionDelivery

        public void setSessionDelivery​(Delivery delivery)
        Set the method of delivery for Bugsnag sessions. By default we'll send sessions asynchronously using a thread pool to https://sessions.bugsnag.com, but you can override this to use a different sending technique or endpoint (for example, if you are using Bugsnag On-Premise).
        Parameters:
        delivery - the delivery mechanism to use
        See Also:
        Delivery
      • setFilters

        public void setFilters​(java.lang.String... filters)
        Set which keys should be filtered when sending metaData to Bugsnag. Use this when you want to ensure sensitive information, such as passwords or credit card information is stripped from metaData you send to Bugsnag. Any keys in metaData which contain these strings will be marked as [FILTERED] when send to Bugsnag.
        Parameters:
        filters - a list of String keys to filter from metaData
      • setIgnoreClasses

        public void setIgnoreClasses​(java.lang.String... ignoreClasses)
        Set which exception classes should be ignored (not sent) by Bugsnag.
        Parameters:
        ignoreClasses - a list of exception classes to ignore
      • setNotifyReleaseStages

        public void setNotifyReleaseStages​(java.lang.String... notifyReleaseStages)
        Set for which releaseStages errors should be sent to Bugsnag. Use this to stop errors from development builds being sent.
        Parameters:
        notifyReleaseStages - a list of releaseStages to notify for
        See Also:
        setReleaseStage(java.lang.String)
      • setProjectPackages

        public void setProjectPackages​(java.lang.String... projectPackages)
        Set which packages should be considered part of your application. Bugsnag uses this to help with error grouping, and stacktrace display.
        Parameters:
        projectPackages - a list of package names
      • setProxy

        public void setProxy​(java.net.Proxy proxy)
        Set a proxy to use when delivering Bugsnag error reports and sessions. This is a convenient shorthand for bugsnag.getDelivery().setProxy();
        Parameters:
        proxy - the proxy to use to send reports
      • setReleaseStage

        public void setReleaseStage​(java.lang.String releaseStage)
        Set the current "release stage" of your application.
        Parameters:
        releaseStage - the release stage of the app
        See Also:
        setNotifyReleaseStages(java.lang.String...)
      • setSendThreads

        public void setSendThreads​(boolean sendThreads)
        Set whether Bugsnag should capture and report thread-state for all running threads. This is often not useful for Java web apps, since there could be thousands of active threads depending on your environment.
        Parameters:
        sendThreads - should we send thread state with error reports
        See Also:
        setNotifyReleaseStages(java.lang.String...)
      • setTimeout

        public void setTimeout​(int timeout)
        Set a timeout (in ms) to use when delivering Bugsnag error reports and sessions. This is a convenient shorthand for bugsnag.getDelivery().setTimeout();
        Parameters:
        timeout - the timeout to set (in ms)
        See Also:
        setDelivery(com.bugsnag.delivery.Delivery)
      • buildReport

        public Report buildReport​(java.lang.Throwable throwable)
        Build an Report object to send to Bugsnag.
        Parameters:
        throwable - the exception to send to Bugsnag
        Returns:
        the report object
        See Also:
        Report, notify(com.bugsnag.Report)
      • notify

        public boolean notify​(java.lang.Throwable throwable)
        Notify Bugsnag of a handled exception.
        Parameters:
        throwable - the exception to send to Bugsnag
        Returns:
        true unless the error report was ignored
      • notify

        public boolean notify​(java.lang.Throwable throwable,
                              Callback callback)
        Notify Bugsnag of a handled exception.
        Parameters:
        throwable - the exception to send to Bugsnag
        callback - the Callback object to run for this Report
        Returns:
        true unless the error report was ignored
      • notify

        public boolean notify​(java.lang.Throwable throwable,
                              Severity severity)
        Notify Bugsnag of a handled exception - with a severity.
        Parameters:
        throwable - the exception to send to Bugsnag
        severity - the severity of the error, one of {#link Severity#ERROR}, Severity.WARNING or Severity.INFO
        Returns:
        true unless the error report was ignored
      • notify

        public boolean notify​(java.lang.Throwable throwable,
                              Severity severity,
                              Callback callback)
        Notify Bugsnag of a handled exception.
        Parameters:
        throwable - the exception to send to Bugsnag
        severity - the severity of the error, one of {#link Severity#ERROR}, Severity.WARNING or Severity.INFO
        callback - the Callback object to run for this Report
        Returns:
        true unless the error report was ignored
      • notify

        public boolean notify​(Report report)
        Notify Bugsnag of an exception and provide custom diagnostic data for this particular error report.
        Parameters:
        report - the Report object to send to Bugsnag
        Returns:
        true unless the error report was ignored
        See Also:
        Report, buildReport(java.lang.Throwable)
      • notify

        public boolean notify​(Report report,
                              Callback reportCallback)
        Notify Bugsnag of an exception and provide custom diagnostic data for this particular error report.
        Parameters:
        report - the Report object to send to Bugsnag
        reportCallback - the Callback object to run for this Report
        Returns:
        false if the error report was ignored
        See Also:
        Report, buildReport(java.lang.Throwable)
      • startSession

        public void startSession()
        Manually starts tracking a new session. Note: sessions are currently tracked on a per-thread basis. Therefore, if this method were called from Thread A then Thread B, two sessions would be considered 'active'. Any custom strategy used to track sessions should take this into account. Automatic session tracking can be enabled via setAutoCaptureSessions(boolean), which will automatically create a new session for each request
      • setAutoCaptureSessions

        public void setAutoCaptureSessions​(boolean autoCaptureSessions)
        Sets whether or not Bugsnag should automatically capture and report User sessions for each request.

        By default this behavior is disabled.

        Parameters:
        autoCaptureSessions - whether sessions should be captured automatically
      • shouldAutoCaptureSessions

        public boolean shouldAutoCaptureSessions()
        Retrieves whether or not Bugsnag should automatically capture and report User sessions for each request.
        Returns:
        whether sessions should be auto captured
      • setEndpoints

        public void setEndpoints​(java.lang.String notify,
                                 java.lang.String sessions)
                          throws java.lang.IllegalArgumentException
        Set the endpoints to send data to. By default we'll send error reports to https://notify.bugsnag.com, and sessions to https://sessions.bugsnag.com, but you can override this if you are using Bugsnag Enterprise to point to your own Bugsnag endpoint. Please note that it is recommended that you set both endpoints. If the notify endpoint is missing, an exception will be thrown. If the session endpoint is missing, a warning will be logged and sessions will not be sent automatically. Note that if you are setting a custom Delivery, this method should be called after the custom implementation has been set.
        Parameters:
        notify - the notify endpoint
        sessions - the sessions endpoint
        Throws:
        java.lang.IllegalArgumentException - if the notify endpoint is empty or null
      • close

        public void close()
        Close the connection to Bugsnag and unlink the exception handler.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • addThreadMetaData

        public static void addThreadMetaData​(java.lang.String tabName,
                                             java.lang.String key,
                                             java.lang.Object value)
        Add a key value pair to a metadata tab just for this thread.
        Parameters:
        tabName - the name of the tab to add the key value pair to
        key - the key of the metadata to add
        value - the metadata value to add
      • clearThreadMetaData

        public static void clearThreadMetaData()
        Clears all metadata added to the current thread
      • clearThreadMetaData

        public static void clearThreadMetaData​(java.lang.String tabName)
        Clears all metadata added to a given tab on the current thread
        Parameters:
        tabName - the name of the tab to remove
      • clearThreadMetaData

        public static void clearThreadMetaData​(java.lang.String tabName,
                                               java.lang.String key)
        Clears a metadata key/value pair from a tab on the current thread
        Parameters:
        tabName - the name of the tab to that the metadata is in
        key - the key of the metadata to remove
      • uncaughtExceptionClients

        public static java.util.Set<Bugsnag> uncaughtExceptionClients()
        Retrieves all instances of Bugsnag which are registered to catch uncaught exceptions.
        Returns:
        clients which catch uncaught exceptions