import { TRACE_ID , TRANSACTION_ID , } from '../../../../common/elasticsearch_fieldnames' ; import { rangeQuery , termQuery } from '../../../../../observability/server' ; import { Setup } from '../../../lib/helpers/setup_request' ; import { ProcessorEvent } from '../../../../common/processor_event' ; import { asMutableArray } from '../../../../common/utils/as_mutable_array' ; export async function getTransaction ( { transactionId , traceId , setup , start , end , } ) { const { apmEventClient } = setup ; const resp = await apmEventClient . search ( 'get_transaction' , { apm : { events : [ ProcessorEvent . transaction ] , } , body : { size : 1 , query : { bool : { filter : asMutableArray ( [ { term : { [ TRANSACTION_ID ] : transactionId } } , ... termQuery ( TRACE_ID , traceId ) , ... ( start && end ? rangeQuery ( start , end ) : [ ] ) , ] ) , } , } , } , } ) ; return resp . hits . hits [ 0 ] ?. _source ; }