Skip to main content
The 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

ClientOptions
required
Configuration options for the client. See Configuration Options for details.

Methods

captureException

Captures an exception event and sends it to Sentry.
unknown
required
The exception to capture. Can be an Error object or any value.
EventHint
Additional information about the exception context.
Scope
The scope containing event metadata. If not provided, uses the current scope.
Returns: string - The event ID of the captured exception. Example:

captureMessage

Captures a message event and sends it to Sentry.
ParameterizedString | string
required
The message to capture.
SeverityLevel
The severity level: 'fatal', 'error', 'warning', 'info', or 'debug'.
EventHint
Additional information about the message context.
Scope
The scope containing event metadata.
Returns: string - The event ID of the captured message. Example:

captureEvent

Captures a manually created event and sends it to Sentry.
Event
required
The event object to send. See Event Types for structure.
EventHint
Additional metadata about the event.
Scope
The scope containing event metadata.
Returns: string - The event ID.

flush

Wait for all events to be sent or the timeout to expire.
number
Maximum time in milliseconds to wait. Omitting this will wait until all events are sent.
Returns: Promise<boolean> - true if all events are sent before timeout, false otherwise. Example:

close

Flush the event queue and disable the client.
number
Maximum time in milliseconds to wait before shutting down.
Returns: Promise<boolean> - true if flush completes successfully, false otherwise. Example:

getDsn

Get the current DSN.
Returns: The parsed DSN components or undefined if no DSN is configured.

getOptions

Get the client options.
Returns: The options passed to the client constructor.

getTransport

Get the transport used by the client.
Returns: The transport instance or undefined if not initialized.

addIntegration

Add an integration to the client at runtime.
Integration
required
The integration to add.
Example:

getIntegrationByName

Get an installed integration by name.
string
required
The name of the integration.
Returns: The integration instance or undefined.

addEventProcessor

Add an event processor that applies to all events.
EventProcessor
required
A function that processes events before they are sent.
Example:

on

Register a callback for lifecycle hooks.
Returns: A function that removes the registered callback. Example:

emit

Emit a hook event.

Hooks

The Client supports various lifecycle hooks:
  • spanStart - Fired when a span starts
  • spanEnd - Fired when a span ends
  • beforeSendEvent - Fired before sending an event
  • afterSendEvent - Fired after sending an event
  • beforeAddBreadcrumb - Fired before adding a breadcrumb
  • flush - Fired when flushing
  • close - Fired when closing