Skip to content

Instantly share code, notes, and snippets.

@wavejumper
Created February 15, 2015 07:22
Show Gist options
  • Save wavejumper/ed92bf6fb542f7e9dff6 to your computer and use it in GitHub Desktop.
Save wavejumper/ed92bf6fb542f7e9dff6 to your computer and use it in GitHub Desktop.
observe-ring.clj
(ns foo.core
(:require [clojure.core.match :refer (match)]
[compojure.core :refer :all]))
(defn metrics [req resp]
(match [req resp]
[{:uri "/login"} {:status 401}]
(println "Failed login")
[{} {:status 500}]
(println "Application error")
:else (println "Nothing to report!")))
(defn wrap-observe [handler observable-fn]
(fn [req]
(let [resp (handler req)]
(future (observable-fn req resp))
resp)))
(def app
(routes (GET "/" [] "OK")))
(wrap-observe app metrics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment