This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-01
Channels
- # beginners (59)
- # cider (3)
- # clara (4)
- # cljsjs (4)
- # clojure (144)
- # clojure-finland (2)
- # clojure-italy (10)
- # clojure-russia (2)
- # clojure-spec (7)
- # clojure-uk (53)
- # clojurescript (81)
- # cursive (30)
- # datomic (36)
- # defnpodcast (2)
- # editors (3)
- # emacs (4)
- # events (1)
- # fulcro (12)
- # off-topic (11)
- # onyx (14)
- # parinfer (2)
- # pedestal (12)
- # re-frame (3)
- # reagent (26)
- # shadow-cljs (81)
- # spacemacs (10)
- # sql (59)
- # uncomplicate (4)
- # yada (4)
I'm kind of lost in interceptors, I would like to log response status code and duration, how can I do that?
You can create an interceptor with an :enter
and :leave
implementation which, on enter, appends a timestamp to the context and, on leave, calculates the difference and logs it as well as the status code
@ddeaguiar excellent answer, I'll give it a try
You can add some headers then it will appear on chrome/firefox network tab
(def http-timming-header
{:name ::http-timming-header
:enter (fn [ctx] (assoc-in ctx [:request :inst] (new Date)))
:leave (fn [{{:keys [inst]} :request
:as ctx}]
(let [diff (-> (time.coerce/to-date-time inst)
(time/interval (time/now))
(time/in-millis))]
(assoc-in ctx [:response :headers "Server-Timing"]
(format "app=%s; \"My App\"" diff))))})
I wonder what approaches are there if you want to measure the time taken for every interceptor individually.
Interleave :chain
with appropriate interceptors? Update :enter
& :leave
handlers of interceptors to include this?