Package io.sentry

Interface IHub

  • All Known Implementing Classes:
    Hub, HubAdapter, NoOpHub

    public interface IHub
    SDK API contract which combines a client and scope management
    • Method Detail

      • isEnabled

        boolean isEnabled()
        Check if the Hub is enabled/active.
        Returns:
        true if its enabled or false otherwise.
      • captureEvent

        @NotNull
        @NotNull SentryId captureEvent​(@NotNull
                                       @NotNull SentryEvent event,
                                       @Nullable
                                       @Nullable java.lang.Object hint)
        Captures the event.
        Parameters:
        event - the event
        hint - SDK specific but provides high level information about the origin of the event
        Returns:
        The Id (SentryId object) of the event
      • captureEvent

        @NotNull
        default @NotNull SentryId captureEvent​(@NotNull
                                               @NotNull SentryEvent event)
        Captures the event.
        Parameters:
        event - the event
        Returns:
        The Id (SentryId object) of the event
      • captureMessage

        @NotNull
        default @NotNull SentryId captureMessage​(@NotNull
                                                 @NotNull java.lang.String message)
        Captures the message.
        Parameters:
        message - The message to send.
        Returns:
        The Id (SentryId object) of the event
      • captureMessage

        @NotNull
        @NotNull SentryId captureMessage​(@NotNull
                                         @NotNull java.lang.String message,
                                         @NotNull
                                         @NotNull SentryLevel level)
        Captures the message.
        Parameters:
        message - The message to send.
        level - The message level.
        Returns:
        The Id (SentryId object) of the event
      • captureEnvelope

        @NotNull
        @NotNull SentryId captureEnvelope​(@NotNull
                                          @NotNull SentryEnvelope envelope,
                                          @Nullable
                                          @Nullable java.lang.Object hint)
        Captures an envelope.
        Parameters:
        envelope - the SentryEnvelope to send.
        hint - SDK specific but provides high level information about the origin of the event
        Returns:
        The Id (SentryId object) of the event
      • captureEnvelope

        @NotNull
        default @NotNull SentryId captureEnvelope​(@NotNull
                                                  @NotNull SentryEnvelope envelope)
        Captures an envelope.
        Parameters:
        envelope - the SentryEnvelope to send.
        Returns:
        The Id (SentryId object) of the event
      • captureException

        @NotNull
        @NotNull SentryId captureException​(@NotNull
                                           @NotNull java.lang.Throwable throwable,
                                           @Nullable
                                           @Nullable java.lang.Object hint)
        Captures the exception.
        Parameters:
        throwable - The exception.
        hint - SDK specific but provides high level information about the origin of the event
        Returns:
        The Id (SentryId object) of the event
      • captureException

        @NotNull
        default @NotNull SentryId captureException​(@NotNull
                                                   @NotNull java.lang.Throwable throwable)
        Captures the exception.
        Parameters:
        throwable - The exception.
        Returns:
        The Id (SentryId object) of the event
      • captureUserFeedback

        void captureUserFeedback​(@NotNull
                                 @NotNull UserFeedback userFeedback)
        Captures a manually created user feedback and sends it to Sentry.
        Parameters:
        userFeedback - The user feedback to send to Sentry.
      • startSession

        void startSession()
        Starts a new session. If there's a running session, it ends it before starting the new one.
      • endSession

        void endSession()
        Ends the current session
      • close

        void close()
        Flushes out the queue for up to timeout seconds and disable the Hub.
      • addBreadcrumb

        void addBreadcrumb​(@NotNull
                           @NotNull Breadcrumb breadcrumb,
                           @Nullable
                           @Nullable java.lang.Object hint)
        Adds a breadcrumb to the current Scope
        Parameters:
        breadcrumb - the breadcrumb
        hint - SDK specific but provides high level information about the origin of the event
      • addBreadcrumb

        default void addBreadcrumb​(@NotNull
                                   @NotNull Breadcrumb breadcrumb)
        Adds a breadcrumb to the current Scope
        Parameters:
        breadcrumb - the breadcrumb
      • addBreadcrumb

        default void addBreadcrumb​(@NotNull
                                   @NotNull java.lang.String message)
        Adds a breadcrumb to the current Scope
        Parameters:
        message - rendered as text and the whitespace is preserved.
      • addBreadcrumb

        default void addBreadcrumb​(@NotNull
                                   @NotNull java.lang.String message,
                                   @NotNull
                                   @NotNull java.lang.String category)
        Adds a breadcrumb to the current Scope
        Parameters:
        message - rendered as text and the whitespace is preserved.
        category - Categories are dotted strings that indicate what the crumb is or where it comes from.
      • setLevel

        void setLevel​(@Nullable
                      @Nullable SentryLevel level)
        Sets the level of all events sent within current Scope
        Parameters:
        level - the Sentry level
      • setTransaction

        void setTransaction​(@Nullable
                            @Nullable java.lang.String transaction)
        Sets the name of the current transaction to the current Scope.
        Parameters:
        transaction - the transaction
      • setUser

        void setUser​(@Nullable
                     @Nullable User user)
        Shallow merges user configuration (email, username, etc) to the current Scope.
        Parameters:
        user - the user
      • setFingerprint

        void setFingerprint​(@NotNull
                            @NotNull java.util.List<java.lang.String> fingerprint)
        Sets the fingerprint to group specific events together to the current Scope.
        Parameters:
        fingerprint - the fingerprints
      • clearBreadcrumbs

        void clearBreadcrumbs()
        Deletes current breadcrumbs from the current scope.
      • setTag

        void setTag​(@NotNull
                    @NotNull java.lang.String key,
                    @NotNull
                    @NotNull java.lang.String value)
        Sets the tag to a string value to the current Scope, overwriting a potential previous value
        Parameters:
        key - the key
        value - the value
      • removeTag

        void removeTag​(@NotNull
                       @NotNull java.lang.String key)
        Removes the tag to a string value to the current Scope
        Parameters:
        key - the key
      • setExtra

        void setExtra​(@NotNull
                      @NotNull java.lang.String key,
                      @NotNull
                      @NotNull java.lang.String value)
        Sets the extra key to an arbitrary value to the current Scope, overwriting a potential previous value
        Parameters:
        key - the key
        value - the value
      • removeExtra

        void removeExtra​(@NotNull
                         @NotNull java.lang.String key)
        Removes the extra key to an arbitrary value to the current Scope
        Parameters:
        key - the key
      • getLastEventId

        @NotNull
        @NotNull SentryId getLastEventId()
        Last event id recorded in the current scope
        Returns:
        last SentryId
      • pushScope

        void pushScope()
        Pushes a new scope while inheriting the current scope's data.
      • popScope

        void popScope()
        Removes the first scope
      • withScope

        void withScope​(@NotNull
                       @NotNull ScopeCallback callback)
        Runs the callback with a new scope which gets dropped at the end
        Parameters:
        callback - the callback
      • configureScope

        void configureScope​(@NotNull
                            @NotNull ScopeCallback callback)
        Configures the scope through the callback.
        Parameters:
        callback - The configure scope callback.
      • bindClient

        void bindClient​(@NotNull
                        @NotNull ISentryClient client)
        Binds a different client to the hub
        Parameters:
        client - the client.
      • flush

        void flush​(long timeoutMillis)
        Flushes events queued up, but keeps the Hub enabled. Not implemented yet.
        Parameters:
        timeoutMillis - time in milliseconds
      • clone

        @NotNull
        @NotNull IHub clone()
        Clones the Hub
        Returns:
        the cloned Hub
      • captureTransaction

        @Internal
        @NotNull
        @NotNull SentryId captureTransaction​(@NotNull
                                             @NotNull SentryTransaction transaction,
                                             @Nullable
                                             @Nullable TraceState traceState,
                                             @Nullable
                                             @Nullable java.lang.Object hint)
        Captures the transaction and enqueues it for sending to Sentry server.
        Parameters:
        transaction - the transaction
        traceState - the trace state
        hint - the hint
        Returns:
        transaction's id
      • captureTransaction

        @Internal
        @NotNull
        default @NotNull SentryId captureTransaction​(@NotNull
                                                     @NotNull SentryTransaction transaction,
                                                     @Nullable
                                                     @Nullable java.lang.Object hint)
      • captureTransaction

        @Internal
        @NotNull
        default @NotNull SentryId captureTransaction​(@NotNull
                                                     @NotNull SentryTransaction transaction,
                                                     @Nullable
                                                     @Nullable TraceState traceState)
        Captures the transaction and enqueues it for sending to Sentry server.
        Parameters:
        transaction - the transaction
        traceState - the trace state
        Returns:
        transaction's id
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull TransactionContext transactionContexts)
        Creates a Transaction and returns the instance.
        Parameters:
        transactionContexts - the transaction contexts
        Returns:
        created transaction
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull TransactionContext transactionContexts,
                                                       boolean bindToScope)
        Creates a Transaction and returns the instance.
        Parameters:
        transactionContexts - the transaction contexts
        bindToScope - if transaction should be bound to scope
        Returns:
        created transaction
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull java.lang.String name,
                                                       @NotNull
                                                       @NotNull java.lang.String operation,
                                                       @Nullable
                                                       @Nullable CustomSamplingContext customSamplingContext)
        Creates a Transaction and returns the instance. Based on the passed sampling context the decision if transaction is sampled will be taken by TracesSampler.
        Parameters:
        name - the transaction name
        operation - the operation
        customSamplingContext - the sampling context
        Returns:
        created transaction.
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull java.lang.String name,
                                                       @NotNull
                                                       @NotNull java.lang.String operation,
                                                       @Nullable
                                                       @Nullable CustomSamplingContext customSamplingContext,
                                                       boolean bindToScope)
        Creates a Transaction and returns the instance. Based on the passed sampling context the decision if transaction is sampled will be taken by TracesSampler.
        Parameters:
        name - the transaction name
        operation - the operation
        customSamplingContext - the sampling context
        bindToScope - if transaction should be bound to scope
        Returns:
        created transaction.
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull TransactionContext transactionContexts,
                                                       @Nullable
                                                       @Nullable CustomSamplingContext customSamplingContext)
        Creates a Transaction and returns the instance. Based on the passed transaction and sampling contexts the decision if transaction is sampled will be taken by TracesSampler.
        Parameters:
        transactionContexts - the transaction context
        customSamplingContext - the sampling context
        Returns:
        created transaction.
      • startTransaction

        @NotNull
        @NotNull ITransaction startTransaction​(@NotNull
                                               @NotNull TransactionContext transactionContexts,
                                               @Nullable
                                               @Nullable CustomSamplingContext customSamplingContext,
                                               boolean bindToScope)
        Creates a Transaction and returns the instance. Based on the passed transaction and sampling contexts the decision if transaction is sampled will be taken by TracesSampler.
        Parameters:
        transactionContexts - the transaction context
        customSamplingContext - the sampling context
        bindToScope - if transaction should be bound to scope
        Returns:
        created transaction.
      • startTransaction

        @Internal
        @NotNull
        @NotNull ITransaction startTransaction​(@NotNull
                                               @NotNull TransactionContext transactionContexts,
                                               @Nullable
                                               @Nullable CustomSamplingContext customSamplingContext,
                                               boolean bindToScope,
                                               @Nullable
                                               @Nullable java.util.Date startTimestamp)
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull java.lang.String name,
                                                       @NotNull
                                                       @NotNull java.lang.String operation)
        Creates a Transaction and returns the instance. Based on the SentryOptions.getTracesSampleRate() the decision if transaction is sampled will be taken by TracesSampler.
        Parameters:
        name - the transaction name
        operation - the operation
        Returns:
        created transaction
      • startTransaction

        @Internal
        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull java.lang.String name,
                                                       @NotNull
                                                       @NotNull java.lang.String operation,
                                                       @Nullable
                                                       @Nullable java.util.Date startTimestamp,
                                                       boolean waitForChildren,
                                                       @Nullable
                                                       @Nullable TransactionFinishedCallback transactionFinishedCallback)
      • startTransaction

        @NotNull
        default @NotNull ITransaction startTransaction​(@NotNull
                                                       @NotNull java.lang.String name,
                                                       @NotNull
                                                       @NotNull java.lang.String operation,
                                                       boolean bindToScope)
        Creates a Transaction and returns the instance. Based on the SentryOptions.getTracesSampleRate() the decision if transaction is sampled will be taken by TracesSampler.
        Parameters:
        name - the transaction name
        operation - the operation
        bindToScope - if transaction should be bound to scope
        Returns:
        created transaction
      • traceHeaders

        @Nullable
        @Nullable SentryTraceHeader traceHeaders()
        Returns trace header of active transaction or null if no transaction is active.
        Returns:
        trace header or null
      • setSpanContext

        @Internal
        void setSpanContext​(@NotNull
                            @NotNull java.lang.Throwable throwable,
                            @NotNull
                            @NotNull ISpan span,
                            @NotNull
                            @NotNull java.lang.String transactionName)
        Associates ISpan and the transaction name with the Throwable. Used to determine in which trace the exception has been thrown in framework integrations.
        Parameters:
        throwable - the throwable
        span - the span context
        transactionName - the transaction name
      • getSpan

        @Nullable
        @Nullable ISpan getSpan()
        Gets the current active transaction or span.
        Returns:
        the active span or null when no active transaction is running
      • getOptions

        @NotNull
        @NotNull SentryOptions getOptions()
        Gets the SentryOptions attached to current scope.
        Returns:
        the options attached to current scope.
      • isCrashedLastRun

        @Nullable
        @Nullable java.lang.Boolean isCrashedLastRun()
        Returns if the App has crashed (Process has terminated) during the last run. It only returns true or false if offline caching {SentryOptions.getCacheDirPath() } is set with a valid dir.

        If the call to this method is early in the App lifecycle and the SDK could not check if the App has crashed in the background, the check is gonna do IO in the calling thread.

        Returns:
        true if App has crashed, false otherwise, and null if not evaluated yet