Package io.sentry

Class Sentry

java.lang.Object
io.sentry.Sentry

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

    • APP_START_PROFILING_CONFIG_FILE_NAME

      @Internal @NotNull public static final @NotNull String APP_START_PROFILING_CONFIG_FILE_NAME
      See Also:
  • 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
    • cloneMainHub

      @Internal @Experimental @NotNull public static @NotNull IHub cloneMainHub()
      Returns a new hub which is cloned from the mainHub.
      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.
    • isHealthy

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

      @NotNull public static @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @Nullable @Nullable String description, @NotNull @NotNull TransactionOptions transactionOptions)
      Creates a Transaction and returns the instance.
      Parameters:
      name - the transaction name
      operation - the operation
      description - the description
      transactionOptions - options for the transaction
      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 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

      @Deprecated @Nullable public static @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
    • 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. In case of globalHubMode=true, always the active transaction is returned, rather than the last active span.
    • 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
    • reportFullyDisplayed

      public static 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 public static void reportFullDisplayed()
      Deprecated.
    • metrics

      @NotNull @Experimental public static @NotNull MetricsApi metrics()
      the metrics API for the current hub
    • continueTrace

      @Nullable public static @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 public static @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 public static @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 public static @NotNull SentryId captureCheckIn(@NotNull @NotNull CheckIn checkIn)