Refactor monitoring services into separate packages

Separated and isolated the responsibilities of monitoring tools. Reorganized the code by introducing a core package that contains common code related to monitoring and moved all the service operations like error capturing and identification of users into their respective packages. This ensures each tool is independent and easy to maintain.
This commit is contained in:
giancarlo
2024-04-24 09:02:02 +07:00
parent a004cbae63
commit 34d9034e65
31 changed files with 210 additions and 96 deletions

View File

@@ -0,0 +1,44 @@
import { ConsoleMonitoringService } from '@kit/monitoring-core';
import { getMonitoringProvider } from '../get-monitoring-provider';
import { InstrumentationProvider } from '../monitoring-providers.enum';
const MONITORING_PROVIDER = getMonitoringProvider();
/**
* @name getServerMonitoringService
* @description Get the monitoring service based on the MONITORING_PROVIDER environment variable.
*/
export async function getServerMonitoringService() {
if (!MONITORING_PROVIDER) {
console.info(
`No instrumentation provider specified. Returning console service...`,
);
return new ConsoleMonitoringService();
}
switch (MONITORING_PROVIDER) {
case InstrumentationProvider.Baselime: {
const { BaselimeServerMonitoringService } = await import(
'@kit/baselime/server'
);
return new BaselimeServerMonitoringService();
}
case InstrumentationProvider.Sentry: {
const { SentryServerMonitoringService } = await import(
'@kit/sentry/server'
);
return new SentryServerMonitoringService();
}
default: {
throw new Error(
`Please set the MONITORING_PROVIDER environment variable to register the monitoring instrumentation provider.`,
);
}
}
}