import { name, autoService, location } from 'knifecycle'; import { type LogService } from 'common-services'; import { type JsonValue } from 'type-fest'; export type WhookAPMDependencies = { log: LogService; }; export type WhookAPMService = ( type: T, data: JsonValue, ) => void; export default location(name('apm', autoService(initAPM)), import.meta.url); const noop = () => undefined; /** * Application monitoring service that simply log stringified contents. * @function * @param {Object} services * The services to inject * @param {Function} [services.log] * A logging function * @return {Promise} * A promise of the apm service. */ async function initAPM({ log = noop, }: WhookAPMDependencies): Promise> { log('debug', '❤️ - Initializing the APM service.'); return (type, data) => log('info', type, JSON.stringify(data)); }