import { getCurrentHub , Hub , Scope } from '../../hub' ; import { Breadcrumb , CaptureContext , Event , Transaction , TransactionContext } from '../../types' ; import { getGlobalObject , isString , logger , truncate } from '../../utils' ; param method param args function callOnHub < T > ( method , ... args ) { const hub = getCurrentHub ( ) ; if ( hub && hub [ method as keyof Hub ] ) { return ( hub [ method as keyof Hub ] as any ) ( ... args ) ; } throw new Error ( `No hub defined or ${ method } was not found on the hub, please open a bug report.` ) ; } param exception returns export function captureException ( exception , captureContext ? ) { let syntheticException ; try { throw new Error ( 'Beidou syntheticException' ) ; } catch ( exception ) { syntheticException = exception as Error ; } return callOnHub ( 'captureException' , exception , { captureContext , originalException : exception , syntheticException , } ) ; } param event returns export function captureEvent ( event ) { return callOnHub ( 'captureEvent' , event ) ; } param breadcrumb export function addBreadcrumb ( breadcrumb ) { callOnHub < void > ( 'addBreadcrumb' , breadcrumb ) ; } param callback export function withScope ( callback ) { callOnHub < void > ( 'withScope' , callback ) ; } param method param args hidden export function _callOnClient ( method , ... args ) { callOnHub < void > ( '_invokeClient' , method , ... args ) ; } param context export function startTransaction ( context ) { return callOnHub ( 'startTransaction' , { ... context } ) ; } param metric param alias export function pageLoadTrace ( metric , alias ? ) { if ( metric . slice ( 0 , 4 ) !== 'LOAD' ) return ; const globalObject = getGlobalObject ( ) ; let startTime = Date . now ( ) ; if ( globalObject ?. performance ?. timeOrigin ) { startTime = performance . timeOrigin ; } else if ( globalObject ?. __WBAPP__ ?. buzStart ) { startTime = globalObject ?. __PERFORMANCE__ ?. in || globalObject . __WBAPP__ . buzStart ; } callOnHub < void > ( 'captureEvent' , { performances : [ { contexts : [ { description : metric , time : Date . now ( ) - startTime , extra : encodeURIComponent ( JSON . stringify ( { name : alias } ) ) } ] , spans : [ ] } ] , type : 'performance' , } ) ; } export param { Custom } data export function addCustomBreadcrumb ( text ) { if ( ! isString ( text ) ) { return ; } let content = truncate ( text , 500 ) ; const event = { type : 'breadcrumb' , breadcrumbs : [ { type : 'custom' , text : encodeURIComponent ( content ) , } , ] , } ; callOnHub < void > ( 'captureEvent' , event ) ; logger . log ( '2' , event ) ; }