import { reducer , TransactionContext , utils } from '../shared' ; import { Span as SpanClass , SpanRecorder } from './span' ; const { isInstanceOf , logger } = utils ; const { getCurrentHub } = reducer ; let instance = null ; export class Transaction extends SpanClass { public name ? : string ; private readonly _hub : any = ( getCurrentHub ( ) as unknown ) as any ; public constructor ( transactionContext , hub ? ) { super ( transactionContext ) ; if ( isInstanceOf ( hub , reducer . Hub ) ) { this . _hub = hub as reducer . Hub ; } if ( transactionContext . name ) { this . name = transactionContext . name ; } } /**
     * JSDoc
     */ public setName ( name ) { this . name = name ; } param maxlen public initSpanRecorder ( ) { if ( ! this . spanRecorder ) { this . spanRecorder = new SpanRecorder ( ) ; } this . spanRecorder . add ( this ) ; } inheritDoc public finish ( endTimestamp ? ) { if ( ! this . name ) { logger . warn ( 'Transaction has no name, falling back to `<unlabeled transaction>`.' ) ; this . name = '<unlabeled transaction>' ; } super . finish ( endTimestamp ) ; const finishedSpans = this . spanRecorder ? this . spanRecorder . spans . filter ( s => s !== this && s . endTimestamp ) : [ ] ; const _finishedSpans = finishedSpans . map ( span => { return { description : span . description , endTimestamp : span . endTimestamp , startTimestamp : span . startTimestamp , } ; } ) ; this . _hub . captureEvent ( { performances : [ { contexts : this . pageContexts , spans : _finishedSpans } ] , type : 'performance' , } ) ; this . pageContexts = [ ] ; this . spanRecorder = new SpanRecorder ( ) ; } static instance ( ctx ? , hub ? ) { if ( instance ) return instance ; instance = new Transaction ( ctx , hub ) ; return instance ; } }