Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

move to a new sentry exception interceptor

Blue Mouse2719543195ce
diff --git a/apps/production/src/analytics/analytics.controller.ts b/apps/production/src/analytics/analytics.controller.ts
index 5b2332a5f..1397d1e15 100644
--- a/apps/production/src/analytics/analytics.controller.ts
+++ b/apps/production/src/analytics/analytics.controller.ts
@@ -1086,6 +1086,8 @@ export class AnalyticsController {
REDIS_EVENTS_COUNT_KEY,
)
+ throw new Error('Test Sentry error')
+
if (exists) {
const users = _toNumber(await redis.get(REDIS_USERS_COUNT_KEY))
const projects = _toNumber(await redis.get(REDIS_PROJECTS_COUNT_KEY))
diff --git a/apps/production/src/common/interceptors/sentry.interceptor.ts b/apps/production/src/common/interceptors/sentry.interceptor.ts
deleted file mode 100644
index df6c5fb0a..000000000
--- a/apps/production/src/common/interceptors/sentry.interceptor.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import {
- CallHandler,
- ExecutionContext,
- Injectable,
- NestInterceptor,
-} from '@nestjs/common'
-import { tap } from 'rxjs'
-import * as Sentry from '@sentry/node'
-
-@Injectable()
-export class SentryInterceptor implements NestInterceptor {
- intercept(_context: ExecutionContext, next: CallHandler) {
- return next.handle().pipe(
- tap({
- error: exception => {
- Sentry.captureException(exception)
- },
- }),
- )
- }
-}
diff --git a/apps/production/src/main.ts b/apps/production/src/main.ts
index 2f4d1519c..5a2ab1341 100644
--- a/apps/production/src/main.ts
+++ b/apps/production/src/main.ts
@@ -1,4 +1,4 @@
-import { NestFactory } from '@nestjs/core'
+import { NestFactory, BaseExceptionFilter, HttpAdapterHost } from '@nestjs/core'
import { ValidationPipe, VersioningType } from '@nestjs/common'
import * as cookieParser from 'cookie-parser'
import * as bodyParser from 'body-parser'
@@ -9,25 +9,26 @@ import { ConfigService } from '@nestjs/config'
import * as Sentry from '@sentry/node'
import { isDevelopment, sentryIgnoreErrors } from './common/constants'
import { AppModule } from './app.module'
-import { SentryInterceptor } from './common/interceptors/sentry.interceptor'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
const configService = app.get(ConfigService)
- const isSentryEnabled = configService.getOrThrow<boolean>('SENTRY_ENABLED')
+ const isSentryEnabled = configService.get<boolean>('SENTRY_ENABLED')
if (isSentryEnabled) {
const isProduction = configService.get<string>('NODE_ENV') === 'production'
Sentry.init({
dsn: configService.get<string>('SENTRY_DSN'),
- tracesSampleRate: isProduction ? 0.1 : 1.0,
+ tracesSampleRate: isProduction ? 0.2 : 1.0,
ignoreErrors: sentryIgnoreErrors,
})
- app.useGlobalInterceptors(new SentryInterceptor())
+ const { httpAdapter } = app.get(HttpAdapterHost)
+
+ Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter))
}
app.use(cookieParser())
diff --git a/package.json b/package.json
index 9b1eba98a..03f1b9db6 100644
--- a/package.json
+++ b/package.json
@@ -41,7 +41,7 @@
"@nestjs/terminus": "^10.2.3",
"@nestjs/typeorm": "^10.0.1",
"@paypal/payouts-sdk": "^1.1.1",
- "@sentry/node": "^7.86.0",
+ "@sentry/node": "^8.0.0-rc.3",
"axios": "^1.6.8",
"bcrypt": "^5.1.1",
"blake3": "^2.1.7",