Imported from bedkillerspacex-boop/codex-skill-library (
python-metrics-catalog/SKILL.md). Install upstream withnpx skills add bedkillerspacex-boop/codex-skill-library --skill python-metrics-catalog. Copyright stays with the author.
Python metrics catalog
Research grounding
Create a governed metrics catalog so Python services emit consistent, low-cardinality,
owned metrics that map to SLOs. Skill id: python-metrics-catalog.
Scope And Authorization
- In scope: your Prometheus/OTel/Datadog/etc. metrics pipelines.
- Out of scope: high-cardinality attacks against shared SaaS; scraping foreign /metrics without authz.
- Prefer OpenTelemetry semantic conventions where applicable.
- Pair with
observability-metrics-tracing,python-monitoring,python-logging-config-dict,code-quality-standards.
When To Use
- Standardizing metric names/labels across microservices.
- Preventing cardinality explosions (
user_idas label). - Cataloging metrics for SLO dashboards and cost control.
Do Not Use As Primary
| Need | Skill instead |
|---|---|
| Alert routing / on-call | python-monitoring |
| Distributed tracing deep dive | observability-metrics-tracing |
| Load test generation | python-load-testing |
| Log fields | python-logging-config-dict |
| Code quality baseline | code-quality-standards |
| Feature flag metrics only | feature-flag-patterns |
Domain Focus
| Area | Guidance |
|---|---|
| Golden signals | latency, traffic, errors, saturation |
| Naming | namespace_subsystem_name_unit (Prometheus style) |
| Labels | bounded enums; never raw ids/emails |
| Catalog fields | name, type, labels, owner, SLO link, retention |
| Python | prometheus_client / OTel metrics SDK wrappers |
Workflow
1. Confirm scope and success criteria
- Metrics backend, cardinality budget, naming standard owner.
- Success: “catalog covers critical services; CI lints new metrics; no unbounded labels.”
- Inventory top series count offenders.
2. Define conventions
| Rule | Example |
|---|---|
| Prefix | billing_http_request_duration_seconds |
| Unit suffix | _seconds, _bytes, _total |
| Label allowlist | method, route_template, status_class, service |
| Forbidden labels | user_id, email, request_id (use traces/logs) |
3. Catalog schema
from dataclasses import dataclass, field
@dataclass
class MetricSpec:
name: str
mtype: str # counter gauge histogram summary
description: str
labels: list[str]
owner: str
slo: str | None = None
retention_days: int = 30
unit: str = ""
def validate(self) -> None:
forbidden = {"user_id", "email", "request_id", "path"}
bad = forbidden.intersection(self.labels)
if bad:
raise ValueError(f"forbidden labels: {bad}")
4. Instrument via shared library
from prometheus_client import Counter, Histogram
REQUESTS = Counter(
"billing_http_requests_total",
"HTTP requests",
["method", "route", "status_class"],
)
LATENCY = Histogram(
"billing_http_request_duration_seconds",
"Request latency",
["method", "route"],
buckets=(0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5),
)
- Use route templates (
/users/{id}) not raw paths. - Central registration: metrics not in catalog fail CI (optional strict mode).
5. Cardinality and cost controls
# Review top metrics by series count in backend
python -m metrics.catalog_lint catalog/*.yaml
python -m pytest tests/test_metric_spec.py -q
- Drop or aggregate high-cost metrics.
- Align retention with
python-log-retentionphilosophy for metrics tiers.
6. SLO linkage
- Each user-facing journey references catalog metrics.
- Alert rules only on cataloged metrics with owners (
python-monitoring). - Document recording rules for expensive queries.
7. Hand off
- Publish catalog site or YAML repo.
- Review process for new metrics (PR template).
- Quarterly cardinality review.
Good / Bad
| Topic | Good | Bad |
|---|---|---|
| Labels | route template | raw URL path |
| Ownership | team per metric | orphan series |
| Creation | PR + lint | Free-for-all names |
| IDs | traces/logs | metric label per user |
| Alerts | On golden signals | Alert on every debug counter |
Output Checklist
- Naming and label policy documented
- Catalog schema and files exist
- Shared instrumentation library adopted
- Lint/CI for forbidden labels
- Cardinality review process
- SLO/alert linkage for critical journeys
- Owners assigned
-
code-quality-standardsapplied
Rules
- Owned telemetry only; do not weaponize cardinality.
- Prefer fewer high-quality metrics over metric sprawl.
- Never put PII in labels.
- Keep secrets out of metric endpoints (auth on /metrics).
- Alerting operations detailed in
python-monitoring.