What is Context?
Context data is organized into named categories, each containing structured information relevant to your events:Context data is automatically included with all subsequent events until it’s removed or replaced.
Setting Context
Basic Usage
Set context on the isolation scope (applies to all events in the current context):Multiple Contexts
You can set multiple different contexts:Removing Context
Remove context by setting it tonull:
Built-in Context Types
Sentry recognizes several standard context types:Device Context
Operating System Context
Runtime Context
App Context
Browser Context
Culture Context
Custom Context Types
You can create custom context types for your application:E-commerce Context
API Request Context
Feature Flag Context
Database Context
Context in Scopes
Isolation Scope Context
Context set viasetContext() is added to the isolation scope:
Current Scope Context
Temporary Context
UsewithScope() to set context that only applies to specific operations:
Context vs Tags vs Extra
When to Use Context
- Structured, typed data
- Multiple related fields that belong together
- Standard categories (device, OS, runtime, etc.)
- Rich object data
When to Use Tags
- Simple key-value pairs
- Data you want to search/filter by
- High-cardinality identifiers (within limits)
- Grouping and aggregation
When to Use Extra
- Arbitrary, unstructured data
- Large objects or arrays
- Debug information
- Data that doesn’t fit other categories
Quick Reference:
- Context: Structured, categorized data (device, OS, custom categories)
- Tags: Searchable key-value pairs (environment, version)
- Extra: Unstructured additional data (debug info, large objects)
Context Best Practices
- Use descriptive names: Choose clear context category names that indicate the type of data
- Keep it relevant: Only include context that helps debug issues
- Avoid sensitive data: Don’t include passwords, tokens, or PII
- Be consistent: Use the same structure for the same context type across your app
- Size matters: Large contexts can impact performance and event size limits
Working with Context Data
Reading Context
Merging Contexts
Next Steps
Scopes
Learn about scope management
Breadcrumbs
Track user actions with breadcrumbs
User Feedback
Collect user feedback with context
Feature Flags
Track feature flag evaluations