Package io.sentry

Class Scope

java.lang.Object
io.sentry.Scope
All Implemented Interfaces:
IScope

public final class Scope extends Object implements IScope
Scope data to be sent with the event
  • Constructor Details

    • Scope

      public Scope(@NotNull @NotNull SentryOptions options)
      Scope's ctor
      Parameters:
      options - the options
  • Method Details

    • getLevel

      @Nullable public @Nullable SentryLevel getLevel()
      Returns the Scope's SentryLevel
      Specified by:
      getLevel in interface IScope
      Returns:
      the SentryLevel
    • setLevel

      public void setLevel(@Nullable @Nullable SentryLevel level)
      Sets the Scope's SentryLevel Level from scope exceptionally take precedence over the event
      Specified by:
      setLevel in interface IScope
      Parameters:
      level - the SentryLevel
    • getTransactionName

      @Nullable public @Nullable String getTransactionName()
      Returns the Scope's transaction name.
      Specified by:
      getTransactionName in interface IScope
      Returns:
      the transaction
    • setTransaction

      public void setTransaction(@NotNull @NotNull String transaction)
      Sets the Scope's transaction.
      Specified by:
      setTransaction in interface IScope
      Parameters:
      transaction - the transaction
    • getSpan

      @Nullable public @Nullable ISpan getSpan()
      Returns current active Span or Transaction.
      Specified by:
      getSpan in interface IScope
      Returns:
      current active Span or Transaction or null if transaction has not been set.
    • setTransaction

      public void setTransaction(@Nullable @Nullable ITransaction transaction)
      Sets the current active transaction
      Specified by:
      setTransaction in interface IScope
      Parameters:
      transaction - the transaction
    • getUser

      @Nullable public @Nullable User getUser()
      Returns the Scope's user
      Specified by:
      getUser in interface IScope
      Returns:
      the user
    • setUser

      public void setUser(@Nullable @Nullable User user)
      Sets the Scope's user
      Specified by:
      setUser in interface IScope
      Parameters:
      user - the user
    • getScreen

      @Internal @Nullable public @Nullable String getScreen()
      Returns the Scope's current screen, previously set by IScope.setScreen(String)
      Specified by:
      getScreen in interface IScope
      Returns:
      the name of the screen
    • setScreen

      @Internal public void setScreen(@Nullable @Nullable String screen)
      Sets the Scope's current screen
      Specified by:
      setScreen in interface IScope
      Parameters:
      screen - the name of the screen
    • getReplayId

      @NotNull public @NotNull SentryId getReplayId()
      Description copied from interface: IScope
      Returns the Scope's current replay_id, previously set by IScope.setReplayId(SentryId)
      Specified by:
      getReplayId in interface IScope
      Returns:
      the id of the current session replay
    • setReplayId

      public void setReplayId(@NotNull @NotNull SentryId replayId)
      Description copied from interface: IScope
      Sets the Scope's current replay_id
      Specified by:
      setReplayId in interface IScope
      Parameters:
      replayId - the id of the current session replay
    • getRequest

      @Nullable public @Nullable Request getRequest()
      Returns the Scope's request
      Specified by:
      getRequest in interface IScope
      Returns:
      the request
    • setRequest

      public void setRequest(@Nullable @Nullable Request request)
      Sets the Scope's request
      Specified by:
      setRequest in interface IScope
      Parameters:
      request - the request
    • getFingerprint

      @Internal @NotNull public @NotNull List<String> getFingerprint()
      Returns the Scope's fingerprint list
      Specified by:
      getFingerprint in interface IScope
      Returns:
      the fingerprint list
    • setFingerprint

      public void setFingerprint(@NotNull @NotNull List<String> fingerprint)
      Sets the Scope's fingerprint list
      Specified by:
      setFingerprint in interface IScope
      Parameters:
      fingerprint - the fingerprint list
    • getBreadcrumbs

      @Internal @NotNull public @NotNull Queue<Breadcrumb> getBreadcrumbs()
      Returns the Scope's breadcrumbs queue
      Specified by:
      getBreadcrumbs in interface IScope
      Returns:
      the breadcrumbs queue
    • addBreadcrumb

      public void addBreadcrumb(@NotNull @NotNull Breadcrumb breadcrumb, @Nullable @Nullable Hint hint)
      Adds a breadcrumb to the breadcrumbs queue. It also executes the BeforeBreadcrumb callback if set
      Specified by:
      addBreadcrumb in interface IScope
      Parameters:
      breadcrumb - the breadcrumb
      hint - the hint
    • addBreadcrumb

      public void addBreadcrumb(@NotNull @NotNull Breadcrumb breadcrumb)
      Adds a breadcrumb to the breadcrumbs queue It also executes the BeforeBreadcrumb callback if set
      Specified by:
      addBreadcrumb in interface IScope
      Parameters:
      breadcrumb - the breadcrumb
    • clearBreadcrumbs

      public void clearBreadcrumbs()
      Clear all the breadcrumbs
      Specified by:
      clearBreadcrumbs in interface IScope
    • clearTransaction

      public void clearTransaction()
      Clears the transaction.
      Specified by:
      clearTransaction in interface IScope
    • getTransaction

      @Nullable public @Nullable ITransaction getTransaction()
      Returns active transaction or null if there is no active transaction.
      Specified by:
      getTransaction in interface IScope
      Returns:
      the transaction
    • clear

      public void clear()
      Resets the Scope to its default state
      Specified by:
      clear in interface IScope
    • getTags

      @Internal @NotNull public @NotNull Map<String,String> getTags()
      Returns the Scope's tags
      Specified by:
      getTags in interface IScope
      Returns:
      the tags map
    • setTag

      public void setTag(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Sets a tag to Scope's tags
      Specified by:
      setTag in interface IScope
      Parameters:
      key - the key
      value - the value
    • removeTag

      public void removeTag(@NotNull @NotNull String key)
      Removes a tag from the Scope's tags
      Specified by:
      removeTag in interface IScope
      Parameters:
      key - the key
    • getExtras

      @Internal @NotNull public @NotNull Map<String,Object> getExtras()
      Returns the Scope's extra map
      Specified by:
      getExtras in interface IScope
      Returns:
      the extra map
    • setExtra

      public void setExtra(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Sets an extra to the Scope's extra map
      Specified by:
      setExtra in interface IScope
      Parameters:
      key - the key
      value - the value
    • removeExtra

      public void removeExtra(@NotNull @NotNull String key)
      Removes an extra from the Scope's extras
      Specified by:
      removeExtra in interface IScope
      Parameters:
      key - the key
    • getContexts

      @NotNull public @NotNull Contexts getContexts()
      Returns the Scope's contexts
      Specified by:
      getContexts in interface IScope
      Returns:
      the contexts
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull Object value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull Boolean value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull Number value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull Collection<?> value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull Object[] value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • setContexts

      public void setContexts(@NotNull @NotNull String key, @NotNull @NotNull Character value)
      Sets the Scope's contexts
      Specified by:
      setContexts in interface IScope
      Parameters:
      key - the context key
      value - the context value
    • removeContexts

      public void removeContexts(@NotNull @NotNull String key)
      Removes a value from the Scope's contexts
      Specified by:
      removeContexts in interface IScope
      Parameters:
      key - the Key
    • getAttachments

      @Internal @NotNull public @NotNull List<Attachment> getAttachments()
      Returns the Scopes's attachments
      Specified by:
      getAttachments in interface IScope
      Returns:
      the attachments
    • addAttachment

      public void addAttachment(@NotNull @NotNull Attachment attachment)
      Adds an attachment to the Scope's list of attachments. The SDK adds the attachment to every event and transaction sent to Sentry.
      Specified by:
      addAttachment in interface IScope
      Parameters:
      attachment - The attachment to add to the Scope's list of attachments.
    • clearAttachments

      public void clearAttachments()
      Clear all attachments.
      Specified by:
      clearAttachments in interface IScope
    • getEventProcessors

      @Internal @NotNull public @NotNull List<EventProcessor> getEventProcessors()
      Returns the Scope's event processors
      Specified by:
      getEventProcessors in interface IScope
      Returns:
      the event processors list
    • addEventProcessor

      public void addEventProcessor(@NotNull @NotNull EventProcessor eventProcessor)
      Adds an event processor to the Scope's event processors list
      Specified by:
      addEventProcessor in interface IScope
      Parameters:
      eventProcessor - the event processor
    • withSession

      @Internal @Nullable public @Nullable Session withSession(@NotNull @NotNull io.sentry.Scope.IWithSession sessionCallback)
      Callback to do atomic operations on session
      Specified by:
      withSession in interface IScope
      Parameters:
      sessionCallback - the IWithSession callback
      Returns:
      a clone of the Session after executing the callback and mutating the session
    • startSession

      @Internal @Nullable public @Nullable io.sentry.Scope.SessionPair startSession()
      Returns a previous session (now closed) bound to this scope together with the newly created one
      Specified by:
      startSession in interface IScope
      Returns:
      the SessionPair with the previous closed session if exists and the current session
    • endSession

      @Internal @Nullable public @Nullable Session endSession()
      Ends a session, unbinds it from the scope and returns it.
      Specified by:
      endSession in interface IScope
      Returns:
      the previous session
    • withTransaction

      @Internal public void withTransaction(@NotNull @NotNull Scope.IWithTransaction callback)
      Mutates the current transaction atomically
      Specified by:
      withTransaction in interface IScope
      Parameters:
      callback - the IWithTransaction callback
    • getOptions

      @Internal @NotNull public @NotNull SentryOptions getOptions()
      Specified by:
      getOptions in interface IScope
    • getSession

      @Internal @Nullable public @Nullable Session getSession()
      Specified by:
      getSession in interface IScope
    • clearSession

      @Internal public void clearSession()
      Specified by:
      clearSession in interface IScope
    • setPropagationContext

      @Internal public void setPropagationContext(@NotNull @NotNull PropagationContext propagationContext)
      Specified by:
      setPropagationContext in interface IScope
    • getPropagationContext

      @Internal @NotNull public @NotNull PropagationContext getPropagationContext()
      Specified by:
      getPropagationContext in interface IScope
    • withPropagationContext

      @Internal @NotNull public @NotNull PropagationContext withPropagationContext(@NotNull @NotNull Scope.IWithPropagationContext callback)
      Specified by:
      withPropagationContext in interface IScope
    • clone

      @NotNull public @NotNull IScope clone()
      Clones the Scope
      Specified by:
      clone in interface IScope
      Overrides:
      clone in class Object
      Returns:
      the cloned Scope