Skip to content

Add telemetry metrics API with structured tags#108

Merged
seriyps merged 2 commits into
epgsql:masterfrom
seriyps:telemetry-metrics
May 15, 2026
Merged

Add telemetry metrics API with structured tags#108
seriyps merged 2 commits into
epgsql:masterfrom
seriyps:telemetry-metrics

Conversation

@seriyps
Copy link
Copy Markdown
Member

@seriyps seriyps commented May 15, 2026

Adds metrics_api = telemetry as a new option alongside the existing folsom and exometer backends. Instead of encoding the pool name in a flat binary metric name, the telemetry backend calls the user module as execute([pooler, MetricName], Measurements, Metadata) where Metadata always carries pool_name and type, and enriched counters also carry reason (e.g. max_lifetime, crashed, at_capacity).

Metric names use clean base atoms without the legacy _count/_rate suffix (free, in_use, take, etc.) and proper types: gauge for point-in-time counts (previously histogram in folsom) and counter for take_rate (previously a folsom meter). Folsom and exometer backends are unchanged in behaviour via compatibility delegate clauses.

Also adds pooler:metrics/0 which returns a descriptor list for all emitted telemetry metrics, intended for pre-declaring prometheus.erl metrics at startup. The return value is a compile-time literal so there is no per-call allocation.

Fixes a pre-existing bug in pooler_sup:pool_child_spec/1 where per-pool metrics_mod/metrics_api config was silently overwritten by the application-level defaults.

seriyps and others added 2 commits May 15, 2026 14:51
Adds metrics_api = telemetry as a new option alongside the existing
folsom and exometer backends. Instead of encoding the pool name in a
flat binary metric name, the telemetry backend calls the user module as
execute([pooler, MetricName], Measurements, Metadata) where Metadata
always carries pool_name and type, and enriched counters also carry
reason (e.g. max_lifetime, crashed, at_capacity).

Metric names use clean base atoms without the legacy _count/_rate suffix
(free, in_use, take, etc.) and proper types: gauge for point-in-time
counts (previously histogram in folsom) and counter for take_rate
(previously a folsom meter). Folsom and exometer backends are unchanged
in behaviour via compatibility delegate clauses.

Also adds pooler:metrics/0 which returns a descriptor list for all
emitted telemetry metrics, intended for pre-declaring prometheus.erl
metrics at startup. The return value is a compile-time literal so there
is no per-call allocation.

Fixes a pre-existing bug in pooler_sup:pool_child_spec/1 where
per-pool metrics_mod/metrics_api config was silently overwritten by the
application-level defaults.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The comment was left in pooler.erl (truncated) when terminate_pid/2 was
extracted to pooler_starter.erl in d7a525f. Restored and moved to
sit above the function it describes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@seriyps seriyps force-pushed the telemetry-metrics branch from 857b3f4 to f8faf23 Compare May 15, 2026 12:57
@seriyps seriyps merged commit 97317d0 into epgsql:master May 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant