The ionhttp package currently instruments HTTP servers and clients with OpenTelemetry tracing via otelhttp. This gives teams distributed trace visibility for each request.
However, production services commonly also need RED metrics (Rate, Errors, Duration) collected automatically at the HTTP middleware layer — without each handler manually creating and recording counter/histogram instruments.
What is missing
A middleware that automatically captures per-route metrics:
http.requests.total (counter, by method + path + status)
http.requests.active (updown counter)
http.request.duration (histogram, by method + path)
http.requests.error_total (counter, by method + path + error cause)
Why now
The ionhttp.Handler() already takes Option arguments. Adding metrics collection would follow the same pattern:
handler := ionhttp.Handler(mux, "api",
ionhttp.WithMetrics(meter), // new option
ionhttp.WithFilter(healthFilter),
)
The OTel contrib package go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp now supports metrics via otelhttp.WithMeterProvider(), so this could build on existing infrastructure rather than re-inventing.
I am happy to implement this if the direction sounds right — the scope would be:
- Add a
WithMetrics(meter metric.Meter) option to ionhttp
- Register RED metric instruments lazily on first request
- Record status code, method, and path from each request/response
Would a PR be welcome?
The
ionhttppackage currently instruments HTTP servers and clients with OpenTelemetry tracing viaotelhttp. This gives teams distributed trace visibility for each request.However, production services commonly also need RED metrics (Rate, Errors, Duration) collected automatically at the HTTP middleware layer — without each handler manually creating and recording counter/histogram instruments.
What is missing
A middleware that automatically captures per-route metrics:
http.requests.total(counter, by method + path + status)http.requests.active(updown counter)http.request.duration(histogram, by method + path)http.requests.error_total(counter, by method + path + error cause)Why now
The
ionhttp.Handler()already takesOptionarguments. Adding metrics collection would follow the same pattern:The OTel contrib package
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttpnow supports metrics viaotelhttp.WithMeterProvider(), so this could build on existing infrastructure rather than re-inventing.I am happy to implement this if the direction sounds right — the scope would be:
WithMetrics(meter metric.Meter)option toionhttpWould a PR be welcome?