/
sentry.clj
33 lines (29 loc) · 1.37 KB
/
sentry.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
29
30
31
32
33
(ns ziggurat.sentry
"Sentry reporting functions used by both Ziggurat and the actor."
(:require [clojure.tools.logging :as log]
[mount.core :refer [defstate]]
[sentry-clj.async :as sentry]
[ziggurat.config :refer [ziggurat-config]])
(:gen-class
:name tech.gojek.ziggurat.internal.Sentry
:methods [^{:static true} [reportError [Throwable String] java.util.concurrent.Future]]))
(defn create-sentry-reporter []
(let [sentry-config (merge (:sentry (ziggurat-config))
{:sync? false
:env (:env (ziggurat-config))
:app-name (:app-name (ziggurat-config))})]
(log/info "Initialising sentry reporter with config " {:config sentry-config})
(sentry/create-reporter sentry-config)))
(defstate sentry-reporter
:start (create-sentry-reporter)
:stop (when (and (-> (ziggurat-config) :sentry :enabled) sentry-reporter)
(log/info "Shutting down sentry reporter")
(sentry/shutdown-reporter sentry-reporter)))
(defmacro report-error
"Logs an exception and reports it to Sentry.
Create an exception using ex-info if you don't have an exception but
still want to report to Sentry."
[^Throwable error & msgs]
`(sentry/report-error sentry-reporter ~error ~@msgs))
(defn -reportError [^Throwable error msg]
(report-error error msg))