Package io.sentry

Interface IScopes

All Known Subinterfaces:
IHub
All Known Implementing Classes:
HubAdapter, HubScopesWrapper, NoOpHub, NoOpScopes, Scopes, ScopesAdapter

public interface IScopes
  • Method Details

    • isEnabled

      boolean isEnabled()
      Check if Sentry 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 Scopes.
    • close

      void close(boolean isRestarting)
      Flushes out the queue for up to timeout seconds and disable the Scopes.
      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

      @NotNull @NotNull ISentryLifecycleToken pushScope()
      Pushes a new scope while inheriting the current scope's data.
    • pushIsolationScope

      @NotNull @NotNull ISentryLifecycleToken pushIsolationScope()
    • popScope

      @Deprecated void popScope()
      Deprecated.
      please call ISentryLifecycleToken.close() on the token returned by pushScope() or pushIsolationScope() instead.
      Removes the first scope and restores its parent.
    • withScope

      void withScope(@NotNull @NotNull ScopeCallback callback)
      Runs the callback with a new current 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
    • withIsolationScope

      void withIsolationScope(@NotNull @NotNull ScopeCallback callback)
      Runs the callback with a new isolation scope which gets dropped at the end. Current scope is also forked.

      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(ScopeType, ScopeCallback) instead.

      Parameters:
      callback - the callback
    • configureScope

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

      void configureScope(@Nullable @Nullable ScopeType scopeType, @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 scopes
      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 scopes enabled. Not implemented yet.
      Parameters:
      timeoutMillis - time in milliseconds
    • clone

      @NotNull @Deprecated @NotNull IHub clone()
      Deprecated.
      Clones the Hub
      Returns:
      the cloned Hub
    • forkedScopes

      @NotNull @NotNull IScopes forkedScopes(@NotNull @NotNull String creator)
      Creates a fork of both current and isolation scope from current scopes.
      Parameters:
      creator - debug information to see why scopes where forked
      Returns:
      forked Scopes
    • forkedCurrentScope

      @NotNull @NotNull IScopes forkedCurrentScope(@NotNull @NotNull String creator)
      Creates a fork of current scope without forking isolation scope.
      Parameters:
      creator - debug information to see why scopes where forked
      Returns:
      forked Scopes
    • forkedRootScopes

      @NotNull @NotNull IScopes forkedRootScopes(@NotNull @NotNull String creator)
      Creates a fork of both current and isolation scope from root scopes.
      Parameters:
      creator - debug information to see why scopes where forked
      Returns:
      forked Scopes
    • makeCurrent

      @NotNull @NotNull ISentryLifecycleToken makeCurrent()
      Stores this Scopes in store, making it the current one that is used by static API.
      Returns:
      a token you should call .close() on when you're done.
    • getScope

      @Internal @NotNull @NotNull IScope getScope()
      Returns the current scope of this Scopes.
      Returns:
      scope
    • getIsolationScope

      @Internal @NotNull @NotNull IScope getIsolationScope()
      Returns the isolation scope of this Scopes.
      Returns:
      isolation scope
    • getGlobalScope

      @Internal @NotNull @NotNull IScope getGlobalScope()
      Returns the global scope.
      Returns:
      global scope
    • getParentScopes

      @Internal @Nullable @Nullable IScopes getParentScopes()
      Returns the parent of this Scopes instance or null, if it does not have a parent. The parent is the Scopes instance this instance was forked from.
      Returns:
      parent Scopes or null
    • isAncestorOf

      @Internal boolean isAncestorOf(@Nullable @Nullable IScopes otherScopes)
      Checks whether this Scopes instance is direct or indirect parent of the other Scopes instance.
      Parameters:
      otherScopes - Scopes instance that could be a direct or indirect child.
      Returns:
      true if this Scopes instance is a direct or indirect parent of the other Scopes.
    • 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.
    • 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
    • setActiveSpan

      @Internal void setActiveSpan(@Nullable @Nullable ISpan span)
    • 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.

    • 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)
    • getRateLimiter

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

      default boolean isNoOp()
    • captureReplay

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