Agent skill
database-observability
Instrument database queries, connection pools, and detect N+1 queries
Install this agent skill to your Project
npx add-skill https://github.com/nexus-labs-automation/backend-observability/tree/main/skills/database-observability
SKILL.md
Database Observability
Database is often the bottleneck. Track queries, pools, and patterns.
Query Span Attributes
| Attribute | Example | Required |
|---|---|---|
db.system |
postgresql, mysql | Yes |
db.operation |
SELECT, INSERT | Yes |
db.name |
orders_db | Yes |
db.sql.table |
users | Recommended |
db.statement |
SELECT * FROM users WHERE id = ? | Parameterized only! |
Connection Pool Metrics (USE)
| Metric | Type | Description |
|---|---|---|
db.connections.active |
Gauge | In use |
db.connections.idle |
Gauge | Available |
db.connections.max |
Gauge | Pool limit |
db.connections.wait_count |
Counter | Had to wait |
db.connections.wait_duration |
Histogram | Wait time |
Issues to Detect
| Issue | Detection | Fix |
|---|---|---|
| N+1 queries | >10 identical queries per request | Use eager loading |
| Slow queries | Duration > p95 threshold | Add indexes, optimize |
| Pool exhaustion | wait_count increasing | Increase pool, fix leaks |
Query Wrapper Pattern
Before: Start span (db.system, db.operation, db.sql.table), start timer
After: Record duration, set db.rows_affected, record errors, end span
Pool Monitor Pattern
Every 10s: Record active, idle, wait_count, wait_duration from pool stats
Anti-Patterns
- Full SQL with values → PII risk, use parameterized only
- No pool metrics → Can't detect saturation
- Missing slow query alerts → Problems go unnoticed
References
references/methodology/use-methodology.mdreferences/platforms/{platform}/database.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
slo-alerting
Define SLIs, SLOs, and implement burn-rate alerting
health-checks
Implement liveness, readiness, and dependency health checks
cache-observability
Track cache hit rates, latency, and detect cache-related issues
request-tracing
Instrument HTTP/gRPC endpoints with distributed tracing and RED metrics
error-handling
Capture errors with rich context for debugging and alerting
instrumentation-planning
Plan backend observability using RED + USE + 4 Golden Signals + JTBD
Didn't find tool you were looking for?