Scope Types
Global Scope
The global scope applies to all events in your application:Isolation Scope
The isolation scope is active for the current execution context (e.g., per request in Node.js, per page in browsers):Current Scope
The current scope is the most local scope, typically used for individual operations:Data from all three scopes is merged when an event is sent. More specific scopes override less specific ones: Current Scope > Isolation Scope > Global Scope.
Working with Scopes
Creating Temporary Scopes
UsewithScope() to create a temporary scope for specific operations:
Creating Isolation Scopes
Create a new isolation scope for separate execution contexts:Setting Scope Data
User Information
Set user information on any scope:Tags
Tags are searchable key-value pairs:Extra Data
Extra data provides additional context (not searchable):Context
Context provides structured data for specific categories:Attributes
Attributes are applied to logs and metrics (and spans in the future):Scope Manipulation
Cloning Scopes
Clearing Scopes
Updating Scopes
Scope Listeners
Listen to scope changes:Advanced Patterns
Setting Transaction Names
Setting the transaction name on the scope does NOT change the name of the active span. Use
Sentry.updateSpanName() to change the active span’s name.Fingerprinting
Group similar errors together:Setting Severity Level
Best Practices
- Use the right scope: Global scope for app-wide data, isolation scope for request/session data, current scope for operation-specific data
- Clean up temporary scopes: Always use
withScope()for temporary data to ensure proper cleanup - Avoid polluting global scope: Only set truly global data on the global scope
- Be mindful of async operations: Scope data may not persist across async boundaries in some environments
Next Steps
Context
Learn more about context types and structured data
Breadcrumbs
Add breadcrumbs to track user actions
Performance
Associate performance data with scopes
Error Monitoring
Capture errors with scope context