import agent from 'elastic-apm-node' ; import { getConfiguration , shouldInstrumentClient } from '@kbn/apm-config-loader' ; export const getApmConfig = ( requestPath ) => { const baseConfig = getConfiguration ( 'kibana-frontend' ) ; if ( ! shouldInstrumentClient ( baseConfig ) ) { return null ; } const config = { ... baseConfig , pageLoadTransactionName : requestPath , } ; const backendTransaction = agent . currentTransaction ; if ( backendTransaction ) { const { sampled , traceId } = backendTransaction as any ; return { ... config , pageLoadTraceId : traceId , pageLoadSampled : sampled , pageLoadSpanId : backendTransaction . ensureParentId ( ) , } ; } return config ; } ;