Package io.sentry

Class Sentry

java.lang.Object
io.sentry.Sentry

public final class Sentry extends Object
Sentry SDK main API entry point
  • Method Details

    • getCurrentHub

      @Internal @NotNull public static @NotNull IHub getCurrentHub()
      Returns the current (threads) hub, if none, clones the mainHub and returns it.
      Returns:
      the hub
    • setCurrentHub

      @Internal public static void setCurrentHub(@NotNull @NotNull IHub hub)
    • isEnabled

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

      public static void init()
      Initializes the SDK
    • init

      public static void init(@NotNull @NotNull String dsn)
      Initializes the SDK
      Parameters:
      dsn - The Sentry DSN
    • init

      public static <T extends SentryOptions> void init(@NotNull @NotNull OptionsContainer<T> clazz, @NotNull @NotNull Sentry.OptionsConfiguration<T> optionsConfiguration) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
      Initializes the SDK
      Type Parameters:
      T - class that extends SentryOptions
      Parameters:
      clazz - OptionsContainer for SentryOptions
      optionsConfiguration - configuration options callback
      Throws:
      IllegalAccessException - the IllegalAccessException
      InstantiationException - the InstantiationException
      NoSuchMethodException - the NoSuchMethodException
      InvocationTargetException - the InvocationTargetException
    • init

      public static <T extends SentryOptions> void init(@NotNull @NotNull OptionsContainer<T> clazz, @NotNull @NotNull Sentry.OptionsConfiguration<T> optionsConfiguration, boolean globalHubMode) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
      Initializes the SDK
      Type Parameters:
      T - class that extends SentryOptions
      Parameters:
      clazz - OptionsContainer for SentryOptions
      optionsConfiguration - configuration options callback
      globalHubMode - the globalHubMode
      Throws:
      IllegalAccessException - the IllegalAccessException
      InstantiationException - the InstantiationException
      NoSuchMethodException - the NoSuchMethodException
      InvocationTargetException - the InvocationTargetException
    • init

      public static void init(@NotNull @NotNull Sentry.OptionsConfiguration<SentryOptions> optionsConfiguration)
      Initializes the SDK with an optional configuration options callback.
      Parameters:
      optionsConfiguration - configuration options callback
    • init

      public static void init(@NotNull @NotNull Sentry.OptionsConfiguration<SentryOptions> optionsConfiguration, boolean globalHubMode)
      Initializes the SDK with an optional configuration options callback.
      Parameters:
      optionsConfiguration - configuration options callback
      globalHubMode - the globalHubMode
    • init

      @Internal public static void init(@NotNull @NotNull SentryOptions options)
      Initializes the SDK with a SentryOptions.
      Parameters:
      options - options the SentryOptions
    • close

      public static void close()
      Close the SDK
    • captureEvent

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

      @NotNull public static @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 public static @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 public static @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 public static @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 public static @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
    • captureMessage

      @NotNull public static @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 public static @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
    • captureException

      @NotNull public static @NotNull SentryId captureException(@NotNull @NotNull Throwable throwable)
      Captures the exception.
      Parameters:
      throwable - The exception.
      Returns:
      The Id (SentryId object) of the event
    • captureException

      @NotNull public static @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 public static @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 public static @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

      public static 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.
    • addBreadcrumb

      public static 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

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

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

      public static 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

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

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

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

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

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

      public static 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

      public static void removeTag(@NotNull @NotNull String key)
      Removes the tag to a string value to the current Scope
      Parameters:
      key - the key
    • setExtra

      public static 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

      public static void removeExtra(@NotNull @NotNull String key)
      Removes the extra key to an arbitrary value to the current Scope
      Parameters:
      key - the key
    • getLastEventId

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

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

      public static void popScope()
      Removes the first scope
    • withScope

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

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

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

      public static void flush(long timeoutMillis)
      Flushes events queued up to the current hub. Not implemented yet.
      Parameters:
      timeoutMillis - time in milliseconds
    • startSession

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

      public static void endSession()
      Ends the current session
    • startTransaction

      @NotNull public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation)
      Creates a Transaction and returns the instance. Started transaction is set on the scope.
      Parameters:
      name - the transaction name
      operation - the operation
      Returns:
      created transaction
    • startTransaction

      @NotNull public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, boolean bindToScope)
      Creates a Transaction and returns the instance.
      Parameters:
      name - the transaction name
      operation - the operation
      bindToScope - if transaction should be bound to scope
      Returns:
      created transaction
    • startTransaction

      @NotNull public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @Nullable @Nullable String description)
      Creates a Transaction and returns the instance.
      Parameters:
      name - the transaction name
      operation - the operation
      description - the description
      Returns:
      created transaction
    • startTransaction

      @NotNull public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @Nullable @Nullable String description, boolean bindToScope)
      Creates a Transaction and returns the instance.
      Parameters:
      name - the transaction name
      operation - the operation
      description - the description
      bindToScope - if transaction should be bound to scope
      Returns:
      created transaction
    • startTransaction

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

      @NotNull public static @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 public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @NotNull @NotNull 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 public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @NotNull @NotNull 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 public static @NotNull ITransaction startTransaction(@NotNull @NotNull TransactionContext transactionContexts, @NotNull @NotNull 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 public static @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 public static @NotNull ITransaction startTransaction(@NotNull @NotNull TransactionContext transactionContext, @NotNull @NotNull TransactionOptions transactionOptions)
      Creates a Transaction and returns the instance.
      Parameters:
      transactionContext - the transaction context
      transactionOptions - options for the transaction
      Returns:
      created transaction.
    • traceHeaders

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

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

      @Nullable public static @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