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,13 @@
import { MonitoringService } from '@kit/monitoring-core';
export class ConsoleMonitoringService implements MonitoringService {
identifyUser() {
// noop
}
captureException(error: Error) {
console.error(
`[Console Monitoring] Caught exception: ${JSON.stringify(error)}`,
);
}
}

View File

@@ -0,0 +1,3 @@
export * from './monitoring.service';
export * from './monitoring.context';
export * from './console-monitoring.service';

View File

@@ -0,0 +1,8 @@
import { createContext } from 'react';
import { ConsoleMonitoringService } from './console-monitoring.service';
import { MonitoringService } from './monitoring.service';
export const MonitoringContext = createContext<MonitoringService>(
new ConsoleMonitoringService(),
);

View File

@@ -0,0 +1,22 @@
/**
* Monitoring service interface
* @description This service is used to capture exceptions and identify users in the monitoring service
* @example
*/
export abstract class MonitoringService {
/**
* Capture an exception
* @param error
* @param extra
*/
abstract captureException<Extra extends object>(
error: Error & { digest?: string },
extra?: Extra,
): unknown;
/**
* Identify a user in the monitoring service - used for tracking user actions
* @param info
*/
abstract identifyUser<Info extends { id: string }>(info: Info): unknown;
}