import Fs from 'fs' ; import { Client , HttpConnection } from '@elastic/elasticsearch' ; import { apm , createLogger , LogLevel } from '@elastic/apm-synthtrace' ; import { CA_CERT_PATH } from '@kbn/dev-utils' ; type { Cypress . PluginConfig } const plugin = ( on , config ) => { const node = config . env . ES_NODE ; const requestTimeout = config . env . ES_REQUEST_TIMEOUT ; const isCloud = config . env . TEST_CLOUD ; const client = new Client ( { node , requestTimeout , Connection : HttpConnection , ... ( isCloud ? { tls : { ca : Fs . readFileSync ( CA_CERT_PATH , 'utf-8' ) } } : { } ) , } ) ; const synthtraceEsClient = new apm . ApmSynthtraceEsClient ( client , createLogger ( LogLevel . info ) ) ; on ( 'task' , { 'synthtrace:index' : async ( events ) => { await synthtraceEsClient . index ( events ) ; return null ; } , 'synthtrace:clean' : async ( ) => { await synthtraceEsClient . clean ( ) ; return null ; } , } ) ; } ; module . exports = plugin ;