In Sentry initialization file, you can set up Sentry with tracing and profiling, along with advanced configuration options to manage error handling more effectively.
instrument.ts
import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import constants from './constants';
import { httpIntegration } from '@sentry/nestjs';
Sentry.init({
dsn: constants.SENTRY_DNS,
environment: constants.SENTRY_ENVIRONMENT,
includeLocalVariables: true,
integrations: [nodeProfilingIntegration(), httpIntegration()],
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
beforeSend(event, hint) {
const error = hint?.originalException;
if (error && typeof error === 'object' && 'status' in error) {
const statusCode = (error as any).status;
if (statusCode >= 400 && statusCode < 500) {
// Do not send 4xx errors to Sentry
return null;
}
}
return event;
},
});
Create Sentry filter
The Sentry filter allows you to add context to each error, making debugging more insightful by providing request details and user information without exposing sensitive data.