agentleFS
roborracleroborracle/agent-workflow-kit/skills/error-observability/SKILL.md

error-observability

Skill0 starsChanged 3 months agoMITView on GitHub

Implement structured error handling, logging, metrics, and observability. Covers error hierarchies, correlation IDs, log levels, alerting thresholds, and health check endpoints.

The file

Files
SKILL.md

Error Handling & Observability

Error Hierarchy Design

Base Error Structure

class AppError extends Error {
  constructor(
    message: string,
    public readonly code: string,        // Machine-readable: "AUTH_TOKEN_EXPIRED"
    public readonly statusCode: number,   // HTTP status: 401
    public readonly isOperational: boolean, // true = expected, false = programmer error
    public readonly context?: Record<string, unknown>
  ) {
    super(message);
    this.name = this.constructor.name;
  }
}

Error Categories

CategoryRetry?Alert?Log LevelExample
ValidationNoNowarnInvalid email format
AuthenticationNoOn spikewarnExpired token
AuthorizationNoOn spikewarnInsufficient permissions
Not FoundNoNoinfoResource doesn't exist
ConflictNoNowarnDuplicate entry
Rate LimitYes (backoff)On thresholdwarnToo many requests
Upstream FailureYes (circuit breaker)YeserrorThird-party API down
InternalNoYeserrorNull pointer, type error
InfrastructureYes (limited)Yes (page)fatalDatabase unreachable

Decision Tree: Retry vs. Fail

Is the error transient?
├── Yes → Has retry budget remaining?
│   ├── Yes → Retry with exponential backoff (base * 2^attempt + jitter)
│   └── No → Fail with "service temporarily unavailable"
└── No → Is it a client error (4xx)?
    ├── Yes → Return error to client with helpful message
    └── No → Log, alert, return generic 500

Structured Logging

Log Format (JSON)

{
  "timestamp": "ISO-8601 timestamp",
  "level": "error",
  "message": "Payment processing failed",
  "correlationId": "req-abc123",
  "service": "payment-service",
  "traceId": "trace-xyz789",
  "error": { "code": "PAYMENT_DECLINED", "message": "Card declined by issuer" }
}

Log Level Guidelines

LevelWhenExample
debugDevelopment-only detailVariable values, query parameters
infoNormal operations worth recordingRequest completed, user logged in, job finished
warnUnexpected but handledRetry succeeded, deprecated API used, rate limit approaching
errorFailure requiring investigationUpstream timeout, unhandled rejection, data inconsistency
fatalSystem cannot continueDatabase connection lost, out of memory, config missing

What to NEVER Log

  • Passwords, tokens, API keys, session IDs
  • Full credit card numbers, SSNs, or PII
  • Request/response bodies containing user data (log a hash or ID instead)
  • Conversation or message content

Correlation IDs

  • Generate a unique ID at the entry point (API gateway, message consumer)
  • Pass it through every function call, database query, and outgoing HTTP request
  • Include it in every log line and error response
  • Return it to the client for support reference

Health Check Endpoints

Liveness (/health/live)

Returns 200 if the process is running. No dependency checks.

Readiness (/health/ready)

Returns 200 only if all critical dependencies are reachable:

{
  "status": "healthy",
  "checks": {
    "database": { "status": "up", "latency_ms": 12 },
    "cache": { "status": "up", "latency_ms": 3 },
    "upstream_api": { "status": "up", "latency_ms": 89 }
  }
}

Alerting Thresholds

MetricWarningCriticalAction
Error rate (5xx)> 1% of requests> 5% of requestsPage on-call
Latency (p95)> 500ms> 2000msInvestigate
Queue depth> 1000> 10000Scale consumers
Disk usage> 80%> 95%Expand storage
Memory usage> 85%> 95%Investigate leaks

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.