Skip to content

Commit 43ff451

Browse files
Logging erros to a monitoring service with sentry/next js
1 parent 0b08f39 commit 43ff451

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

utils/error-monitoring.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export function initErrorMonitoring() {
4+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
5+
Sentry.init({
6+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
7+
tracesSampleRate: 1.0,
8+
debug: process.env.NODE_ENV === 'development',
9+
});
10+
}
11+
}
12+
13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14+
export function logError(error: Error, context?: Record<string, any>) {
15+
console.error('Error:', error);
16+
17+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
18+
Sentry.captureException(error, {
19+
extra: context,
20+
});
21+
}
22+
}

0 commit comments

Comments
 (0)