Skip to content

Feature request: HTTP server metrics middleware (RED metrics) #5

Description

@cschanhniem

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:

  1. Add a WithMetrics(meter metric.Meter) option to ionhttp
  2. Register RED metric instruments lazily on first request
  3. Record status code, method, and path from each request/response

Would a PR be welcome?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions