Liking cljdoc? Tell your friends :D


Clojars Project

Ring middleware for sending errors to using the standalone honeybadger library.



(require '[ring.middleware.honeybadger :refer [wrap-honeybadger]])

(def hb-config
  {:api-key "d34db33f"
   :env     "development"})

(def app
  (wrap-honeybadger handler hb-config))


The underlying honeybadger library supports a flexible mechanism called filters for controlling exactly what gets sent to Honeybadger, and under what conditions. There is also a collection of filters for common operations in the honeybadger.filter namespace:

(require '[honeybadger.filter :as hbf])

(def hb-config
  {:api-key "d34db33f"
   :env     "development"
   :filters [(hbf/only   (hbf/env? :production))              ; only report exceptions in prod
             (hbf/except (hbf/instance? ArithmeticException)) ; never report ArithmeticExceptions
             (hbf/obscure-params [[:config :password]         ; replace these params with
                                  [:secret-id])]})            ;   "[FILTERED]" (if present)

For full details, see that library's documentation.


If you'd like to add contextual metadata to the error report you can provide a context-generating function in the config parameter under the :context-fn key. The function will be called with the current request, and it should return a map of metadata which can be serialized to JSON.

This map can contain any information which will help you to make sense of the reported errors, but there are two keys which have special significance to Honeybadger: :user-id and :user-email; these keys are used to show which users are experiencing the reported issue.

(def hb-config
  {:api-key    "d34db33f"
   :env        "development"
   :context-fn (fn [req]
                 {:user-id (auth/current-user-id req)


If you'd like to run code when errors are reported, you can provide a callback function which will be invoked with the reported error and the resultant Honeybadger ID (or nil if reporting was suppressed by a filter). For example:

(defn hb-callback [_err id]
   (if id
     (str "Reported error to Honeybadger with ID " id)
     "Error reporting suppressed by filter")))

(def hb-config
  {:api-key  "d34db33f"
   :env      "development"
   :callback hb-callback})


Copyright © 2015 Cameron Desautels

Distributed under the MIT License.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close