// Add Sentry v8 error tracking and performance monitoring to your project services. Use this skill when adding error handling, creating new controllers, instrumenting cron jobs, or tracking database performance. ALL ERRORS MUST BE CAPTURED TO SENTRY - no exceptions.
| name | error-tracking |
| description | Add Sentry v8 error tracking and performance monitoring to your project services. Use this skill when adding error handling, creating new controllers, instrumenting cron jobs, or tracking database performance. ALL ERRORS MUST BE CAPTURED TO SENTRY - no exceptions. |
This skill enforces comprehensive Sentry error tracking and performance monitoring across all your project services following Sentry v8 patterns.
ALL ERRORS MUST BE CAPTURED TO SENTRY - No exceptions. Never use console.error alone.
// โ
CORRECT - Use BaseController
import { BaseController } from '../controllers/BaseController';
export class MyController extends BaseController {
async myMethod() {
try {
// ... your code
} catch (error) {
this.handleError(error, 'myMethod'); // Automatically sends to Sentry
}
}
}
import * as Sentry from '@sentry/node';
router.get('/route', async (req, res) => {
try {
// ... your code
} catch (error) {
Sentry.captureException(error, {
tags: { route: '/route', method: 'GET' },
extra: { userId: req.user?.id }
});
res.status(500).json({ error: 'Internal server error' });
}
});
import { WorkflowSentryHelper } from '../workflow/utils/sentryHelper';
// โ
CORRECT - Use WorkflowSentryHelper
WorkflowSentryHelper.captureWorkflowError(error, {
workflowCode: 'DHS_CLOSEOUT',
instanceId: 123,
stepId: 456,
userId: 'user-123',
operation: 'stepCompletion',
metadata: { additionalInfo: 'value' }
});
#!/usr/bin/env node
// FIRST LINE after shebang - CRITICAL!
import '../instrument';
import * as Sentry from '@sentry/node';
async function main() {
return await Sentry.startSpan({
name: 'cron.job-name',
op: 'cron',
attributes: {
'cron.job': 'job-name',
'cron.startTime': new Date().toISOString(),
}
}, async () => {
try {
// Your cron job logic
} catch (error) {
Sentry.captureException(error, {
tags: {
'cron.job': 'job-name',
'error.type': 'execution_error'
}
});
console.error('[Job] Error:', error);
process.exit(1);
}
});
}
main()
.then(() => {
console.log('[Job] Completed successfully');
process.exit(0);
})
.catch((error) => {
console.error('[Job] Fatal error:', error);
process.exit(1);
});
import { DatabasePerformanceMonitor } from '../utils/databasePerformance';
// โ
CORRECT - Wrap database operations
const result = await DatabasePerformanceMonitor.withPerformanceTracking(
'findMany',
'UserProfile',
async () => {
return await PrismaService.main.userProfile.findMany({
take: 5,
});
}
);
import * as Sentry from '@sentry/node';
const result = await Sentry.startSpan({
name: 'operation.name',
op: 'operation.type',
attributes: {
'custom.attribute': 'value'
}
}, async () => {
// Your async operation
return await someAsyncOperation();
});
Use appropriate severity levels:
import * as Sentry from '@sentry/node';
Sentry.withScope((scope) => {
// ALWAYS include these if available
scope.setUser({ id: userId });
scope.setTag('service', 'form'); // or 'email', 'users', etc.
scope.setTag('environment', process.env.NODE_ENV);
// Add operation-specific context
scope.setContext('operation', {
type: 'workflow.start',
workflowCode: 'DHS_CLOSEOUT',
entityId: 123
});
Sentry.captureException(error);
});
Location: ./blog-api/src/instrument.ts
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV || 'development',
integrations: [
nodeProfilingIntegration(),
],
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
});
Key Helpers:
WorkflowSentryHelper - Workflow-specific errorsDatabasePerformanceMonitor - DB query trackingBaseController - Controller error handlingLocation: ./notifications/src/instrument.ts
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV || 'development',
integrations: [
nodeProfilingIntegration(),
],
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
});
Key Helpers:
EmailSentryHelper - Email-specific errorsBaseController - Controller error handling[sentry]
dsn = your-sentry-dsn
environment = development
tracesSampleRate = 0.1
profilesSampleRate = 0.1
[databaseMonitoring]
enableDbTracing = true
slowQueryThreshold = 100
logDbQueries = false
dbErrorCapture = true
enableN1Detection = true
# Test basic error capture
curl http://localhost:3002/blog-api/api/sentry/test-error
# Test workflow error
curl http://localhost:3002/blog-api/api/sentry/test-workflow-error
# Test database performance
curl http://localhost:3002/blog-api/api/sentry/test-database-performance
# Test error boundary
curl http://localhost:3002/blog-api/api/sentry/test-error-boundary
# Test basic error capture
curl http://localhost:3003/notifications/api/sentry/test-error
# Test email-specific error
curl http://localhost:3003/notifications/api/sentry/test-email-error
# Test performance tracking
curl http://localhost:3003/notifications/api/sentry/test-performance
import * as Sentry from '@sentry/node';
// Automatic transaction tracking for Express routes
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
// Manual transaction for custom operations
const transaction = Sentry.startTransaction({
op: 'operation.type',
name: 'Operation Name',
});
try {
// Your operation
} finally {
transaction.finish();
}
โ NEVER use console.error without Sentry โ NEVER swallow errors silently โ NEVER expose sensitive data in error context โ NEVER use generic error messages without context โ NEVER skip error handling in async operations โ NEVER forget to import instrument.ts as first line in cron jobs
When adding Sentry to new code:
/blog-api/src/instrument.ts - Sentry initialization/blog-api/src/workflow/utils/sentryHelper.ts - Workflow errors/blog-api/src/utils/databasePerformance.ts - DB monitoring/blog-api/src/controllers/BaseController.ts - Controller base/notifications/src/instrument.ts - Sentry initialization/notifications/src/utils/EmailSentryHelper.ts - Email errors/notifications/src/controllers/BaseController.ts - Controller base/blog-api/config.ini - Form service config/notifications/config.ini - Email service config/sentry.ini - Shared Sentry config/dev/active/email-sentry-integration//blog-api/docs/sentry-integration.md/notifications/docs/sentry-integration.md