Package 

Class Bugsnag


  • 
    public final class Bugsnag
    
                        

    Static access to a Bugsnag Client, the easiest way to use Bugsnag in your Android app. For example:

    {@code * Bugsnag.start(this, "your-api-key"); * Bugsnag.notify(new RuntimeException("something broke!")); * }
    • Method Detail

      • start

        @NonNull() static Client start(@NonNull() Context androidContext)

        Initialize the static Bugsnag client

        Parameters:
        androidContext - an Android context, usually this
      • start

        @NonNull() static Client start(@NonNull() Context androidContext, @NonNull() String apiKey)

        Initialize the static Bugsnag client

        Parameters:
        androidContext - an Android context, usually this
        apiKey - your Bugsnag API key from your Bugsnag dashboard
      • isStarted

         static boolean isStarted()

        Returns true if one of the start methods have been has been called andso Bugsnag is initialized; false if start has not been called and theother methods will throw {@code IllegalStateException}.

      • getContext

        @Nullable() static String getContext()

        Bugsnag uses the concept of "contexts" to help display and group your errors. Contextsrepresent what was happening in your application at the time an error occurs.

        In an android app the "context" is automatically set as the foreground Activity.If you would like to set this value manually, you should alter this property.

      • setContext

         static void setContext(@Nullable() String context)

        Bugsnag uses the concept of "contexts" to help display and group your errors. Contextsrepresent what was happening in your application at the time an error occurs.

        In an android app the "context" is automatically set as the foreground Activity.If you would like to set this value manually, you should alter this property.

      • setGroupingDiscriminator

        @Nullable() static String setGroupingDiscriminator(@Nullable() String groupingDiscriminator)

        Set the Grouping Discriminator and return its previous value (if any was set).

        Parameters:
        groupingDiscriminator - the new grouping discriminator or null to clear it
      • addOnError

         static void addOnError(@NonNull() OnErrorCallback onError)

        Add a "on error" callback, to execute code at the point where an error report iscaptured in Bugsnag.

        You can use this to add or modify information attached to an Eventbefore it is sent to your dashboard. You can also returnfalse from any callback to prevent delivery. "on error"callbacks do not run before reports generated in the eventof immediate app termination from crashes in C/C++ code.

        For example:

        {@code * Bugsnag.addOnError((Event event) -> { * event.setSeverity(Severity.INFO); * return true; * }); * }
        Parameters:
        onError - a callback to run before sending errors to Bugsnag
      • addOnBreadcrumb

         static void addOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)

        Add an "on breadcrumb" callback, to execute code before everybreadcrumb captured by Bugsnag.

        You can use this to modify breadcrumbs before they are stored by Bugsnag.You can also return false from any callback to ignore a breadcrumb.

        For example:

        {@code * Bugsnag.onBreadcrumb((Breadcrumb breadcrumb) -> { * return false; // ignore the breadcrumb * }); * }
        Parameters:
        onBreadcrumb - a callback to run before a breadcrumb is captured
      • addOnSession

         static void addOnSession(@NonNull() OnSessionCallback onSession)

        Add an "on session" callback, to execute code before everysession captured by Bugsnag.

        You can use this to modify sessions before they are stored by Bugsnag.You can also return false from any callback to ignore a session.

        For example:

        {@code * Bugsnag.onSession((Session session) -> { * return false; // ignore the session * }); * }
        Parameters:
        onSession - a callback to run before a session is captured
      • notify

         static void notify(@NonNull() Throwable exception)

        Notify Bugsnag of a handled exception

        Parameters:
        exception - the exception to send to Bugsnag
      • notify

         static void notify(@NonNull() Throwable exception, @Nullable() OnErrorCallback onError)

        Notify Bugsnag of a handled exception

        Parameters:
        exception - the exception to send to Bugsnag
        onError - callback invoked on the generated error report foradditional modification
      • notify

         static void notify(@NonNull() Throwable exception, @Nullable() ErrorOptions options, @Nullable() OnErrorCallback onError)

        Notify Bugsnag of a handled exception

        Parameters:
        exception - the exception to send to Bugsnag
        options - additional options to adjust the reporting of the exception
        onError - callback invoked on the generated error report foradditional modification
      • addMetadata

         static void addMetadata(@NonNull() String section, @NonNull() String key, @Nullable() Object value)

        Adds the specified key and value in the specified section. The value can be ofany primitive type or a collection such as a map, set or array.

      • leaveBreadcrumb

         static void leaveBreadcrumb(@NonNull() String message)

        Leave a "breadcrumb" log message, representing an action that occurredin your app, to aid with debugging.

        Parameters:
        message - the log message to leave
      • leaveBreadcrumb

         static void leaveBreadcrumb(@NonNull() String message, @Nullable() Map<String, Object> metadata, @NonNull() BreadcrumbType type)

        Leave a "breadcrumb" log message representing an action or event whichoccurred in your app, to aid with debugging

        Parameters:
        message - A short label
        metadata - Additional diagnostic information about the app environment
        type - A category for the breadcrumb
      • startSession

         static void startSession()

        Starts tracking a new session. You should disable automatic session tracking via setAutoTrackSessions if you call this method.

        You should call this at the appropriate time in your application when you wish to start asession. Any subsequent errors which occur in your application will still be reported toBugsnag but will not count towards your application'sstability score. This will start a new session even if there is already an existingsession; you should call resumeSession if you only want to start a sessionwhen one doesn't already exist.
      • resumeSession

         static boolean resumeSession()

        Resumes a session which has previously been paused, or starts a new session if none exists.If a session has already been resumed or started and has not been paused, calling thismethod will have no effect. You should disable automatic session tracking via setAutoTrackSessions if you call this method.

        It's important to note that sessions are stored in memory for the lifetime of theapplication process and are not persisted on disk. Therefore calling this method on appstartup would start a new session, rather than continuing any previous session.You should call this at the appropriate time in your application when you wish to resumea previously started session. Any subsequent errors which occur in your application willstill be reported to Bugsnag but will not count towards your application'sstability score.
      • pauseSession

         static void pauseSession()

        Pauses tracking of a session. You should disable automatic session tracking via setAutoTrackSessions if you call this method.

        You should call this at the appropriate time in your application when you wish to pause asession. Any subsequent errors which occur in your application will still be reported toBugsnag but will not count towards your application'sstability score. This can be advantageous if, for example, you do not wish thestability score to include crashes in a background service.
      • getBreadcrumbs

        @NonNull() static List<Breadcrumb> getBreadcrumbs()

        Returns the current buffer of breadcrumbs that will be sent with captured events. Thisordered list represents the most recent breadcrumbs to be captured up to the limitset in getMaxBreadcrumbs.

        The returned collection is readonly and mutating the list will cause no effect on theClient's state. If you wish to alter the breadcrumbs collected by the Client then you shoulduse setEnabledBreadcrumbTypes and addOnBreadcrumb instead.

      • getLastRunInfo

        @Nullable() static LastRunInfo getLastRunInfo()

        Retrieves information about the last launch of the application, if it has been run before.

        For example, this allows checking whether the app crashed on its last launch, which couldbe used to perform conditional behaviour to recover from crashes, such as clearing theapp data cache.

      • markLaunchCompleted

         static void markLaunchCompleted()

        Informs Bugsnag that the application has finished launching. Once this has been called isLaunching will always be false in any new error reports,and synchronous delivery will not be attempted on the next launch for any fatal crashes.

        By default this method will be called after Bugsnag is initialized when getLaunchDurationMillis has elapsed. Invoking this method manuallyhas precedence over the value supplied via the launchDurationMillis configuration option.

      • addFeatureFlag

         static void addFeatureFlag(@NonNull() String name)

        Add a single feature flag with no variant. If there is an existing feature flag with thesame name, it will be overwritten to have no variant.

        Parameters:
        name - the name of the feature flag to add
      • addFeatureFlag

         static void addFeatureFlag(@NonNull() String name, @Nullable() String variant)

        Add a single feature flag with an optional variant. If there is an existing featureflag with the same name, it will be overwritten with the new variant. If the variant is {@code null} this method has the same behaviour as addFeatureFlag.

        Parameters:
        name - the name of the feature flag to add
        variant - the variant to set the feature flag to, or {@code null} to specify a featureflag with no variant
      • addFeatureFlags

         static void addFeatureFlags(@NonNull() Iterable<FeatureFlag> featureFlags)

        Add a collection of feature flags. This method behaves exactly the same as calling addFeatureFlag for each of the {@code FeatureFlag} objects.

        Parameters:
        featureFlags - the feature flags to add
      • clearFeatureFlag

         static void clearFeatureFlag(@NonNull() String name)

        Remove a single feature flag regardless of its current status. This will stop the specifiedfeature flag from being reported. If the named feature flag does not exist this willhave no effect.

        Parameters:
        name - the name of the feature flag to remove
      • clearFeatureFlags

         static void clearFeatureFlags()

        Clear all of the feature flags. This will stop all feature flags from being reported.