-
Notifications
You must be signed in to change notification settings - Fork 30
/
ring.clj
28 lines (25 loc) · 1.1 KB
/
ring.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns raven-clj.ring
(:require [raven-clj.core :refer [capture]]
[raven-clj.interfaces :refer [http stacktrace]]))
;; Limit the size of the extra contextual data
;; https://docs.sentry.io/clientdev/data-handling/
(defn- truncate-extra-str [text]
(subs text 0 (min (count text) 4096)))
(defn capture-error [dsn req ^Throwable error extra app-namespaces http-alter-fn]
(future (capture dsn (-> (merge extra
{:message (.getMessage error)
:extra {:ex-data (truncate-extra-str (str (ex-data error)))}})
(http req http-alter-fn)
(stacktrace error app-namespaces)))))
(defn wrap-sentry [handler dsn & [opts]]
(fn [req]
(let [alter-fn (or (:http-alter-fn opts)
identity)]
(try
(handler req)
(catch Exception e
(capture-error dsn req e (:extra opts) (:namespaces opts) alter-fn)
(throw e))
(catch AssertionError e
(capture-error dsn req e (:extra opts) (:namespaces opts) alter-fn)
(throw e))))))