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
+41
View File
@@ -0,0 +1,41 @@
{
"name": "@kit/monitoring-core",
"private": true,
"sideEffects": false,
"version": "0.1.0",
"scripts": {
"clean": "git clean -xdf .turbo node_modules",
"format": "prettier --check \"**/*.{ts,tsx}\"",
"lint": "eslint .",
"typecheck": "tsc --noEmit"
},
"prettier": "@kit/prettier-config",
"exports": {
".": "./src/index.ts"
},
"devDependencies": {
"@kit/eslint-config": "workspace:*",
"@kit/prettier-config": "workspace:*",
"@kit/tailwind-config": "workspace:*",
"@kit/tsconfig": "workspace:*",
"@types/react": "^18.2.79",
"react": "18.2.0"
},
"peerDependencies": {
"react": "^18.2.0"
},
"eslintConfig": {
"root": true,
"extends": [
"@kit/eslint-config/base",
"@kit/eslint-config/react"
]
},
"typesVersions": {
"*": {
"*": [
"src/*"
]
}
}
}
@@ -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)}`,
);
}
}
+3
View File
@@ -0,0 +1,3 @@
export * from './monitoring.service';
export * from './monitoring.context';
export * from './console-monitoring.service';
@@ -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(),
);
@@ -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;
}
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "@kit/tsconfig/base.json",
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"exclude": ["node_modules"]
}