• Version 6.19.7
  • Published
  • 309 kB
  • 3 dependencies
  • BSD-3-Clause license


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


Sentry hub which handles global state managment.



function addGlobalEventProcessor

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

    Parameter callback

    EventProcessor to add

function getActiveDomain

getActiveDomain: () => DomainAsCarrier | undefined;
  • Returns the active domain, if one exists


    The domain, or undefined if there is no active domain


    No longer used; remove in v7

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 getHubFromCarrier

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

    Parameter carrier


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 makeMain

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


    The old replaced hub

function setHubOnCarrier

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

    Parameter carrier


    Parameter hub



    A boolean indicating success or failure


class Hub

class Hub implements HubInterface {}


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, 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 startSession

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

method startSpan

startSpan: (context: SpanContext) => Span;

method startTransaction

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

method traceHeaders

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

method withScope

withScope: (callback: (scope: Scope) => void) => 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.

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 the current context and fingerprint to the event. Note that breadcrumbs will be added by the client. Also if the event has already breadcrumbs on it, we do not merge them.

    Parameter event


    Parameter hint

    May contain additional information about the original exception.

method clear

clear: () => this;

method clearBreadcrumbs

clearBreadcrumbs: () => this;

method clone

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

    Parameter scope

    to clone.

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) => 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 setTransaction

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

method setTransactionName

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

method setUser

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

method update

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

class Session

class Session implements SessionInterface {}


constructor(context?: Omit<SessionContext, 'started' | 'status'>);

    property did

    did?: string;

      property duration

      duration?: number;

        property environment

        environment?: string;

          property errors

          errors: number;

            property ignoreDuration

            ignoreDuration: boolean;

              property init

              init: boolean;

                property ipAddress

                ipAddress?: string;

                  property release

                  release?: string;

                    property sid

                    sid: string;

                      property started

                      started: number;

                        property status

                        status: SessionStatus;

                          property timestamp

                          timestamp: number;

                            property userAgent

                            userAgent?: string;

                              method close

                              close: (status?: Exclude<SessionStatus, 'ok'>) => void;
                              • JSDoc

                              method toJSON

                              toJSON: () => {
                              init: boolean;
                              sid: string;
                              did?: string;
                              timestamp: string;
                              started: string;
                              duration?: number;
                              status: SessionStatus;
                              errors: number;
                              attrs?: {
                              release?: string;
                              environment?: string;
                              user_agent?: string;
                              ip_address?: string;
                              • JSDoc

                              method update

                              update: (context?: SessionContext) => void;
                              • JSDoc

                              class SessionFlusher

                              class SessionFlusher implements SessionFlusherLike {}


                              constructor(transport: Transport, 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 sendSessions

                                  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

                                  method sendSessionAggregates

                                  sendSessionAggregates: (sessionAggregates: SessionAggregates) => void;
                                  • Sends session aggregates to Transport


                                  interface Carrier

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

                                  interface DomainAsCarrier

                                  interface DomainAsCarrier extends Carrier {}
                                  • Deprecated

                                    Can be removed once Hub.getActiveDomain is removed.

                                  property members

                                  members: {
                                  [key: string]: any;

                                    interface Layer

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

                                    property client

                                    client?: Client;

                                      property scope

                                      scope?: Scope;

                                        Package Files (5)

                                        Dependencies (3)

                                        Dev Dependencies (0)

                                        No dev dependencies.

                                        Peer Dependencies (0)

                                        No peer dependencies.


                                        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/hub.

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