ExceptionTracker component can be used to report exceptions to Rollbar.
Component uses Rollcage client
Following configuration is required when creating component
Additionaly you can set your own handler for Rollbar results.
(constantly nil)
as result-fnExceptionTracker component implements two protocols
start
creates Rollcage client and configures to push all 'Unhandled exceptions' to Rollbarstop
report
method reports given exception to Rollbar
(both exception message and data are sent to Rollbar)wrap-ring
method is intented to be wrapper-fn for ring handler.
It evaluates handler-fn, in case of exception report error to Rollbar and rethrow.
(require '[caliban.tracker.protocol :as proto]
'[caliban.tracker :as tracker])
(def exception-tracker (-> (tracker/create {:token "123" :environment "development})
(component/start))
(proto/report exception-tracker (ex-info "REPORT THIS" {:data "data"}))
(defn handler-setup [handler-fn]
(proto/wrap-ring exception-tracker handler-fn))
For testing purposes or in development mode you can use Mock Component. This will log the exception instead reporting it to Rollbar.
(require '[caliban.tracker.protocol :as proto]
'[caliban.tracker.mock :as mock])
(def m (mock/create))
(proto/report m (ex-info "REPORT MOCK" {}))
You can use caliban without relying on Component with this wrapper namespace:
(require '[caliban.tracker :as tracker]
'[caliban.protocol :as protocol])
;; setup a exception-tracker instance, but do not start it
(def exception-tracker (atom (tracker/create {:token "123" :environment "development})))
;; helper fn to start and stop
(defn stop! []
(reset! exception-tracker (.stop @exception-tracker)))
(defn start! []
(reset! exception-tracker (.start @exception-tracker)))
(defn init! []
(stop!)
(start!))
;; define wrapper fn
;; exception-tracker needs to be initialized in order to use fn below!
(defn report
([error]
(protocol/report @exception-tracker error))
([error request-data]
(protocol/report @exception-tracker error request-data)))
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close