import { BaseClient , Scope , SDK_VERSION } from '@sentry/core' ; import { SessionFlusher } from '@sentry/hub' ; import { Event , EventHint } from '@sentry/types' ; import { logger } from '@sentry/utils' ; import { NodeBackend } from './backend' ; import { NodeOptions } from './types' ; see NodeOptions see SentryClient export class NodeClient extends BaseClient < NodeBackend , NodeOptions > { protected _sessionFlusher : SessionFlusher | undefined ; param options public constructor ( options ) { options . _metadata = options . _metadata || { } ; options . _metadata . sdk = options . _metadata . sdk || { name : 'sentry.javascript.node' , packages : [ { name : 'npm:@sentry/node' , version : SDK_VERSION , } , ] , version : SDK_VERSION , } ; super ( NodeBackend , options ) ; } inheritDoc public captureException ( exception , hint ? , scope ? ) { if ( this . _options . autoSessionTracking && this . _sessionFlusher && scope ) { const requestSession = scope . getRequestSession ( ) ; if ( requestSession && requestSession . status === 'ok' ) { requestSession . status = 'errored' ; } } return super . captureException ( exception , hint , scope ) ; } inheritDoc public captureEvent ( event , hint ? , scope ? ) { if ( this . _options . autoSessionTracking && this . _sessionFlusher && scope ) { const eventType = event . type || 'exception' ; const isException = eventType === 'exception' && event . exception && event . exception . values && event . exception . values . length > 0 ; if ( isException ) { const requestSession = scope . getRequestSession ( ) ; if ( requestSession && requestSession . status === 'ok' ) { requestSession . status = 'errored' ; } } } return super . captureEvent ( event , hint , scope ) ; } inheritdoc public close ( timeout ? ) { this . _sessionFlusher ?. close ( ) ; return super . close ( timeout ) ; } /** Method that initialises an instance of SessionFlusher on Client */ public initSessionFlusher ( ) { const { release , environment } = this . _options ; if ( ! release ) { logger . warn ( 'Cannot initialise an instance of SessionFlusher if no release is provided!' ) ; } else { this . _sessionFlusher = new SessionFlusher ( this . getTransport ( ) , { release , environment , } ) ; } } inheritDoc protected _prepareEvent ( event , scope ? , hint ? ) { event . platform = event . platform || 'node' ; if ( this . getOptions ( ) . serverName ) { event . server_name = this . getOptions ( ) . serverName ; } return super . _prepareEvent ( event , scope , hint ) ; } /**
     * Method responsible for capturing/ending a request session by calling `incrementSessionStatusCount` to increment
     * appropriate session aggregates bucket
     */ protected _captureRequestSession ( ) { if ( ! this . _sessionFlusher ) { logger . warn ( 'Discarded request mode session because autoSessionTracking option was disabled' ) ; } else { this . _sessionFlusher . incrementSessionStatusCount ( ) ; } } }