Class BaseClient<O>Abstract

Base implementation for all JavaScript SDK clients.

Call the constructor with the corresponding options specific to the client subclass. To access these options later, use getOptions.

If a Dsn is specified in the options, it will be parsed and stored. Use getDsn to retrieve the Dsn at any moment. In case the Dsn is invalid, the constructor will throw a SentryException. Note that without a valid Dsn, the SDK will not send any events to Sentry.

Before sending an event, it is passed through _prepareEvent to add SDK information and scope data (breadcrumbs and context). To add more custom information, override this method and extend the resulting prepared event.

To issue automatically created events (e.g. via instrumentation), use captureEvent. It will prepare the event and pass it through the callback lifecycle. To issue auto-breadcrumbs, use Client.addBreadcrumb.

Example

class NodeClient extends BaseClient<NodeOptions> {
public constructor(options: NodeOptions) {
super(options);
}

// ...
}

Type Parameters

  • O extends ClientOptions

Hierarchy

Implements

Constructors

  • Initializes this client instance.

    Type Parameters

    • O extends ClientOptions<BaseTransportOptions, O>

    Parameters

    • options: O

      Options for the client.

    Returns BaseClient<O>

Properties

The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled.

_integrations: IntegrationIndex = {}

Array of set up integrations.

_integrationsInitialized: boolean = false

Indicates whether this client's integrations have been set up.

_numProcessing: number = 0

Number of calls being processed

_options: O

Options passed to the SDK.

