captureMessage function captures a message string and sends it to Sentry as an event.
Function Signature
Parameters
string
required
The message string to capture.
CaptureContext | SeverityLevel
Either a severity level string or additional context. Can be:
- A SeverityLevel:
'fatal','error','warning','info','debug', or'log' - A Scope object
- A partial ScopeContext object
- A callback function receiving the current scope
Returns
string
The unique ID of the captured event.
Basic Usage
Severity Levels
With Context
Using Object Context
Using Scope Callback
Advanced Examples
API Monitoring
Feature Flag Tracking
Business Metrics
Implementation Details
Frompackages/core/src/client.ts:
Message vs Exception
UsecaptureMessage for:
- Informational logging
- Business events
- Feature usage tracking
- Performance milestones
- State changes
captureException for:
- Caught exceptions
- Error conditions
- Failed operations
- Unexpected states
Filtering Messages
UsebeforeSend to filter or modify messages: