import { first } from 'rxjs/operators' ; import { StartServicesAccessor } from '../../../../../core/public' ; import { METRIC_TYPE , UsageCollectionSetup } from '../../../../usage_collection/public' ; import { SEARCH_EVENT_TYPE , SearchUsageCollector } from './types' ; export const createUsageCollector = ( getStartServices , usageCollection ? ) : SearchUsageCollector => { const getCurrentApp = async ( ) => { const [ { application } ] = await getStartServices ( ) ; return application . currentAppId$ . pipe ( first ( ) ) . toPromise ( ) ; } ; return { trackQueryTimedOut : async ( ) => { const currentApp = await getCurrentApp ( ) ; return usageCollection ?. reportUiStats ( currentApp ! , METRIC_TYPE . LOADED , SEARCH_EVENT_TYPE . QUERY_TIMED_OUT ) ; } , trackQueriesCancelled : async ( ) => { const currentApp = await getCurrentApp ( ) ; return usageCollection ?. reportUiStats ( currentApp ! , METRIC_TYPE . LOADED , SEARCH_EVENT_TYPE . QUERIES_CANCELLED ) ; } , } ; } ;