Methods

  • Processes the event and logs an error in case of rejection

    Parameters

    Returns PromiseLike<undefined | string>

  • Clears outcomes on this client and returns them.

    Returns Outcome[]

  • Determine if the client is finished processing. Returns a promise because it will wait timeout ms before saying "no" (resolving to false) in order to give the client a chance to potentially finish first.

    Parameters

    • Optional timeout: number

      The time, in ms, after which to resolve to false if the client is still busy. Passing 0 (or not passing anything) will make the promise wait as long as it takes for processing to finish before resolving to true.

    Returns PromiseLike<boolean>

    A promise which will resolve to true if processing is already done or finishes before the timeout, and false otherwise

  • Determines whether this SDK is enabled and a valid Dsn is present.

    Returns boolean

  • Adds common information to events.

    The information includes release and environment from options, breadcrumbs and context (extra, tags and user) from the scope.

    Information that is already present in the event is never overwritten. For nested objects, such as the context, keys are merged.

    Parameters

    • event: Event

      The original event.

    • hint: EventHint

      May contain additional information about the original exception.

    • Optional scope: Scope

      A scope containing event metadata.

    Returns PromiseLike<null | Event>

    A new event with more information.

  • Occupies the client with processing and event

    Type Parameters

    • T

    Parameters

    • promise: PromiseLike<T>

    Returns void

  • Processes an event (either error or message) and sends it to Sentry.

    This also adds breadcrumbs and context information to the event. However, platform specific meta data (such as the User's IP address) must be added by the SDK implementor.

    Parameters

    • event: Event

      The event to send to Sentry.

    • hint: EventHint

      May contain additional information about the original exception.

    • Optional scope: Scope

      A scope containing event metadata.

    Returns PromiseLike<Event>

    A SyncPromise that resolves with the event or rejects in case event was/will not be send.

  • Parameters

    • envelope: Envelope

    Returns void | PromiseLike<void | TransportMakeRequestResponse>

    Inherit Doc

  • Updates existing session based on the provided event

    Parameters

    • session: Session
    • event: Event

    Returns void

  • Add an integration to the client. This can be used to e.g. lazy load integrations. In most cases, this should not be necessary, and you're better off just passing the integrations via integrations: [] at initialization time. However, if you find the need to conditionally load & add an integration, you can use addIntegration to do so.

    TODO (v8): Make this a required method.

    Parameters

    Returns void

  • Captures a manually created event and sends it to Sentry.

    Parameters

    • event: Event

      The event to send to Sentry.

    • Optional hint: EventHint

      May contain additional information about the original exception.

    • Optional scope: Scope

      An optional scope containing event metadata.

    Returns undefined | string

    The event id

  • Captures an exception event and sends it to Sentry.

    Parameters

    • exception: any

      An exception-like object.

    • Optional hint: EventHint

      May contain additional information about the original exception.

    • Optional scope: Scope

      An optional scope containing event metadata.

    Returns undefined | string

    The event id

  • Captures a message event and sends it to Sentry.

    Parameters

    • message: string

      The message to send to Sentry.

    • Optional level: Severity | SeverityLevel

      Define the level of the message.

    • Optional hint: EventHint

      May contain additional information about the original exception.

    • Optional scope: Scope

      An optional scope containing event metadata.

    Returns undefined | string

    The event id

  • Flush the event queue and set the client to enabled = false. See flush.

    Parameters

    • Optional timeout: number

      Maximum time in ms the client should wait before shutting down. Omitting this parameter will cause the client to wait until all events are sent before disabling itself.

    Returns PromiseLike<boolean>

    A promise which resolves to true if the flush completes successfully before the timeout, or false if it doesn't.

  • Fire a hook event for transaction start and finish. Expects to be given a transaction as the second argument.

    Parameters

    • hook: "startTransaction" | "finishTransaction"
    • transaction: Transaction

    Returns void

  • Fire a hook for when a breadcrumb is added. Expects the breadcrumb as second argument.

    Parameters

    • hook: "beforeEnvelope"
    • envelope: Envelope

    Returns void

  • Fire a hook for when a DSC (Dynamic Sampling Context) is created. Expects the DSC as second argument.

    Parameters

    • hook: "afterSendEvent"
    • event: Event
    • sendResponse: void | TransportMakeRequestResponse

    Returns void

  • Parameters

    Returns void

    Inherit Doc

  • Parameters

    • hook: "createDsc"
    • dsc: DynamicSamplingContext

    Returns void

    Inherit Doc

  • Wait for all events to be sent or the timeout to expire, whichever comes first.

    Parameters

    • Optional timeout: number

      Maximum time in ms the client should wait for events to be flushed. Omitting this parameter will cause the client to wait until all events are sent before resolving the promise.

    Returns PromiseLike<boolean>

    A promise that will resolve with true if all events are sent before the timeout, or false if there are still events in the queue when the timeout is reached.

  • Gets an installed integration by its id.

    Parameters

    • integrationId: string

    Returns undefined | Integration

    The installed integration or undefined if no integration with that id was installed.

  • Returns the transport that is used by the client. Please note that the transport gets lazy initialized so it will only be there once the first event has been sent.

    Returns undefined | Transport

    The transport.

  • Register a callback for transaction start and finish.

    Parameters

    • hook: "startTransaction" | "finishTransaction"
    • callback: ((transaction) => void)
        • (transaction): void
        • Parameters

          Returns void

    Returns void

  • Register a callback for transaction start and finish.

    Parameters

    • hook: "beforeEnvelope"
    • callback: ((envelope) => void)
        • (envelope): void
        • Parameters

          • envelope: Envelope

          Returns void

    Returns void

  • Register a callback for when an event has been sent.

    Parameters

    • hook: "afterSendEvent"
    • callback: ((event, sendResponse) => void)
        • (event, sendResponse): void
        • Parameters

          • event: Event
          • sendResponse: void | TransportMakeRequestResponse

          Returns void

    Returns void

  • Register a callback before a breadcrumb is added.

    Parameters

    • hook: "beforeAddBreadcrumb"
    • callback: ((breadcrumb, hint?) => void)

    Returns void

  • Register a callback whena DSC (Dynamic Sampling Context) is created.

    Parameters

    • hook: "createDsc"
    • callback: ((dsc) => void)
        • (dsc): void
        • Parameters

          • dsc: DynamicSamplingContext

          Returns void

    Returns void

  • Record on the client that an event got dropped (ie, an event that will not be sent to sentry).

    Parameters

    • reason: EventDropReason

      The reason why the event got dropped.

    • category: DataCategory
    • Optional _event: Event

      The dropped event.

    Returns void

Generated using TypeDoc