Skip to content

add a prometheus /metrics endpoint (std.prometheus)#448

Merged
kacy merged 1 commit into
mainfrom
feat/o11y-prometheus
Jul 17, 2026
Merged

add a prometheus /metrics endpoint (std.prometheus)#448
kacy merged 1 commit into
mainfrom
feat/o11y-prometheus

Conversation

@kacy

@kacy kacy commented Jul 17, 2026

Copy link
Copy Markdown
Owner

summary

first phase of observability support. std.prometheus.serve(host, port) runs an
accept loop that answers GET /metrics with the text exposition of every
registered std.metrics series (labels included), 404 otherwise. spawn it
alongside an app and prometheus scrapes it on its interval:

spawn prometheus.serve("0.0.0.0", 9464)

it reuses what exists — metrics.snapshot_text() for the body, the std.net.http
request/response helpers over the raw tcp_accept primitives — so no server
framework is needed. read-only and pull-based; serve() renders the current
snapshot per request, and concurrent scrapes are safe (the metric maps are
mutex-guarded).

part of the observability sprint (prerequisites #441/#445/#446 already landed).
next: std.trace + OTLP export.

what was tested

  • unit test on metrics_response() (prometheus content type + snapshot present)
  • a live self-scrape: spawn serve, GET /metrics over the http client → 200
    with the labeled counter and gauge in the body
  • a new deterministic example examples/prometheus_metrics.pith; 86 examples

pure-additive stdlib; no compiler change, no bootstrap seed refresh.

first phase of observability support. std.prometheus.serve(host, port) runs an
accept loop that answers GET /metrics with the text exposition of every
registered std.metrics series (labels included), and 404 for anything else.
spawn it alongside an app and prometheus scrapes it on its interval:

    spawn prometheus.serve("0.0.0.0", 9464)

it reuses what already exists: metrics.snapshot_text() for the body and the
std.net.http request/response helpers over the raw tcp accept primitives, so no
server framework is needed. the endpoint is read-only and pull-based, so serve()
just renders the current snapshot per request; concurrent scrapes are safe
because the metric maps are mutex-guarded.

verified: a unit test on the response (content type + snapshot), a live
self-scrape (spawn serve, GET /metrics over the http client -> 200 with the
labeled counter and gauge present), a new deterministic example, and 86 examples.
@kacy
kacy merged commit 9ca8ba9 into main Jul 17, 2026
2 checks passed
@kacy
kacy deleted the feat/o11y-prometheus branch July 17, 2026 18:20
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