import { Client , Transport , HttpConnection } from '@elastic/elasticsearch' ; import type { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana' ; import type { TransportRequestParams , TransportRequestOptions , TransportResult , } from '@elastic/elasticsearch' ; import { Logger } from '../../logging' ; import { parseClientOptions , ElasticsearchClientConfig } from './client_config' ; import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation' ; const noop = ( ) => undefined ; export const configureClient = ( config , { logger , type , scoped = false , getExecutionContext = noop , } ) : KibanaClient => { const clientOptions = parseClientOptions ( config , scoped ) ; class KibanaTransport extends Transport { request ( params , options ? ) { const opts = options || { } ; const opaqueId = getExecutionContext ( ) ; if ( opaqueId && ! opts . opaqueId ) { opts . opaqueId = opaqueId ; } if ( opts . meta === undefined ) { opts . meta = true ; } return super . request ( params , opts ) as Promise < TransportResult < any , any > > ; } } const client = new Client ( { ... clientOptions , Transport : KibanaTransport , Connection : HttpConnection , } ) ; instrumentEsQueryAndDeprecationLogger ( { logger , client , type } ) ; return client as KibanaClient ; } ;