A Clojure interface to Sentry.
Usage | Ring Middleware | Alternatives | Changes | Contributing
[raven-clj "1.7.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:[email protected]/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:[email protected]/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.
- 1.7.0
- Fix parsing of project id number from sentry.io which caused an integer overflow. It now parses to long instead of integer. (Emil Bengtsson, #33)
- Bump to clj-http-lite to org.clj-commons/clj-http-lite 1.0.13. Note it has switched to clj-commons
- Bump to Cheshire 5.11.0
- Bump to prone 2021-04-23
- 1.6.0
- Bump to Cheshire 5.9.0 (Kevin W. van Rooijen, #29)
- 1.6.0-alpha4
- Supply
sentry_timestamp
header in correct format (Joey Bloom, #28)
- Supply
- 1.6.0-alpha3
- Support query params in DSNs (Jean-Samuel Bédard, #27)
- 1.6.0-alpha2
- Switch from
clj-http-lite
toorg.martinklepsch/clj-http-lite
for Java 9+ compatibility
- Switch from
- 1.6.0-alpha
- Switch from
clj-http
toclj-http-lite
- New!
raven-clj.core/install-uncaught-exception-handler!
can be used to install an exception handler for uncaught exceptions.
- Switch from
- 1.5.2
- Support new secret-less DSNs
- 1.5.1
- Prevent indexOutOfBounds exception when determining context line (#25)
- 1.5.0
- 1.4.3
- 1.4.2
- add missing requires
- 1.4.1 (defunct)
- actually depend on prone prone
- 1.4.0 (defunct)
- 1.3.2
- update
clj-http
to3.0.1
- update
- Build and install the jar with
lein jar
- Start a repl with
lein repl
- Run tests with
lein test
- Deploy a release with
lein deploy clojars
PRs and issues welcome 🎉
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.