Client class is the base implementation for all JavaScript SDK clients. It handles event capture, transport, integrations, and lifecycle management.
Overview
The Client is responsible for:- Capturing exceptions, messages, and events
- Managing integrations and event processors
- Sending data to Sentry via transports
- Managing scope and session data
Class Definition
Constructor
Configuration options for the client. See Configuration Options for details.
Methods
captureException
Captures an exception event and sends it to Sentry.The exception to capture. Can be an Error object or any value.
Additional information about the exception context.
The scope containing event metadata. If not provided, uses the current scope.
string - The event ID of the captured exception.
Example:
captureMessage
Captures a message event and sends it to Sentry.The message to capture.
The severity level:
'fatal', 'error', 'warning', 'info', or 'debug'.Additional information about the message context.
The scope containing event metadata.
string - The event ID of the captured message.
Example:
captureEvent
Captures a manually created event and sends it to Sentry.The event object to send. See Event Types for structure.
Additional metadata about the event.
The scope containing event metadata.
string - The event ID.
flush
Wait for all events to be sent or the timeout to expire.Maximum time in milliseconds to wait. Omitting this will wait until all events are sent.
Promise<boolean> - true if all events are sent before timeout, false otherwise.
Example:
close
Flush the event queue and disable the client.Maximum time in milliseconds to wait before shutting down.
Promise<boolean> - true if flush completes successfully, false otherwise.
Example:
getDsn
Get the current DSN.undefined if no DSN is configured.
getOptions
Get the client options.getTransport
Get the transport used by the client.undefined if not initialized.
addIntegration
Add an integration to the client at runtime.The integration to add.
getIntegrationByName
Get an installed integration by name.The name of the integration.
undefined.
addEventProcessor
Add an event processor that applies to all events.A function that processes events before they are sent.
on
Register a callback for lifecycle hooks.emit
Emit a hook event.Hooks
The Client supports various lifecycle hooks:spanStart- Fired when a span startsspanEnd- Fired when a span endsbeforeSendEvent- Fired before sending an eventafterSendEvent- Fired after sending an eventbeforeAddBreadcrumb- Fired before adding a breadcrumbflush- Fired when flushingclose- Fired when closing