Skip to main content
Sentry uses a three-tier scope system to manage contextual data: Global Scope, Isolation Scope, and Current Scope. Understanding these scopes is essential for properly organizing your error tracking.

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

Use withScope() to create a temporary scope for specific operations:

Creating Isolation Scopes

Create a new isolation scope for separate execution contexts:
Using withIsolationScope() in environments without an async context strategy (like browsers) may lead to unexpected behavior. This function is primarily designed for server-side environments.

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):
Currently, only strings, numbers, and boolean attributes are fully supported. More complex types will be added in future versions.

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

  1. Use the right scope: Global scope for app-wide data, isolation scope for request/session data, current scope for operation-specific data
  2. Clean up temporary scopes: Always use withScope() for temporary data to ensure proper cleanup
  3. Avoid polluting global scope: Only set truly global data on the global scope
  4. 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