@sentry/hub

  • Version 6.12.0
  • Published
  • 280 kB
  • 3 dependencies
  • BSD-3-Clause license

Install

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

Overview

Sentry hub which handles global state managment.

Index

Functions

function addGlobalEventProcessor

addGlobalEventProcessor: (callback: any) => 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

    Returns

    The domain, or undefined if there is no active domain

    Deprecated

    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

    object

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

    Returns

    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

    object

    Parameter hub

    Hub

    Returns

    A boolean indicating success or failure

Classes

class Hub

class Hub implements HubInterface {}

constructor

constructor(client?: any, 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: any, hint?: any) => void;

method bindClient

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

method captureEvent

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

method captureException

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

method captureMessage

captureMessage: (message: string, level?: any, hint?: any) => string;

method captureSession

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

method configureScope

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

method endSession

endSession: () => void;

method getClient

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

method getIntegration

getIntegration: <T extends any>(integration: any) => 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: any) => void;

method setExtras

setExtras: (extras: any) => void;

method setTag

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

method setTags

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

method setUser

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

method startSession

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

method startSpan

startSpan: (context: any) => any;

method startTransaction

startTransaction: (context: any, customSamplingContext?: any) => any;

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: any, maxBreadcrumbs?: number) => this;

method addEventProcessor

addEventProcessor: (callback: any) => 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: any, hint?: any) => 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

    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: any) => this;

method setExtras

setExtras: (extras: any) => this;

method setFingerprint

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

method setLevel

setLevel: (level: any) => this;

method setRequestSession

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

method setSession

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

method setSpan

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

method setTag

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

method setTags

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

method setTransaction

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

method setTransactionName

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

method setUser

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

method update

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

class Session

class Session implements SessionInterface {}

constructor

constructor(context?: Omit<any, '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: any;

                          property timestamp

                          timestamp: number;

                            property userAgent

                            userAgent?: string;

                              method close

                              close: (status?: Exclude<SessionStatus, 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?: any) => void;
                              • JSDoc

                              class SessionFlusher

                              class SessionFlusher implements SessionFlusherLike {}

                              constructor

                              constructor(transport: any, 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: () => any;
                                  • 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: any) => void;
                                  • Sends session aggregates to Transport

                                  Interfaces

                                  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 (6)

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

                                        • Markdown
                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@sentry/hub)
                                        • 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>