Refactor monitoring package and improve error handling
The monitoring package has been significantly refactored to improve the granularity of error capture. Code from the 'capture-exception.ts' files in different locations have been deleted and replaced by a more unified approach in the 'use-baselime.ts' and 'use-sentry.ts' hooks. The README documentation has also been updated to reflect these changes and provide additional information about error monitoring setup and usage.
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
|
||||
export function captureException(error: Error & { digest?: string }) {
|
||||
return Sentry.captureException(error);
|
||||
}
|
||||
1
packages/monitoring/sentry/src/client.ts
Normal file
1
packages/monitoring/sentry/src/client.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './hooks/use-sentry';
|
||||
12
packages/monitoring/sentry/src/hooks/use-sentry.ts
Normal file
12
packages/monitoring/sentry/src/hooks/use-sentry.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { SentryServerMonitoringService } from '../services/sentry-server-monitoring.service';
|
||||
|
||||
/**
|
||||
* @name useSentry
|
||||
* @description Get the Sentry monitoring service. Sentry can be used in the browser and server - so we don't need to differentiate between the two.
|
||||
* @returns {SentryServerMonitoringService}
|
||||
*/
|
||||
export function useSentry(): SentryServerMonitoringService {
|
||||
return useMemo(() => new SentryServerMonitoringService(), []);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './capture-exception';
|
||||
1
packages/monitoring/sentry/src/server.ts
Normal file
1
packages/monitoring/sentry/src/server.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './services/sentry-server-monitoring.service';
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
|
||||
import { MonitoringService } from '../../../src/services/monitoring.service';
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @implements {MonitoringService}
|
||||
* ServerSentryMonitoringService is responsible for capturing exceptions and identifying users using the Sentry monitoring service.
|
||||
*/
|
||||
export class SentryServerMonitoringService implements MonitoringService {
|
||||
captureException(error: Error | null) {
|
||||
return Sentry.captureException(error);
|
||||
}
|
||||
|
||||
identifyUser(user: Sentry.User) {
|
||||
Sentry.setUser(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user