Skip to main content
The Scope class holds additional event information such as breadcrumbs, user context, tags, and extra data. Scopes are used to attach metadata to events.

Overview

Scopes contain:
  • User information
  • Breadcrumbs trail
  • Tags and extra data
  • Context data
  • Event processors
  • Propagation context for distributed tracing

Class Definition

Constructor

Creates a new Scope instance with default values.

Methods

clone

Clone all data from this scope into a new scope.
Returns: A new Scope instance with copied data. Example:

setUser

Set the user for this scope.
User | null
required
User information. Set to null to unset the user.
Returns: The Scope instance for chaining. Example:

getUser

Get the user from this scope.
Returns: The user object or undefined.

setTag

Set a tag on the scope.
string
required
The tag name.
Primitive
required
The tag value (string, number, boolean, null, or undefined).
Example:

setTags

Set multiple tags at once.
Record<string, Primitive>
required
Object containing tag key-value pairs.
Example:

setExtra

Set extra data on the scope.
string
required
The extra data key.
Extra
required
Any value to attach as extra data.
Example:

setExtras

Set multiple extra data fields at once.
Extras
required
Object containing extra data key-value pairs.

setContext

Set context data.
string
required
The context key (e.g., ‘os’, ‘device’, ‘app’).
Context | null
required
Context data object. Set to null to remove the context.
Example:

setContexts

Set multiple contexts at once.
Contexts
required
Object containing context data.

setLevel

Set the severity level.
SeverityLevel
required
One of: 'fatal', 'error', 'warning', 'info', 'debug', or 'log'.
Example:

setFingerprint

Set the fingerprint for grouping events.
string[]
required
Array of strings to group events by.
Example:

addBreadcrumb

Add a breadcrumb to the scope.
Breadcrumb
required
The breadcrumb to add. See Breadcrumb Types for details.
number
Maximum number of breadcrumbs to store. Defaults to 100.
Example:

getLastBreadcrumb

Get the most recent breadcrumb.
Returns: The last breadcrumb or undefined.

clearBreadcrumbs

Clear all breadcrumbs from the scope.

addEventProcessor

Add an event processor to the scope.
EventProcessor
required
Function that processes events before they are sent.
Example:

addAttachment

Add an attachment to the scope.
Attachment
required
File attachment to include with events.
Example:

clear

Clear all data from the scope.

getPropagationContext

Get the propagation context for distributed tracing.
Returns: The propagation context containing trace and span IDs.

setPropagationContext

Set the propagation context.
PropagationContext
required
Propagation context with traceId, spanId, and other tracing data.

Scope Data

The scope data interface represents the normalized data: