@sentry/core

  • Version 7.23.0
  • Published
  • 571 kB
  • 3 dependencies
  • MIT license

Install

npm i @sentry/core
yarn add @sentry/core
pnpm add @sentry/core

Overview

Base implementation for all Sentry JavaScript SDKs

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable SDK_VERSION

const SDK_VERSION: string;

    Functions

    function addBreadcrumb

    addBreadcrumb: (breadcrumb: Breadcrumb) => ReturnType<Hub['addBreadcrumb']>;
    • Records a new breadcrumb which will be attached to future events.

      Breadcrumbs will be added to subsequent events to provide more context on user's actions prior to an error or crash.

      Parameter breadcrumb

      The breadcrumb to record.

    function addGlobalEventProcessor

    addGlobalEventProcessor: (callback: EventProcessor) => void;
    • Add a EventProcessor to be kept globally.

      Parameter callback

      EventProcessor to add

    function captureEvent

    captureEvent: (
    event: Event,
    hint?: EventHint
    ) => ReturnType<Hub['captureEvent']>;
    • Captures a manually created event and sends it to Sentry.

      Parameter event

      The event to send to Sentry.

      Returns

      The generated eventId.

    function captureException

    captureException: (
    exception: any,
    captureContext?: CaptureContext
    ) => ReturnType<Hub['captureException']>;
    • Captures an exception event and sends it to Sentry.

      Parameter exception

      An exception-like object.

      Parameter captureContext

      Additional scope data to apply to exception event.

      Returns

      The generated eventId.

    function captureMessage

    captureMessage: (
    message: string,
    captureContext?: CaptureContext | Severity | SeverityLevel
    ) => ReturnType<Hub['captureMessage']>;
    • Captures a message event and sends it to Sentry.

      Parameter message

      The message to send to Sentry.

      Parameter Severity

      Define the level of the message.

      Returns

      The generated eventId.

    function closeSession

    closeSession: (session: Session, status?: Exclude<SessionStatus, 'ok'>) => void;
    • Closes a session by setting its status and updating the session object with it. Internally calls updateSession to update the passed session object.

      Note that this function mutates the passed session (@see updateSession for explanation).

      Parameter session

      the Session object to be closed

      Parameter status

      the SessionStatus with which the session was closed. If you don't pass a status, this function will keep the previously set status, unless it was 'ok' in which case it is changed to 'exited'.

    function configureScope

    configureScope: (
    callback: (scope: Scope) => void
    ) => ReturnType<Hub['configureScope']>;
    • Callback to set context information onto the scope.

      Parameter callback

      Callback function that receives Scope.

    function createTransport

    createTransport: (
    options: InternalBaseTransportOptions,
    makeRequest: TransportRequestExecutor,
    buffer?: PromiseBuffer<void>
    ) => Transport;
    • Creates an instance of a Sentry Transport

      Parameter options

      Parameter makeRequest

    function getCurrentHub

    getCurrentHub: () => Hub;
    • Returns the default hub instance.

      If a hub is already registered in the global carrier but this module contains a more recent version, it replaces the registered version. Otherwise, the currently registered hub will be returned.

    function getEnvelopeEndpointWithUrlEncodedAuth

    getEnvelopeEndpointWithUrlEncodedAuth: (
    dsn: DsnComponents,
    tunnelOrOptions?: string | ClientOptions
    ) => string;
    • Returns the envelope endpoint URL with auth in the query string.

      Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.

    function getHubFromCarrier

    getHubFromCarrier: (carrier: Carrier) => Hub;
    • This will create a new Hub and add to the passed object on __SENTRY__.hub.

      Parameter carrier

      object

    function getIntegrationsToSetup

    getIntegrationsToSetup: (options: Options) => Integration[];
    • Gets integrations to install

    function getMainCarrier

    getMainCarrier: () => Carrier;
    • Returns the global shim registry.

      FIXME: This function is problematic, because despite always returning a valid Carrier, it has an optional __SENTRY__ property, which then in turn requires us to always perform an unnecessary check at the call-site. We always access the carrier through this function, so we can guarantee that __SENTRY__ is there.

    function getReportDialogEndpoint

    getReportDialogEndpoint: (
    dsnLike: DsnLike,
    dialogOptions: { [key: string]: any; user?: { name?: string; email?: string } }
    ) => string;
    • Returns the url to the report dialog endpoint.

    function initAndBind

    initAndBind: <F extends Client, O extends ClientOptions>(
    clientClass: ClientClass<F, O>,
    options: O
    ) => void;
    • Internal function to create a new SDK client instance. The client is installed and then bound to the current scope.

      Parameter clientClass

      The client class to instantiate.

      Parameter options

      Options to pass to the client.

    function makeMain

    makeMain: (hub: Hub) => Hub;
    • Replaces the current main hub with the passed one on the global object

      Returns

      The old replaced hub

    function makeSession

    makeSession: (context?: Omit<SessionContext, 'started' | 'status'>) => Session;
    • Creates a new Session object by setting certain default parameters. If optional

      Parameter context

      is passed, the passed properties are applied to the session object.

      Parameter context

      (optional) additional properties to be applied to the returned session object

      Returns

      a new Session object

    function setContext

    setContext: (
    name: string,
    context: { [key: string]: any }
    ) => ReturnType<Hub['setContext']>;
    • Sets context data with the given name.

      Parameter name

      of the context

      Parameter context

      Any kind of data. This data will be normalized.

    function setExtra

    setExtra: (key: string, extra: Extra) => ReturnType<Hub['setExtra']>;
    • Set key:value that will be sent as extra data with the event.

      Parameter key

      String of extra

      Parameter extra

      Any kind of data. This data will be normalized.

    function setExtras

    setExtras: (extras: Extras) => ReturnType<Hub['setExtras']>;
    • Set an object that will be merged sent as extra data with the event.

      Parameter extras

      Extras object to merge into current context.

    function setHubOnCarrier

    setHubOnCarrier: (carrier: Carrier, hub: Hub) => boolean;
    • This will set passed Hub on the passed object's __SENTRY__.hub attribute

      Parameter carrier

      object

      Parameter hub

      Hub

      Returns

      A boolean indicating success or failure

    function setTag

    setTag: (key: string, value: Primitive) => ReturnType<Hub['setTag']>;
    • Set key:value that will be sent as tags data with the event.

      Can also be used to unset a tag, by passing undefined.

      Parameter key

      String key of tag

      Parameter value

      Value of tag

    function setTags

    setTags: (tags: { [key: string]: Primitive }) => ReturnType<Hub['setTags']>;
    • Set an object that will be merged sent as tags data with the event.

      Parameter tags

      Tags context object to merge into current context.

    function setUser

    setUser: (user: User | null) => ReturnType<Hub['setUser']>;
    • Updates user context information for future events.

      Parameter user

      User context object to be set in the current context. Pass null to unset the user.

    function startTransaction

    startTransaction: (
    context: TransactionContext,
    customSamplingContext?: CustomSamplingContext
    ) => Transaction;
    • Starts a new Transaction and returns it. This is the entry point to manual tracing instrumentation.

      A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a new child span within the transaction or any span, call the respective .startChild() method.

      Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.

      The transaction must be finished with a call to its .finish() method, at which point the transaction with all its finished child spans will be sent to Sentry.

      NOTE: This function should only be used for *manual* instrumentation. Auto-instrumentation should call startTransaction directly on the hub.

      Parameter context

      Properties of the new Transaction.

      Parameter customSamplingContext

      Information given to the transaction sampling function (along with context-dependent default values). See Options.tracesSampler.

      Returns

      The transaction which was just started

    function updateSession

    updateSession: (session: Session, context?: SessionContext) => void;
    • Updates a session object with the properties passed in the context.

      Note that this function mutates the passed object and returns void. (Had to do this instead of returning a new and updated session because closing and sending a session makes an update to the session after it was passed to the sending logic.

      Parameter session

      the Session to update

      Parameter context

      the SessionContext holding the properties that should be updated in

      Parameter session

      See Also

      • BaseClient.captureSession )

    function withScope

    withScope: (callback: (scope: Scope) => void) => ReturnType<Hub['withScope']>;
    • Creates a new scope with and executes the given operation within. The scope is automatically removed once the operation finishes or throws.

      This is essentially a convenience function for:

      pushScope(); callback(); popScope();

      Parameter callback

      that will be enclosed into push/popScope.

    Classes

    class BaseClient

    abstract class BaseClient<O extends ClientOptions> implements Client<O> {}
    • 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 Client.getOptions.

      If a Dsn is specified in the options, it will be parsed and stored. Use Client.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 BaseClient._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 Client.captureEvent. It will prepare the event and pass it through the callback lifecycle. To issue auto-breadcrumbs, use Client.addBreadcrumb.

      Example 1

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

      // ... }

    constructor

    protected constructor(options: ClientOptions);
    • Initializes this client instance.

      Parameter options

      Options for the client.

    method captureEvent

    captureEvent: (
    event: Event,
    hint?: EventHint,
    scope?: Scope
    ) => string | undefined;

    method captureException

    captureException: (
    exception: any,
    hint?: EventHint,
    scope?: Scope
    ) => string | undefined;

    method captureMessage

    captureMessage: (
    message: string,
    level?: Severity | SeverityLevel,
    hint?: EventHint,
    scope?: Scope
    ) => string | undefined;

    method captureSession

    captureSession: (session: Session) => void;

    method close

    close: (timeout?: number) => PromiseLike<boolean>;

    method eventFromException

    abstract eventFromException: (
    _exception: any,
    _hint?: EventHint
    ) => PromiseLike<Event>;

    method eventFromMessage

    abstract eventFromMessage: (
    _message: string,
    _level?: Severity | SeverityLevel,
    _hint?: EventHint
    ) => PromiseLike<Event>;

    method flush

    flush: (timeout?: number) => PromiseLike<boolean>;

    method getDsn

    getDsn: () => DsnComponents | undefined;

    method getIntegration

    getIntegration: <T extends Integration>(
    integration: IntegrationClass<T>
    ) => T | null;

    method getIntegrationById

    getIntegrationById: (integrationId: string) => Integration | undefined;
    • Gets an installed integration by its id.

      Returns

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

    method getOptions

    getOptions: () => O;

    method getTransport

    getTransport: () => Transport | undefined;

    method recordDroppedEvent

    recordDroppedEvent: (
    reason: EventDropReason,
    category: DataCategory,
    _event?: Event
    ) => void;

    method sendEvent

    sendEvent: (event: Event, hint?: EventHint) => void;

    method sendSession

    sendSession: (session: Session | SessionAggregates) => void;

    method setupIntegrations

    setupIntegrations: () => void;
    • Sets up the integrations

    class FunctionToString

    class FunctionToString implements Integration {}
    • Patch toString calls to return proper name for wrapped functions

    property id

    static id: string;

    property name

    name: string;

    method setupOnce

    setupOnce: () => void;

    class Hub

    class Hub implements HubInterface {}

    constructor

    constructor(client?: Client, scope?: Scope, _version?: number);
    • Creates a new instance of the hub, will push one Layer into the internal stack on creation.

      Parameter client

      bound to the hub.

      Parameter scope

      bound to the hub.

      Parameter version

      number, higher number means higher priority.

    method addBreadcrumb

    addBreadcrumb: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => void;

    method bindClient

    bindClient: (client?: Client) => void;

    method captureEvent

    captureEvent: (event: Event, hint?: EventHint) => string;

    method captureException

    captureException: (exception: any, hint?: EventHint) => string;

    method captureMessage

    captureMessage: (
    message: string,
    level?: Severity | SeverityLevel,
    hint?: EventHint
    ) => string;

    method captureSession

    captureSession: (endSession?: boolean) => void;

    method configureScope

    configureScope: (callback: (scope: Scope) => void) => void;

    method endSession

    endSession: () => void;

    method getClient

    getClient: <C extends Client>() => C | undefined;

    method getIntegration

    getIntegration: <T extends Integration>(
    integration: IntegrationClass<T>
    ) => T | null;

    method getScope

    getScope: () => Scope | undefined;
    • Returns the scope of the top stack.

    method getStack

    getStack: () => Layer[];
    • Returns the scope stack for domains or the process.

    method getStackTop

    getStackTop: () => Layer;
    • Returns the topmost scope layer in the order domain > local > process.

    method isOlderThan

    isOlderThan: (version: number) => boolean;

    method lastEventId

    lastEventId: () => string | undefined;

    method popScope

    popScope: () => boolean;

    method pushScope

    pushScope: () => Scope;

    method run

    run: (callback: (hub: Hub) => void) => void;

    method setContext

    setContext: (name: string, context: { [key: string]: any }) => void;

    method setExtra

    setExtra: (key: string, extra: Extra) => void;

    method setExtras

    setExtras: (extras: Extras) => void;

    method setTag

    setTag: (key: string, value: Primitive) => void;

    method setTags

    setTags: (tags: { [key: string]: Primitive }) => void;

    method setUser

    setUser: (user: User | null) => void;

    method shouldSendDefaultPii

    shouldSendDefaultPii: () => boolean;
    • Returns if default PII should be sent to Sentry and propagated in ourgoing requests when Tracing is used.

    method startSession

    startSession: (context?: SessionContext) => Session;

    method startTransaction

    startTransaction: (
    context: TransactionContext,
    customSamplingContext?: CustomSamplingContext
    ) => Transaction;

    method traceHeaders

    traceHeaders: () => { [key: string]: string };

    method withScope

    withScope: (callback: (scope: Scope) => void) => void;

    class InboundFilters

    class InboundFilters implements Integration {}
    • Inbound filters configurable by the user

    constructor

    constructor(_options?: Partial<InboundFiltersOptions>);

      property id

      static id: string;

      property name

      name: string;

      method setupOnce

      setupOnce: (
      addGlobalEventProcessor: (processor: EventProcessor) => void,
      getCurrentHub: () => Hub
      ) => void;

      class Scope

      class Scope implements ScopeInterface {}
      • Holds additional event information. Scope.applyToEvent will be called by the client before an event will be sent.

      constructor

      constructor();

        method addAttachment

        addAttachment: (attachment: Attachment) => this;

        method addBreadcrumb

        addBreadcrumb: (breadcrumb: Breadcrumb, maxBreadcrumbs?: number) => this;

        method addEventProcessor

        addEventProcessor: (callback: EventProcessor) => this;

        method addScopeListener

        addScopeListener: (callback: (scope: Scope) => void) => void;
        • Add internal on change listener. Used for sub SDKs that need to store the scope.

        method applyToEvent

        applyToEvent: (event: Event, hint?: EventHint) => PromiseLike<Event | null>;
        • Applies data from the scope to the event and runs all event processors on it.

          Parameter event

          Event

          Parameter hint

          Object containing additional information about the original exception, for use by the event processors.

        method clear

        clear: () => this;

        method clearAttachments

        clearAttachments: () => this;

        method clearBreadcrumbs

        clearBreadcrumbs: () => this;

        method clone

        static clone: (scope?: Scope) => Scope;
        • Inherit values from the parent scope.

          Parameter scope

          to clone.

        method getAttachments

        getAttachments: () => Attachment[];

        method getRequestSession

        getRequestSession: () => RequestSession | undefined;

        method getSession

        getSession: () => Session | undefined;

        method getSpan

        getSpan: () => Span | undefined;

        method getTransaction

        getTransaction: () => Transaction | undefined;

        method getUser

        getUser: () => User | undefined;

        method setContext

        setContext: (key: string, context: Context | null) => this;

        method setExtra

        setExtra: (key: string, extra: Extra) => this;

        method setExtras

        setExtras: (extras: Extras) => this;

        method setFingerprint

        setFingerprint: (fingerprint: string[]) => this;

        method setLevel

        setLevel: (level: Severity | SeverityLevel) => this;

        method setRequestSession

        setRequestSession: (requestSession?: RequestSession) => this;

        method setSDKProcessingMetadata

        setSDKProcessingMetadata: (newData: { [key: string]: unknown }) => this;
        • Add data which will be accessible during event processing but won't get sent to Sentry

        method setSession

        setSession: (session?: Session) => this;

        method setSpan

        setSpan: (span?: Span) => this;

        method setTag

        setTag: (key: string, value: Primitive) => this;

        method setTags

        setTags: (tags: { [key: string]: Primitive }) => this;

        method setTransactionName

        setTransactionName: (name?: string) => this;

        method setUser

        setUser: (user: User | null) => this;

        method update

        update: (captureContext?: CaptureContext) => this;

        class SessionFlusher

        class SessionFlusher implements SessionFlusherLike {}

        constructor

        constructor(client: Client, attrs: ReleaseHealthAttributes);

          property flushTimeout

          readonly flushTimeout: number;

            method close

            close: () => void;
            • JSDoc

            method flush

            flush: () => void;
            • Checks if pendingAggregates has entries, and if it does flushes them by calling sendSession

            method getSessionAggregates

            getSessionAggregates: () => SessionAggregates;
            • Massages the entries in pendingAggregates and returns aggregated sessions

            method incrementSessionStatusCount

            incrementSessionStatusCount: () => void;
            • Wrapper function for _incrementSessionStatusCount that checks if the instance of SessionFlusher is enabled then fetches the session status of the request from Scope.getRequestSession().status on the scope and passes them to _incrementSessionStatusCount along with the start date

            Interfaces

            interface Carrier

            interface Carrier {}
            • An object that contains a hub and maintains a scope stack.

            interface Layer

            interface Layer {}
            • A layer in the process stack.

            property client

            client?: Client;

              property scope

              scope?: Scope;

                Type Aliases

                type ClientClass

                type ClientClass<F extends Client, O extends ClientOptions> = new (options: O) => F;
                • A class object that can instantiate Client objects.

                Namespaces

                namespace Integrations

                module 'types/integrations/index.d.ts' {}

                  class FunctionToString

                  class FunctionToString implements Integration {}
                  • Patch toString calls to return proper name for wrapped functions

                  property id

                  static id: string;

                  property name

                  name: string;

                  method setupOnce

                  setupOnce: () => void;

                  class InboundFilters

                  class InboundFilters implements Integration {}
                  • Inbound filters configurable by the user

                  constructor

                  constructor(_options?: Partial<InboundFiltersOptions>);

                    property id

                    static id: string;

                    property name

                    name: string;

                    method setupOnce

                    setupOnce: (
                    addGlobalEventProcessor: (processor: EventProcessor) => void,
                    getCurrentHub: () => Hub
                    ) => void;

                    Package Files (15)

                    Dependencies (3)

                    Dev Dependencies (0)

                    No dev dependencies.

                    Peer Dependencies (0)

                    No peer dependencies.

                    Badge

                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@sentry/core.

                    • Markdown
                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@sentry/core)
                    • HTML
                      <a href="https://www.jsdocs.io/package/@sentry/core"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>