clj-commons / clj-commons/metrics-clojure
Support ring metrics for asynchronous requests
- Dominant language
- Clojure
- Stars
- 349
- Forks
- 80
- PR merge metrics
- No merged PRs in 30d
Description
The Aleph web server, built on top of Netty, gives the option of returning a manifold deferred object in addition to the standard ring response map. This allows the request to be carried out asynchronously.
The current `instrument` middleware assumes a synchronous implementation. It would be great if async was supported as well.
It wouldn't be much work to get this working. Something along the lines of:
``` clojure
(defn wrap-metrics
[handler]
(fn [req]
(start-metrics)
(let [resp (handler req)]
(if (instance? manifold.deferred.Deferred resp)
(on-realized resp stop-metrics)
(stop-metrics))
resp)))
```
Of course, it means introducing manifold as a dependency. It's a small library though, and only introduces a couple of transitive dependencies.
Happy to submit a PR for this.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.