Registry API Refactoring (#144)
* Refactor core to use a flexible registry pattern - Introduce a new registry mechanism for mailer providers - Extract mailer provider enum to a separate file - Implement dynamic mailer loading using a registry - Update package dependencies and exports - Improve modularity and extensibility of mailer implementation * Refactor monitoring and billing services to use a flexible registry pattern - Introduce a shared registry mechanism for dynamic service loading - Replace static switch-based implementations with a registry-based approach - Update instrumentation, CMS, and monitoring services to use the new registry - Improve modularity and extensibility of service implementations - Add Zod-based type-safe provider validation * Simplify async registration in monitoring and billing services - Remove unnecessary async wrappers for no-op registrations - Update type definitions to support both async and sync registration functions - Standardize registration approach for Paddle and Sentry providers * Remove Tailwind package from packages where it is not being needed * Remove Tailwind config references from pnpm-lock.yaml * Update instrumentation registry to support dynamic monitoring providers - Modify type definition to use NonNullable MonitoringProvider - Import MonitoringProvider type from get-monitoring-provider - Enhance type safety for instrumentation registration
This commit is contained in:
committed by
GitHub
parent
3140f0cf21
commit
4a47df81db
@@ -1,42 +1,52 @@
|
||||
import { ConsoleMonitoringService } from '@kit/monitoring-core';
|
||||
import {
|
||||
ConsoleMonitoringService,
|
||||
MonitoringService,
|
||||
} from '@kit/monitoring-core';
|
||||
import { createRegistry } from '@kit/shared/registry';
|
||||
|
||||
import { getMonitoringProvider } from '../get-monitoring-provider';
|
||||
import { InstrumentationProvider } from '../monitoring-providers.enum';
|
||||
import {
|
||||
MonitoringProvider,
|
||||
getMonitoringProvider,
|
||||
} from '../get-monitoring-provider';
|
||||
|
||||
const MONITORING_PROVIDER = getMonitoringProvider();
|
||||
// create a registry for the server monitoring services
|
||||
const serverMonitoringRegistry = createRegistry<
|
||||
MonitoringService,
|
||||
NonNullable<MonitoringProvider>
|
||||
>();
|
||||
|
||||
// Register the 'baselime' monitoring service
|
||||
serverMonitoringRegistry.register('baselime', async () => {
|
||||
const { BaselimeServerMonitoringService } = await import(
|
||||
'@kit/baselime/server'
|
||||
);
|
||||
|
||||
return new BaselimeServerMonitoringService();
|
||||
});
|
||||
|
||||
// Register the 'sentry' monitoring service
|
||||
serverMonitoringRegistry.register('sentry', async () => {
|
||||
const { SentryMonitoringService } = await import('@kit/sentry');
|
||||
|
||||
return new SentryMonitoringService();
|
||||
});
|
||||
|
||||
// if you have a new monitoring provider, you can register it here
|
||||
//
|
||||
|
||||
/**
|
||||
* @name getServerMonitoringService
|
||||
* @description Get the monitoring service based on the MONITORING_PROVIDER environment variable.
|
||||
*/
|
||||
export async function getServerMonitoringService() {
|
||||
if (!MONITORING_PROVIDER) {
|
||||
const provider = getMonitoringProvider();
|
||||
|
||||
if (!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 { SentryMonitoringService } = await import('@kit/sentry');
|
||||
|
||||
return new SentryMonitoringService();
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new Error(
|
||||
`Please set the MONITORING_PROVIDER environment variable to register the monitoring instrumentation provider.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return serverMonitoringRegistry.get(provider);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user