zio-http
zio-http copied to clipboard
Metric middleware labels based on response
Currently we only allow passing labels when providing the metric middleware (https://github.com/zio/zio-http/blob/b43dbc478e1f387c6de60bdab0b99dfbc1de3e6f/zio-http/src/main/scala/zio/http/Middleware.scala#L260).
What do you think about making this effectful and allow providing these based on request+response? It can be useful when you want to segment metrics on, for example, cache hit or similar only known at response time.
Perhaps a new version can be introduced, to avoid negatively impacting the performance of the existing version?
I think you don't need to make this effectful, except you want to access the body of the request/response or need state to carry over from the request to the response (response time for example). Accessing things like headers, status code and query params can be done in pure functions. That is the same for the logging middlewares we have.
Yeah, we could initially provide two pure callbacks for labels from request
, and labels from response
, (we probably would have one that provides both in practice), which would be a big upgrade already. But as you said, with restrictions. I think it would be worth adding the restricted form at least, and that should not be very impactful to performance.