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 Details

    • 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 Hint 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
    • captureEvent

      @NotNull default @NotNull SentryId captureEvent(@NotNull @NotNull SentryEvent event, @NotNull @NotNull ScopeCallback callback)
      Captures the event.
      Parameters:
      event - the event
      callback - The callback to configure the scope for a single invocation.
      Returns:
      The Id (SentryId object) of the event
    • captureEvent

      @NotNull @NotNull SentryId captureEvent(@NotNull @NotNull SentryEvent event, @Nullable @Nullable Hint hint, @NotNull @NotNull ScopeCallback callback)
      Captures the event.
      Parameters:
      event - the event
      hint - SDK specific but provides high level information about the origin of the event
      callback - The callback to configure the scope for a single invocation.
      Returns:
      The Id (SentryId object) of the event
    • captureMessage

      @NotNull default @NotNull SentryId captureMessage(@NotNull @NotNull 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 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
    • captureMessage

      @NotNull @NotNull SentryId captureMessage(@NotNull @NotNull String message, @NotNull @NotNull SentryLevel level, @NotNull @NotNull ScopeCallback callback)
      Captures the message.
      Parameters:
      message - The message to send.
      level - The message level.
      callback - The callback to configure the scope for a single invocation.
      Returns:
      The Id (SentryId object) of the event
    • captureMessage

      @NotNull default @NotNull SentryId captureMessage(@NotNull @NotNull String message, @NotNull @NotNull ScopeCallback callback)
      Captures the message.
      Parameters:
      message - The message to send.
      callback - The callback to configure the scope for a single invocation.
      Returns:
      The Id (SentryId object) of the event
    • captureEnvelope

      @NotNull @NotNull SentryId captureEnvelope(@NotNull @NotNull SentryEnvelope envelope, @Nullable @Nullable Hint 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 Throwable throwable, @Nullable @Nullable Hint 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 Throwable throwable)
      Captures the exception.
      Parameters:
      throwable - The exception.
      Returns:
      The Id (SentryId object) of the event
    • captureException

      @NotNull default @NotNull SentryId captureException(@NotNull @NotNull Throwable throwable, @NotNull @NotNull ScopeCallback callback)
      Captures the exception.
      Parameters:
      throwable - The exception.
      callback - The callback to configure the scope for a single invocation.
      Returns:
      The Id (SentryId object) of the event
    • captureException

      @NotNull @NotNull SentryId captureException(@NotNull @NotNull Throwable throwable, @Nullable @Nullable Hint hint, @NotNull @NotNull ScopeCallback callback)
      Captures the exception.
      Parameters:
      throwable - The exception.
      hint - SDK specific but provides high level information about the origin of the event
      callback - The callback to configure the scope for a single invocation.
      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.
    • close

      void close(boolean isRestarting)
      Flushes out the queue for up to timeout seconds and disable the Hub.
      Parameters:
      isRestarting - if true, avoids locking the main thread when finishing the queue.
    • addBreadcrumb

      void addBreadcrumb(@NotNull @NotNull Breadcrumb breadcrumb, @Nullable @Nullable Hint 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

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

      default void addBreadcrumb(@NotNull @NotNull 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 String message, @NotNull @NotNull 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 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 List<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 String key, @NotNull @NotNull 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 String key)
      Removes the tag to a string value to the current Scope
      Parameters:
      key - the key
    • setExtra

      void setExtra(@NotNull @NotNull String key, @NotNull @NotNull 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 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. If you're using the Sentry SDK in globalHubMode (defaults to true on Android) Sentry.init(Sentry.OptionsConfiguration, boolean) calling withScope is discouraged, as scope changes may be dropped when executed in parallel. Use configureScope(ScopeCallback) instead.
      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.
    • isHealthy

      boolean isHealthy()
      Whether the transport is healthy.
      Returns:
      true if the transport is healthy
    • 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 TraceContext traceContext, @Nullable @Nullable Hint hint, @Nullable @Nullable ProfilingTraceData profilingTraceData)
      Captures the transaction and enqueues it for sending to Sentry server.
      Parameters:
      transaction - the transaction
      traceContext - the trace context
      hint - the hints
      profilingTraceData - the profiling trace data
      Returns:
      transaction's id
    • captureTransaction

      @Internal @NotNull default @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable TraceContext traceContext, @Nullable @Nullable Hint hint)
      Captures the transaction and enqueues it for sending to Sentry server.
      Parameters:
      transaction - the transaction
      traceContext - the trace context
      hint - the hints
      Returns:
      transaction's id
    • captureTransaction

      @Internal @NotNull default @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable Hint hint)
    • captureTransaction

      @Internal @NotNull default @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable TraceContext traceContext)
      Captures the transaction and enqueues it for sending to Sentry server.
      Parameters:
      transaction - the transaction
      traceContext - the trace context
      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 String name, @NotNull @NotNull 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

      @NotNull default @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @NotNull @NotNull TransactionOptions transactionOptions)
      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
      transactionOptions - the transaction options
      Returns:
      created transaction
    • startTransaction

      @NotNull @NotNull ITransaction startTransaction(@NotNull @NotNull TransactionContext transactionContext, @NotNull @NotNull TransactionOptions transactionOptions)
      Creates a Transaction and returns the instance. Based on the passed transaction context and transaction options the decision if transaction is sampled will be taken by TracesSampler.
      Parameters:
      transactionContext - the transaction context
      transactionOptions - the transaction options
      Returns:
      created transaction.
    • traceHeaders

      @Deprecated @Nullable @Nullable SentryTraceHeader traceHeaders()
      Deprecated.
      please use getTraceparent() instead.
      Returns the "sentry-trace" header that allows tracing across services. Can also be used in <meta> HTML tags. Also see getBaggage().
      Returns:
      sentry trace header or null
    • setSpanContext

      @Internal void setSpanContext(@NotNull @NotNull Throwable throwable, @NotNull @NotNull ISpan span, @NotNull @NotNull 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
    • getTransaction

      @Internal @Nullable @Nullable ITransaction getTransaction()
      Returns the transaction.
      Returns:
      the transaction 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 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
    • reportFullyDisplayed

      void reportFullyDisplayed()
      Report a screen has been fully loaded. That means all data needed by the UI was loaded. If time-to-full-display tracing {SentryOptions.isEnableTimeToFullDisplayTracing() } is disabled this call is ignored.

      This method is safe to be called multiple times. If the time-to-full-display span is already finished, this call will be ignored.

    • reportFullDisplayed

      @Deprecated default void reportFullDisplayed()
      Deprecated.
    • continueTrace

      @Nullable @Nullable TransactionContext continueTrace(@Nullable @Nullable String sentryTrace, @Nullable @Nullable List<String> baggageHeaders)
      Continue a trace based on HTTP header values. If no "sentry-trace" header is provided a random trace ID and span ID is created.
      Parameters:
      sentryTrace - "sentry-trace" header
      baggageHeaders - "baggage" headers
      Returns:
      a transaction context for starting a transaction or null if performance is disabled
    • getTraceparent

      @Nullable @Nullable SentryTraceHeader getTraceparent()
      Returns the "sentry-trace" header that allows tracing across services. Can also be used in <meta> HTML tags. Also see getBaggage().
      Returns:
      sentry trace header or null
    • getBaggage

      @Nullable @Nullable BaggageHeader getBaggage()
      Returns the "baggage" header that allows tracing across services. Can also be used in <meta> HTML tags. Also see getTraceparent().
      Returns:
      baggage header or null
    • captureCheckIn

      @Experimental @NotNull @NotNull SentryId captureCheckIn(@NotNull @NotNull CheckIn checkIn)
    • captureReplay

      @NotNull @NotNull SentryId captureReplay(@NotNull @NotNull SentryReplayEvent replay, @Nullable @Nullable Hint hint)
    • getRateLimiter

      @Internal @Nullable @Nullable RateLimiter getRateLimiter()
    • metrics

      @Experimental @NotNull @NotNull MetricsApi metrics()