import { getSearchAggregatedTransactions } from '.' ; import { SearchAggregatedTransactionSetting } from '../../../../common/aggregated_transactions' ; import { Setup } from '../setup_request' ; import { kqlQuery , rangeQuery } from '../../../../../observability/server' ; import { ProcessorEvent } from '../../../../common/processor_event' ; import { APMEventClient } from '../create_es_client/create_apm_event_client' ; export async function getIsUsingTransactionEvents ( { setup : { config , apmEventClient } , kuery , start , end , } ) { const searchAggregatedTransactions = config . searchAggregatedTransactions ; if ( searchAggregatedTransactions === SearchAggregatedTransactionSetting . never ) { return false ; } if ( ! kuery && searchAggregatedTransactions === SearchAggregatedTransactionSetting . always ) { return false ; } const searchesAggregatedTransactions = await getSearchAggregatedTransactions ( { config , start , end , apmEventClient , kuery , } ) ; if ( ! searchesAggregatedTransactions ) { return await getHasTransactions ( { start , end , apmEventClient , kuery , } ) ; } return false ; } async function getHasTransactions ( { start , end , apmEventClient , kuery , } ) { const response = await apmEventClient . search ( 'get_has_transactions' , { apm : { events : [ ProcessorEvent . transaction ] , } , body : { query : { bool : { filter : [ ... ( start && end ? rangeQuery ( start , end ) : [ ] ) , ... kqlQuery ( kuery ) , ] , } , } , } , terminate_after : 1 , } ) ; return response . hits . total . value > 0 ; }