             response-status (get response :status 404)
             response-path (get (meta response) :path "unspecified")
             request-time (/ (double (- finish-time start-time)) 1000.0)]
-        (record-request-metric counter histogram request-method response-status request-time response-path)
+        (record-request-metric metrics-store app-name request-method response-status request-time response-path)
         response))))
 
 (defn dump-metrics

      response)
    response))

(defn- record-request-metric [counter histogram request-method response-status request-time response-path]
  (let [status-class (str (int (/ response-status 100)) "XX")
        method-label (string/upper-case (name request-method))
        labels [method-label (str response-status) status-class response-path]]
    (-> (histogram-with-labels histogram labels) (.observe request-time))
    (-> (counter-with-labels counter labels) (.inc))))

(defn instrument-handler
  "Ring middleware to record request metrics"
  [handler ^String app-name ^CollectorRegistry registry]
  (let [counter (make-request-counter app-name registry)
        histogram (make-request-histogram app-name registry)]
    (fn [request]
      (let [request-method (:request-method request)
            start-time (System/currentTimeMillis)

    (io.prometheus.client Counter Histogram Counter$Child Histogram$Child CollectorRegistry Gauge Gauge$Child)))

; more useful set of buckets for microservice APIs than the defaults provided by the Histogram class
(def request-latency-histogram-buckets (atom [0.001, 0.005, 0.010, 0.020, 0.050, 0.100, 0.200, 0.300, 0.500, 0.750, 1, 5]))

(defn- ^Counter$Child counter-with-labels [^Counter counter label-array] (.labels counter (into-array String label-array)))

