Error Tracking & Monitoring
This skill provides reusable patterns for integrating error tracking and performance monitoring into services, jobs, and scripts.
While examples may mention Sentry-style APIs, the principles apply to any monitoring backend.
Purpose
- •Ensure failures are observable (no silent failures).
- •Capture enough context to debug (without leaking secrets).
- •Make performance issues diagnosable (traces/spans, slow queries, hot paths).
When to Use
Use this skill when:
- •Adding new endpoints, controllers, or middleware
- •Adding background jobs / scheduled tasks
- •Handling errors from external systems (DB, APIs, queues)
- •Refactoring error handling and logging
- •Adding performance spans or profiling
Core rules
- •Capture exceptions to a monitoring backend (not only
console.error). - •Attach context: service name, environment, operation name, request correlation id (if available), and user identity (if safe).
- •Initialize early: monitoring SDK should be initialized before application logic.
- •Do not leak secrets: redact tokens, passwords, raw PII, and full request bodies unless explicitly approved.
- •Prefer structured logs: logs should be queryable and correlated with traces.
Patterns
Controller / request handler
ts
try {
// handler logic
} catch (err) {
monitor.captureException(err, {
tags: { layer: "controller", route: "your/<route>", method: "POST" },
});
throw err;
}
Background jobs
- •Initialize monitoring at process start.
- •Wrap the job in a single top-level span/transaction.
- •Ensure non-zero exit codes on failure (so infra can detect it).
Performance spans
ts
return monitor.startSpan({ name: "db.query", op: "db" }, async () => {
return await doDatabaseOperation();
});
Checklist (for new code)
- • Monitoring initialized early
- • Exceptions captured with useful tags/context
- • Errors are re-thrown or converted into explicit failure responses (no swallowing)
- • Sensitive fields are redacted
- • Key operations include spans/traces
- • A minimal test exists to verify capture behavior (unit/integration)
Related
- •
/.system/skills/ssot/backend/backend-dev-guidelines/SKILL.md - •
/.system/skills/ssot/frontend/frontend-dev-guidelines/SKILL.md