client_python icon indicating copy to clipboard operation
client_python copied to clipboard

docs: add API reference for CollectorRegistry and custom collector classes

Open kkukadia opened this issue 7 months ago • 1 comments

Following the API reference work in #1021 (metric types) and #1161 (pushgateway, textfile, multiprocess), CollectorRegistry and the collector classes have the same gap, examples without formal parameter documentation.

What's missing

CollectorRegistry (no dedicated doc page exists)

The object every user interacts with implicitly (REGISTRY) or explicitly when creating isolated registries. The constructor has undocumented parameters:

  • auto_describe
  • target_info
  • support_collectors_without_names

Undocumented public methods: register(collector), unregister(collector), collect(), restricted_registry(names), get_sample_value(name, labels), get_target_info(), set_target_info()

Custom Collectors (docs/content/collector/custom.md)

Currently 38 lines with a working example. Missing:

  • GaugeMetricFamily(name, documentation, value, labels, unit) — constructor params
  • CounterMetricFamily(name, documentation, value, labels, created, unit, exemplar) — constructor params
  • SummaryMetricFamily(name, documentation, count_value, sum_value, labels, unit) — constructor params
  • HistogramMetricFamily(name, documentation, buckets, sum_value, labels, unit) — constructor params
  • InfoMetricFamily(name, documentation, value, labels) — constructor params
  • add_metric(labels, value) on each family — not formally documented
  • The Collector protocol (describe() and collect()) — only shown by example
  • The mutual exclusivity of value vs labels in MetricFamily constructors — not explained

Built-in Collectors (docs/content/collector/_index.md)

Currently 36 lines. Missing:

  • ProcessCollector(namespace, pid, proc, registry) — proc and registry params undocumented
  • PlatformCollector(registry, platform) — constructor params undocumented
  • GCCollector(registry) — constructor params undocumented
  • How to selectively disable specific default collectors

Proposed approach

Add "## API Reference" sections to each existing page with:

  • Function parameter tables (name, type, default, description)
  • Return values
  • Error conditions
  • A validation script confirming every claim against the source

Source files to reference

  • prometheus_client/registry.py — CollectorRegistry
  • prometheus_client/metrics_core.py — all MetricFamily classes
  • prometheus_client/gc_collector.py — GCCollector
  • prometheus_client/platform_collector.py — PlatformCollector
  • prometheus_client/process_collector.py — ProcessCollector

kkukadia avatar Apr 13 '26 20:04 kkukadia

I'll start working on this immediately :)

kkukadia avatar Apr 13 '26 20:04 kkukadia