
Error Tracking
- 35 installs
- 16 repo stars
- Updated November 20, 2025
- jackspace/claudeskillz
Add Sentry v8 error tracking and performance monitoring to services - controllers, cron jobs, DB spans - capturing all errors to Sentry.
About
Enforces Sentry v8 error tracking and performance monitoring across services. A developer uses it when adding error handling, creating controllers, instrumenting cron jobs, or tracking database performance.
- Sentry v8 patterns with mandatory error capture
- Performance spans for controllers, cron jobs, and DB calls
Error Tracking by the numbers
- 35 all-time installs (skills.sh)
- Ranked #346 of 597 Debugging skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/jackspace/claudeskillz --skill error-trackingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 35 |
|---|---|
| repo stars | ★ 16 |
| Last updated | November 20, 2025 |
| Repository | jackspace/claudeskillz ↗ |
What it does
Add Sentry v8 error tracking and performance monitoring to services - controllers, cron jobs, DB spans - capturing all errors to Sentry.
Files
your project Sentry Integration Skill
Purpose
This skill enforces comprehensive Sentry error tracking and performance monitoring across all your project services following Sentry v8 patterns.
When to Use This Skill
- Adding error handling to any code
- Creating new controllers or routes
- Instrumenting cron jobs
- Tracking database performance
- Adding performance spans
- Handling workflow errors
🚨 CRITICAL RULE
ALL ERRORS MUST BE CAPTURED TO SENTRY - No exceptions. Never use console.error alone.
Current Status
Form Service ✅ Complete
- Sentry v8 fully integrated
- All workflow errors tracked
- SystemActionQueueProcessor instrumented
- Test endpoints available
Email Service 🟡 In Progress
- Phase 1-2 complete (6/22 tasks)
- 189 ErrorLogger.log() calls remaining
Sentry Integration Patterns
1. Controller Error Handling
// ✅ 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
}
}
}2. Route Error Handling (Without BaseController)
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' });
}
});3. Workflow Error Handling
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' }
});4. Cron Jobs (MANDATORY Pattern)
#!/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);
});5. Database Performance Monitoring
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,
});
}
);6. Async Operations with Spans
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();
});Error Levels
Use appropriate severity levels:
- fatal: System is unusable (database down, critical service failure)
- error: Operation failed, needs immediate attention
- warning: Recoverable issues, degraded performance
- info: Informational messages, successful operations
- debug: Detailed debugging information (dev only)
Required Context
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);
});Service-Specific Integration
Form Service
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 handling
Email Service
Location: ./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
Configuration (config.ini)
[sentry]
dsn = your-sentry-dsn
environment = development
tracesSampleRate = 0.1
profilesSampleRate = 0.1
[databaseMonitoring]
enableDbTracing = true
slowQueryThreshold = 100
logDbQueries = false
dbErrorCapture = true
enableN1Detection = trueTesting Sentry Integration
Form Service Test Endpoints
# 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-boundaryEmail Service Test Endpoints
# 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-performancePerformance Monitoring
Requirements
1. All API endpoints must have transaction tracking 2. Database queries > 100ms are automatically flagged 3. N+1 queries are detected and reported 4. Cron jobs must track execution time
Transaction Tracking
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();
}Common Mistakes to Avoid
❌ 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
Implementation Checklist
When adding Sentry to new code:
- [ ] Imported Sentry or appropriate helper
- [ ] All try/catch blocks capture to Sentry
- [ ] Added meaningful context to errors
- [ ] Used appropriate error level
- [ ] No sensitive data in error messages
- [ ] Added performance tracking for slow operations
- [ ] Tested error handling paths
- [ ] For cron jobs: instrument.ts imported first
Key Files
Form Service
/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
Email Service
/notifications/src/instrument.ts- Sentry initialization/notifications/src/utils/EmailSentryHelper.ts- Email errors/notifications/src/controllers/BaseController.ts- Controller base
Configuration
/blog-api/config.ini- Form service config/notifications/config.ini- Email service config/sentry.ini- Shared Sentry config
Documentation
- Full implementation:
/dev/active/email-sentry-integration/ - Form service docs:
/blog-api/docs/sentry-integration.md - Email service docs:
/notifications/docs/sentry-integration.md
Related Skills
- Use database-verification before database operations
- Use workflow-builder for workflow error context
- Use database-scripts for database error handling
{
"sections": {
"Purpose": "This skill enforces comprehensive Sentry error tracking and performance monitoring across all your project services following Sentry v8 patterns.",
"Documentation": "- Full implementation: `/dev/active/email-sentry-integration/`\r\n- Form service docs: `/blog-api/docs/sentry-integration.md`\r\n- Email service docs: `/notifications/docs/sentry-integration.md`",
"Common Mistakes to Avoid": "❌ **NEVER** use console.error without Sentry\r\n❌ **NEVER** swallow errors silently\r\n❌ **NEVER** expose sensitive data in error context\r\n❌ **NEVER** use generic error messages without context\r\n❌ **NEVER** skip error handling in async operations\r\n❌ **NEVER** forget to import instrument.ts as first line in cron jobs",
"Sentry Integration Patterns": "### 1. Controller Error Handling\r\n\r\n```typescript\r\n// ✅ CORRECT - Use BaseController\r\nimport { BaseController } from '../controllers/BaseController';\r\n\r\nexport class MyController extends BaseController {\r\n async myMethod() {\r\n try {\r\n // ... your code\r\n } catch (error) {\r\n this.handleError(error, 'myMethod'); // Automatically sends to Sentry\r\n }\r\n }\r\n}\r\n```\r\n\r\n### 2. Route Error Handling (Without BaseController)\r\n\r\n```typescript\r\nimport * as Sentry from '@sentry/node';\r\n\r\nrouter.get('/route', async (req, res) => {\r\n try {\r\n // ... your code\r\n } catch (error) {\r\n Sentry.captureException(error, {\r\n tags: { route: '/route', method: 'GET' },\r\n extra: { userId: req.user?.id }\r\n });\r\n res.status(500).json({ error: 'Internal server error' });\r\n }\r\n});\r\n```\r\n\r\n### 3. Workflow Error Handling\r\n\r\n```typescript\r\nimport { WorkflowSentryHelper } from '../workflow/utils/sentryHelper';\r\n\r\n// ✅ CORRECT - Use WorkflowSentryHelper\r\nWorkflowSentryHelper.captureWorkflowError(error, {\r\n workflowCode: 'DHS_CLOSEOUT',\r\n instanceId: 123,\r\n stepId: 456,\r\n userId: 'user-123',\r\n operation: 'stepCompletion',\r\n metadata: { additionalInfo: 'value' }\r\n});\r\n```\r\n\r\n### 4. Cron Jobs (MANDATORY Pattern)\r\n\r\n```typescript\r\n#!/usr/bin/env node\r\n// FIRST LINE after shebang - CRITICAL!\r\nimport '../instrument';\r\nimport * as Sentry from '@sentry/node';\r\n\r\nasync function main() {\r\n return await Sentry.startSpan({\r\n name: 'cron.job-name',\r\n op: 'cron',\r\n attributes: {\r\n 'cron.job': 'job-name',\r\n 'cron.startTime': new Date().toISOString(),\r\n }\r\n }, async () => {\r\n try {\r\n // Your cron job logic\r\n } catch (error) {\r\n Sentry.captureException(error, {\r\n tags: {\r\n 'cron.job': 'job-name',\r\n 'error.type': 'execution_error'\r\n }\r\n });\r\n console.error('[Job] Error:', error);\r\n process.exit(1);\r\n }\r\n });\r\n}\r\n\r\nmain()\r\n .then(() => {\r\n console.log('[Job] Completed successfully');\r\n process.exit(0);\r\n })\r\n .catch((error) => {\r\n console.error('[Job] Fatal error:', error);\r\n process.exit(1);\r\n });\r\n```\r\n\r\n### 5. Database Performance Monitoring\r\n\r\n```typescript\r\nimport { DatabasePerformanceMonitor } from '../utils/databasePerformance';\r\n\r\n// ✅ CORRECT - Wrap database operations\r\nconst result = await DatabasePerformanceMonitor.withPerformanceTracking(\r\n 'findMany',\r\n 'UserProfile',\r\n async () => {\r\n return await PrismaService.main.userProfile.findMany({\r\n take: 5,\r\n });\r\n }\r\n);\r\n```\r\n\r\n### 6. Async Operations with Spans\r\n\r\n```typescript\r\nimport * as Sentry from '@sentry/node';\r\n\r\nconst result = await Sentry.startSpan({\r\n name: 'operation.name',\r\n op: 'operation.type',\r\n attributes: {\r\n 'custom.attribute': 'value'\r\n }\r\n}, async () => {\r\n // Your async operation\r\n return await someAsyncOperation();\r\n});\r\n```",
"Testing Sentry Integration": "curl http://localhost:3003/notifications/api/sentry/test-performance\r\n```",
"Configuration (config.ini)": "```ini\r\n[sentry]\r\ndsn = your-sentry-dsn\r\nenvironment = development\r\ntracesSampleRate = 0.1\r\nprofilesSampleRate = 0.1\r\n\r\n[databaseMonitoring]\r\nenableDbTracing = true\r\nslowQueryThreshold = 100\r\nlogDbQueries = false\r\ndbErrorCapture = true\r\nenableN1Detection = true\r\n```",
"Error Levels": "Use appropriate severity levels:\r\n\r\n- **fatal**: System is unusable (database down, critical service failure)\r\n- **error**: Operation failed, needs immediate attention\r\n- **warning**: Recoverable issues, degraded performance\r\n- **info**: Informational messages, successful operations\r\n- **debug**: Detailed debugging information (dev only)",
"Required Context": "```typescript\r\nimport * as Sentry from '@sentry/node';\r\n\r\nSentry.withScope((scope) => {\r\n // ALWAYS include these if available\r\n scope.setUser({ id: userId });\r\n scope.setTag('service', 'form'); // or 'email', 'users', etc.\r\n scope.setTag('environment', process.env.NODE_ENV);\r\n\r\n // Add operation-specific context\r\n scope.setContext('operation', {\r\n type: 'workflow.start',\r\n workflowCode: 'DHS_CLOSEOUT',\r\n entityId: 123\r\n });\r\n\r\n Sentry.captureException(error);\r\n});\r\n```",
"Performance Monitoring": "### Requirements\r\n\r\n1. **All API endpoints** must have transaction tracking\r\n2. **Database queries > 100ms** are automatically flagged\r\n3. **N+1 queries** are detected and reported\r\n4. **Cron jobs** must track execution time\r\n\r\n### Transaction Tracking\r\n\r\n```typescript\r\nimport * as Sentry from '@sentry/node';\r\n\r\n// Automatic transaction tracking for Express routes\r\napp.use(Sentry.Handlers.requestHandler());\r\napp.use(Sentry.Handlers.tracingHandler());\r\n\r\n// Manual transaction for custom operations\r\nconst transaction = Sentry.startTransaction({\r\n op: 'operation.type',\r\n name: 'Operation Name',\r\n});\r\n\r\ntry {\r\n // Your operation\r\n} finally {\r\n transaction.finish();\r\n}\r\n```",
"Key Files": "### Form Service\r\n- `/blog-api/src/instrument.ts` - Sentry initialization\r\n- `/blog-api/src/workflow/utils/sentryHelper.ts` - Workflow errors\r\n- `/blog-api/src/utils/databasePerformance.ts` - DB monitoring\r\n- `/blog-api/src/controllers/BaseController.ts` - Controller base\r\n\r\n### Email Service\r\n- `/notifications/src/instrument.ts` - Sentry initialization\r\n- `/notifications/src/utils/EmailSentryHelper.ts` - Email errors\r\n- `/notifications/src/controllers/BaseController.ts` - Controller base\r\n\r\n### Configuration\r\n- `/blog-api/config.ini` - Form service config\r\n- `/notifications/config.ini` - Email service config\r\n- `/sentry.ini` - Shared Sentry config",
"Related Skills": "- Use **database-verification** before database operations\r\n- Use **workflow-builder** for workflow error context\r\n- Use **database-scripts** for database error handling",
"Implementation Checklist": "When adding Sentry to new code:\r\n\r\n- [ ] Imported Sentry or appropriate helper\r\n- [ ] All try/catch blocks capture to Sentry\r\n- [ ] Added meaningful context to errors\r\n- [ ] Used appropriate error level\r\n- [ ] No sensitive data in error messages\r\n- [ ] Added performance tracking for slow operations\r\n- [ ] Tested error handling paths\r\n- [ ] For cron jobs: instrument.ts imported first",
"Current Status": "### Form Service ✅ Complete\r\n- Sentry v8 fully integrated\r\n- All workflow errors tracked\r\n- SystemActionQueueProcessor instrumented\r\n- Test endpoints available\r\n\r\n### Email Service 🟡 In Progress\r\n- Phase 1-2 complete (6/22 tasks)\r\n- 189 ErrorLogger.log() calls remaining",
"When to Use This Skill": "- Adding error handling to any code\r\n- Creating new controllers or routes\r\n- Instrumenting cron jobs\r\n- Tracking database performance\r\n- Adding performance spans\r\n- Handling workflow errors",
"🚨 CRITICAL RULE": "**ALL ERRORS MUST BE CAPTURED TO SENTRY** - No exceptions. Never use console.error alone.",
"Service-Specific Integration": "### Form Service\r\n\r\n**Location**: `./blog-api/src/instrument.ts`\r\n\r\n```typescript\r\nimport * as Sentry from '@sentry/node';\r\nimport { nodeProfilingIntegration } from '@sentry/profiling-node';\r\n\r\nSentry.init({\r\n dsn: process.env.SENTRY_DSN,\r\n environment: process.env.NODE_ENV || 'development',\r\n integrations: [\r\n nodeProfilingIntegration(),\r\n ],\r\n tracesSampleRate: 0.1,\r\n profilesSampleRate: 0.1,\r\n});\r\n```\r\n\r\n**Key Helpers**:\r\n- `WorkflowSentryHelper` - Workflow-specific errors\r\n- `DatabasePerformanceMonitor` - DB query tracking\r\n- `BaseController` - Controller error handling\r\n\r\n### Email Service\r\n\r\n**Location**: `./notifications/src/instrument.ts`\r\n\r\n```typescript\r\nimport * as Sentry from '@sentry/node';\r\nimport { nodeProfilingIntegration } from '@sentry/profiling-node';\r\n\r\nSentry.init({\r\n dsn: process.env.SENTRY_DSN,\r\n environment: process.env.NODE_ENV || 'development',\r\n integrations: [\r\n nodeProfilingIntegration(),\r\n ],\r\n tracesSampleRate: 0.1,\r\n profilesSampleRate: 0.1,\r\n});\r\n```\r\n\r\n**Key Helpers**:\r\n- `EmailSentryHelper` - Email-specific errors\r\n- `BaseController` - Controller error handling"
},
"content": "### Form Service Test Endpoints\r\n\r\n```bash\r\ncurl http://localhost:3002/blog-api/api/sentry/test-error\r\n\r\ncurl http://localhost:3002/blog-api/api/sentry/test-workflow-error\r\n\r\ncurl http://localhost:3002/blog-api/api/sentry/test-database-performance\r\n\r\ncurl http://localhost:3002/blog-api/api/sentry/test-error-boundary\r\n```\r\n\r\n### Email Service Test Endpoints\r\n\r\n```bash\r\ncurl http://localhost:3003/notifications/api/sentry/test-error\r\n\r\ncurl http://localhost:3003/notifications/api/sentry/test-email-error",
"id": "error-tracking_diet103",
"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."
}---
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.
---
# your project Sentry Integration Skill
## Purpose
This skill enforces comprehensive Sentry error tracking and performance monitoring across all your project services following Sentry v8 patterns.
## When to Use This Skill
- Adding error handling to any code
- Creating new controllers or routes
- Instrumenting cron jobs
- Tracking database performance
- Adding performance spans
- Handling workflow errors
## 🚨 CRITICAL RULE
**ALL ERRORS MUST BE CAPTURED TO SENTRY** - No exceptions. Never use console.error alone.
## Current Status
### Form Service ✅ Complete
- Sentry v8 fully integrated
- All workflow errors tracked
- SystemActionQueueProcessor instrumented
- Test endpoints available
### Email Service 🟡 In Progress
- Phase 1-2 complete (6/22 tasks)
- 189 ErrorLogger.log() calls remaining
## Sentry Integration Patterns
### 1. Controller Error Handling
```typescript
// ✅ 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
}
}
}
```
### 2. Route Error Handling (Without BaseController)
```typescript
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' });
}
});
```
### 3. Workflow Error Handling
```typescript
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' }
});
```
### 4. Cron Jobs (MANDATORY Pattern)
```typescript
#!/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);
});
```
### 5. Database Performance Monitoring
```typescript
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,
});
}
);
```
### 6. Async Operations with Spans
```typescript
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();
});
```
## Error Levels
Use appropriate severity levels:
- **fatal**: System is unusable (database down, critical service failure)
- **error**: Operation failed, needs immediate attention
- **warning**: Recoverable issues, degraded performance
- **info**: Informational messages, successful operations
- **debug**: Detailed debugging information (dev only)
## Required Context
```typescript
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);
});
```
## Service-Specific Integration
### Form Service
**Location**: `./blog-api/src/instrument.ts`
```typescript
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 errors
- `DatabasePerformanceMonitor` - DB query tracking
- `BaseController` - Controller error handling
### Email Service
**Location**: `./notifications/src/instrument.ts`
```typescript
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 errors
- `BaseController` - Controller error handling
## Configuration (config.ini)
```ini
[sentry]
dsn = your-sentry-dsn
environment = development
tracesSampleRate = 0.1
profilesSampleRate = 0.1
[databaseMonitoring]
enableDbTracing = true
slowQueryThreshold = 100
logDbQueries = false
dbErrorCapture = true
enableN1Detection = true
```
## Testing Sentry Integration
### Form Service Test Endpoints
```bash
# 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
```
### Email Service Test Endpoints
```bash
# 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
```
## Performance Monitoring
### Requirements
1. **All API endpoints** must have transaction tracking
2. **Database queries > 100ms** are automatically flagged
3. **N+1 queries** are detected and reported
4. **Cron jobs** must track execution time
### Transaction Tracking
```typescript
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();
}
```
## Common Mistakes to Avoid
❌ **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
## Implementation Checklist
When adding Sentry to new code:
- [ ] Imported Sentry or appropriate helper
- [ ] All try/catch blocks capture to Sentry
- [ ] Added meaningful context to errors
- [ ] Used appropriate error level
- [ ] No sensitive data in error messages
- [ ] Added performance tracking for slow operations
- [ ] Tested error handling paths
- [ ] For cron jobs: instrument.ts imported first
## Key Files
### Form Service
- `/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
### Email Service
- `/notifications/src/instrument.ts` - Sentry initialization
- `/notifications/src/utils/EmailSentryHelper.ts` - Email errors
- `/notifications/src/controllers/BaseController.ts` - Controller base
### Configuration
- `/blog-api/config.ini` - Form service config
- `/notifications/config.ini` - Email service config
- `/sentry.ini` - Shared Sentry config
## Documentation
- Full implementation: `/dev/active/email-sentry-integration/`
- Form service docs: `/blog-api/docs/sentry-integration.md`
- Email service docs: `/notifications/docs/sentry-integration.md`
## Related Skills
- Use **database-verification** before database operations
- Use **workflow-builder** for workflow error context
- Use **database-scripts** for database error handling