This fork adds status code tracking in recording request writer and, on top of that, an "outcome"
attribute for metrics. The http.status_code attribute (per OpenTelemetry HTTP metrics semantic
conventions) and the fork-specific "outcome" attribute — which lets us easily filter by "success" or
"failure" — are both available fork-wide, including on the semantic-convention metrics
(http.server.request.duration, http.server.response.body.size), not just the legacy ones.
OpenTelemetry instrumentation for go-chi/chi.
Essentially this is an adaptation from otelmux but instead of using gorilla/mux, we use go-chi/chi.
Currently, this library can only instrument traces and metrics.
Contributions are welcomed!
$ go get github.com/ionextai/otelchiSee examples for details.
The metric package provides OpenTelemetry semantic-convention compliant HTTP server metric middleware:
http.server.request.durationhttp.server.active_requestshttp.server.request.body.sizehttp.server.response.body.size
Legacy metric middleware for request_duration_millis, requests_inflight, and response_size_bytes is still available but deprecated.
WithOutcomeFunc(fn func(statusCode int) string)— overrides how theoutcomeattribute is derived from the response status code. Defaults to classifying>= 500as"failure"and everything else (including 4xx) as"success". Use this to redefine the threshold per service, e.g. to also treat429as a failure.WithFilter(filter metric.Filter)— excludes matching requests from all metric recordings (e.g. health checks, readiness probes), so noisy endpoints don't skew histograms and alerting thresholds. Mirrors the tracing package'sWithFilter. The next handler still runs; only the metric recording is skipped.WithExplicitBucketBoundaries(bounds ...float64)— overrides the histogram bucket boundaries used byhttp.server.request.duration, so bucket resolution can be tuned to service-specific SLO/alerting thresholds.
See metric/config.go godoc for details.