A Clojure interface to Sentry.
Usage | Ring Middleware | Alternatives | Changes | Contributing
[raven-clj "1.6.0"] ;; latest release
raven-clj.core/capture
is a general use function that can be
placed throughout your Clojure code to log information to your Sentry
server.
(require '[raven-clj.core :refer [capture]])
(def dsn "https://b70a31b3510c4cf793964a185cfe1fd0:b7d80b520139450f903720eb7991bf3d@example.com/1")
(capture dsn {:message "Test Exception Message"
:tags {:version "1.0"}
:logger "main-logger"
:extra {:my-key 1
:some-other-value "foo bar"}})
Various interfaces are supported.
(require '[raven-clj.interfaces :as interfaces])
(capture dsn
(-> {:message "Test HTTP Exception"
:tags {:testing "1.0"}}
(interfaces/http ring-style-request-map)))
;; All namespaces in the following map will be regarded
;; as application code and highlighted in Sentry's stacktraces
;; > Note that this also matches "myapp.ns.core" etc.
(def your-namespace ["myapp.ns"])
(capture dsn
(-> {:message "Test Stacktrace Exception"}
(interfaces/stacktrace (Exception.) your-ns)))
In the capture
function I use merge to merge together the final
packet to send to Sentry. The only fields that can't be overwritten
when sending information to capture
is event-id
and timestamp
.
Everything else can be overwritten by passing along a new value for
the key:
(capture dsn
(-> {:message "Test Stacktrace Exception"
:logger "application-logger"}
(interfaces/stacktrace (Exception.))))
Please refer to Building the JSON Packet for more information on what attributes are allowed within the packet sent to Sentry.
Since 1.6.0-alpha
a function that will install an uncaught exception
handler
is included, see raven-clj.core/install-uncaught-exception-handler!
for details.
raven-clj also includes a Ring middleware that sends the Http and Stacktrace interfaces for Sentry packets. Usage (for Compojure):
(use 'raven-clj.ring)
(def dsn "https://b70a31b3510c4cf793964a185cfe1fd0:b7d80b520139450f903720eb7991bf3d@example.com/1")
;; If you want to fully utilize the Http interface you should make sure
;; you use the wrap-params and wrap-keyword-params middlewares to ensure
;; the request data is stored correctly.
(-> routes
(wrap-sentry dsn)
(handler/site))
;; You could also include some of the optional attributes, pass
;; your app's namespace prefixes so your app's stack frames are
;; highlighted in sentry or specify a function to alter the data
;; that is stored from the HTTP request.
(-> routes
(wrap-sentry dsn {:extra {:tags {:version "1.0"}}
:namespaces ["myapp" "com.mylib"]
:http-alter-fn (fn [r] (dissoc r :data))})
(handler/site))
There are a variety of Clojure libraries for Sentry, a quick, not necessarily up-to-date overview/comparison:
io.sentry/sentry-clj
, the official one. Wraps Sentry's own Java client. Light on dependencies.exoscale/raven
, a newer one. Depends on Netty. Well documented.raven-clj
, the one you're looking at. Similar dependencies as Sentry's own client. Perhaps slightly more ergonomic.sentry_timestamp
header in correct format (Joey Bloom, #28)clj-http-lite
to org.martinklepsch/clj-http-lite
for Java 9+ compatibilityclj-http
to clj-http-lite
raven-clj.core/install-uncaught-exception-handler!
can be used to install an exception handler for uncaught exceptions.clj-http
to 3.0.1
boot build-jar
boot repl
boot test!
boot build-jar push-release
PRs and issues welcome :tada:
Note: Because this library uses it's own version in various
places the version is stored on the classpath. In order to modify
the version you need to modify resources/raven_clj/version.txt
.
Copyright © 2013-2015 Seth Buntin
Distributed under the Eclipse Public License, the same as Clojure.
Can you improve this documentation? These fine people already did:
Seth Buntin, Martin Klepsch, Stefan Friesel, Chris McDevitt & Kendall BuchananEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close