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:
@@ -11,6 +11,7 @@
|
||||
"prettier": "@kit/prettier-config",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./instrumentation": "./src/instrumentation.ts",
|
||||
"./config/client": "./src/config/sentry.client.config.ts",
|
||||
"./config/server": "./src/config/sentry.server.config.ts",
|
||||
"./config/edge": "./src/config/sentry.server.edge.ts"
|
||||
|
||||
5
packages/monitoring/sentry/src/capture-exception.ts
Normal file
5
packages/monitoring/sentry/src/capture-exception.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
|
||||
export function captureException(error: Error & { digest?: string }) {
|
||||
return Sentry.captureException(error);
|
||||
}
|
||||
@@ -1,36 +1 @@
|
||||
const INSTRUMENTATION_SERVICE_NAME = process.env.INSTRUMENTATION_SERVICE_NAME;
|
||||
|
||||
if (!INSTRUMENTATION_SERVICE_NAME) {
|
||||
throw new Error(`
|
||||
You have set the Sentry instrumentation provider, but have not set the INSTRUMENTATION_SERVICE_NAME environment variable. Please set the INSTRUMENTATION_SERVICE_NAME environment variable.
|
||||
`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name registerSentryInstrumentation
|
||||
* @description This file is used to register Sentry instrumentation for your Next.js application.
|
||||
*
|
||||
* Please set the MONITORING_INSTRUMENTATION_PROVIDER environment variable to 'sentry' to register Sentry instrumentation.
|
||||
*/
|
||||
export async function registerSentryInstrumentation() {
|
||||
const { Resource } = await import('@opentelemetry/resources');
|
||||
const { NodeSDK } = await import('@opentelemetry/sdk-node');
|
||||
|
||||
const { SEMRESATTRS_SERVICE_NAME } = await import(
|
||||
'@opentelemetry/semantic-conventions'
|
||||
);
|
||||
|
||||
const { SentrySpanProcessor, SentryPropagator } = await import(
|
||||
'@sentry/opentelemetry-node'
|
||||
);
|
||||
|
||||
const sdk = new NodeSDK({
|
||||
resource: new Resource({
|
||||
[SEMRESATTRS_SERVICE_NAME]: INSTRUMENTATION_SERVICE_NAME,
|
||||
}),
|
||||
spanProcessor: new SentrySpanProcessor(),
|
||||
textMapPropagator: new SentryPropagator(),
|
||||
});
|
||||
|
||||
sdk.start();
|
||||
}
|
||||
export { captureException } from './capture-exception';
|
||||
|
||||
36
packages/monitoring/sentry/src/instrumentation.ts
Normal file
36
packages/monitoring/sentry/src/instrumentation.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
const INSTRUMENTATION_SERVICE_NAME = process.env.INSTRUMENTATION_SERVICE_NAME;
|
||||
|
||||
if (!INSTRUMENTATION_SERVICE_NAME) {
|
||||
throw new Error(`
|
||||
You have set the Sentry instrumentation provider, but have not set the INSTRUMENTATION_SERVICE_NAME environment variable. Please set the INSTRUMENTATION_SERVICE_NAME environment variable.
|
||||
`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name registerSentryInstrumentation
|
||||
* @description This file is used to register Sentry instrumentation for your Next.js application.
|
||||
*
|
||||
* Please set the MONITORING_INSTRUMENTATION_PROVIDER environment variable to 'sentry' to register Sentry instrumentation.
|
||||
*/
|
||||
export async function registerSentryInstrumentation() {
|
||||
const { Resource } = await import('@opentelemetry/resources');
|
||||
const { NodeSDK } = await import('@opentelemetry/sdk-node');
|
||||
|
||||
const { SEMRESATTRS_SERVICE_NAME } = await import(
|
||||
'@opentelemetry/semantic-conventions'
|
||||
);
|
||||
|
||||
const { SentrySpanProcessor, SentryPropagator } = await import(
|
||||
'@sentry/opentelemetry-node'
|
||||
);
|
||||
|
||||
const sdk = new NodeSDK({
|
||||
resource: new Resource({
|
||||
[SEMRESATTRS_SERVICE_NAME]: INSTRUMENTATION_SERVICE_NAME,
|
||||
}),
|
||||
spanProcessor: new SentrySpanProcessor(),
|
||||
textMapPropagator: new SentryPropagator(),
|
||||
});
|
||||
|
||||
sdk.start();
|
||||
}
|
||||
Reference in New Issue
Block a user