error-tracking
它能做什么
这个技能在代码中设置 Sentry,这是一项在线错误跟踪服务,使错误被发送到那里供审查。适合运行网络服务、希望看到故障和缓慢调用的开发者。
适用场景
- ✓你为服务添加错误处理或新建控制器的时候。
- ✓你设置了一个应当报告失败情况的定时任务的时候。
- ✓你想跟踪缓慢的数据库调用,或添加性能跨度的时候。
技能链接
https://github.com/diet103/claude-code-infrastructure-showcase/blob/main/.agents/skills/error-tracking/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的新控制器添加 Sentry 错误跟踪,使每个错误都发送到 Sentry。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能展示了将错误和性能数据发送到 Sentry 的标准模式。它提醒智能体要报告每个错误,而不只是记录下来,并涵盖控制器、路由和后台任务。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sentry Integration Skill
Purpose
This skill enforces comprehensive Sentry error tracking and performance monitoring across all 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
Example: API Service ✅ Complete
- Sentry v8 fully integrated
- All workflow errors tracked
- Background job processors instrumented
- Test endpoints available
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
Example of a domain-specific Sentry helper from the original production project. If you build a helper like this for your domain, the call site looks like:
import { WorkflowSentryHelper } from '../workflow/utils/sentryHelper';
WorkflowSentryHelper.captureWorkflowError(error, {
workflowCode: 'INVOICE_APPROVAL',
instanceId: 123,
stepId: 456,
userId: 'user-123',
operation: 'stepCompletion',
metadata: { additionalInfo: 'value' }
});
Without a helper, plain Sentry works everywhere:
Sentry.captureException(error, {
tags: { operation: 'stepCompletion' },
extra: { workflowCode: 'INVOICE_APPROVAL', instanceId: 123, userId: 'user-123' }
});
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
Example from the original production project - a small helper that wraps DB calls in Sentry spans. Adapt to your codebase:
import { DatabasePerformanceMonitor } from '../utils/databasePerformance';
const result = await DatabasePerformanceMonitor.withPerformanceTracking(
'findMany',
'UserProfile',
async () => {
return await PrismaService.main.userProfile.findMany({
take: 5,
});
}
);
The universally-available equivalent is a direct Sentry span:
const result = await Sentry.startSpan({
name: 'db.userProfile.findMany',
op: 'db.query',
attributes: { 'db.model': 'UserProfile', 'db.operation': 'findMany' }
}, async () => {
return await prisma.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
常见问题
什么是 Sentry?
Sentry 是一项在线服务,用于收集软件的错误并展示给开发者。
它只把错误记录到控制台吗?
不是。这个技能说明错误必须发送到 Sentry,而不能只写入控制台。
它涵盖后台任务吗?
涵盖。这个技能包含定时任务和后台处理程序的指导。
详情
作者的原始描述
Add Sentry v8 error tracking and performance monitoring to your 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.
热度
- GitHub 星标
- 10k
- 排名
- #12032
- 许可证
- MIT
- 更新时间
- 2026/7/13
评论
- …