Introduce error boundary mechanism and exception capture with Baselime and Sentry
Deleted the ErrorBoundary component from the makerkit package and introduced new exception capture mechanisms for Baselime and Sentry monitoring providers. The code now captures all exceptions thrown within components and sends them to the configured monitoring provider, which in turn logs the errors for debugging purposes. Updated packages and environment variables accordingly to support this feature.
This commit is contained in:
@@ -1,44 +1,46 @@
|
||||
enum InstrumentationProvider {
|
||||
Baselime = 'baselime',
|
||||
Sentry = 'sentry',
|
||||
}
|
||||
import { InstrumentationProvider } from './monitoring-providers.enum';
|
||||
|
||||
/**
|
||||
* @name DEFAULT_INSTRUMENTATION_PROVIDER
|
||||
* @description Register monitoring instrumentation based on the MONITORING_INSTRUMENTATION_PROVIDER environment variable.
|
||||
* @name MONITORING_PROVIDER
|
||||
* @description Register monitoring instrumentation based on the MONITORING_PROVIDER environment variable.
|
||||
*/
|
||||
const DEFAULT_INSTRUMENTATION_PROVIDER = process.env
|
||||
.MONITORING_INSTRUMENTATION_PROVIDER as InstrumentationProvider | undefined;
|
||||
const MONITORING_PROVIDER = process.env.MONITORING_PROVIDER as
|
||||
| InstrumentationProvider
|
||||
| undefined;
|
||||
|
||||
/**
|
||||
* @name registerMonitoringInstrumentation
|
||||
* @description Register monitoring instrumentation based on the MONITORING_INSTRUMENTATION_PROVIDER environment variable.
|
||||
* @description Register monitoring instrumentation based on the MONITORING_PROVIDER environment variable.
|
||||
*
|
||||
* Please set the MONITORING_INSTRUMENTATION_PROVIDER environment variable to register the monitoring instrumentation provider.
|
||||
* Please set the MONITORING_PROVIDER environment variable to register the monitoring instrumentation provider.
|
||||
*/
|
||||
export async function registerMonitoringInstrumentation() {
|
||||
if (!DEFAULT_INSTRUMENTATION_PROVIDER) {
|
||||
if (!MONITORING_PROVIDER) {
|
||||
console.info(`No instrumentation provider specified. Skipping...`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (DEFAULT_INSTRUMENTATION_PROVIDER) {
|
||||
switch (MONITORING_PROVIDER) {
|
||||
case InstrumentationProvider.Baselime: {
|
||||
const { registerBaselimeInstrumentation } = await import('@kit/baselime');
|
||||
const { registerBaselimeInstrumentation } = await import(
|
||||
'@kit/baselime/instrumentation'
|
||||
);
|
||||
|
||||
return registerBaselimeInstrumentation();
|
||||
}
|
||||
|
||||
case InstrumentationProvider.Sentry: {
|
||||
const { registerSentryInstrumentation } = await import('@kit/sentry');
|
||||
const { registerSentryInstrumentation } = await import(
|
||||
'@kit/sentry/instrumentation'
|
||||
);
|
||||
|
||||
return registerSentryInstrumentation();
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown instrumentation provider: ${DEFAULT_INSTRUMENTATION_PROVIDER as string}`,
|
||||
`Unknown instrumentation provider: ${MONITORING_PROVIDER as string}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user