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.setUser
Set the user for this scope.User | null
required
User information. Set to
null to unset the user.getUser
Get the user from this scope.undefined.
setTag
Set a tag on the scope.string
required
The tag name.
Primitive
required
The tag value (string, number, boolean, null, or undefined).
setTags
Set multiple tags at once.Record<string, Primitive>
required
Object containing tag key-value pairs.
setExtra
Set extra data on the scope.string
required
The extra data key.
Extra
required
Any value to attach as extra data.
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.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'.setFingerprint
Set the fingerprint for grouping events.string[]
required
Array of strings to group events by.
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.
getLastBreadcrumb
Get the most recent breadcrumb.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.
addAttachment
Add an attachment to the scope.Attachment
required
File attachment to include with events.
clear
Clear all data from the scope.getPropagationContext
Get the propagation context for distributed tracing.setPropagationContext
Set the propagation context.PropagationContext
required
Propagation context with traceId, spanId, and other tracing data.