mirror of https://github.com/status-im/timbre.git
[#215] PR housekeeping
This commit is contained in:
parent
1a434293a3
commit
1c007f2e16
|
@ -1,7 +1,5 @@
|
||||||
(ns taoensso.timbre.appenders.3rd-party.sentry
|
(ns taoensso.timbre.appenders.3rd-party.sentry
|
||||||
"Sentry appender
|
"Sentry appender. Requires https://github.com/sethtrain/raven-clj."
|
||||||
|
|
||||||
Requires https://github.com/sethtrain/raven-clj"
|
|
||||||
{:author "Samuel Otter (@samuelotter)"}
|
{:author "Samuel Otter (@samuelotter)"}
|
||||||
(:require
|
(:require
|
||||||
[taoensso.encore :as enc]
|
[taoensso.encore :as enc]
|
||||||
|
@ -9,55 +7,64 @@
|
||||||
[raven-clj.core :as raven]
|
[raven-clj.core :as raven]
|
||||||
[raven-clj.interfaces :as interfaces]))
|
[raven-clj.interfaces :as interfaces]))
|
||||||
|
|
||||||
(def ^:private levels {:fatal "fatal"
|
(def ^:private timbre->sentry-levels
|
||||||
:error "error"
|
{:trace "debug"
|
||||||
:warn "warning"
|
:debug "debug"
|
||||||
:info "info"
|
:info "info"
|
||||||
:debug "debug"
|
:warn "warning"
|
||||||
:trace "debug"})
|
:error "error"
|
||||||
|
:fatal "fatal"
|
||||||
|
:report "info"})
|
||||||
|
|
||||||
(defn sentry-appender
|
(defn sentry-appender
|
||||||
"Creates a sentry-appender. Requires the DSN (e.g.
|
"Returns a raven-clj Sentry appender.
|
||||||
\"https://<key>:<secret>@sentry.io/<project>\", see sentry documentation) to
|
|
||||||
be passed in.
|
|
||||||
|
|
||||||
opts may contain additional attributes:
|
Requires the DSN (e.g. \"https://<key>:<secret>@sentry.io/<project>\")
|
||||||
|
to be passed in, see Sentry documentation for details.
|
||||||
|
|
||||||
|
Common options:
|
||||||
|
* :tags, :environment, :release, and :modules will be passed to Sentry
|
||||||
|
as attributes, Ref. https://docs.sentry.io/clientdev/attributes/.
|
||||||
|
* :event-fn can be used to modify the raw event before sending it
|
||||||
|
to Sentry."
|
||||||
|
|
||||||
* :tags :environment :release :modules will be passed on to sentry as
|
|
||||||
attributes See https://docs.sentry.io/clientdev/attributes/ for more
|
|
||||||
information.
|
|
||||||
* :event-fn can be used to modify the raw even before sending it
|
|
||||||
to sentry.
|
|
||||||
"
|
|
||||||
[dsn & [opts]]
|
[dsn & [opts]]
|
||||||
(let [{:keys [event-fn] :or {event-fn identity}} opts
|
(let [{:keys [event-fn] :or {event-fn identity}} opts
|
||||||
base-event (->> (select-keys opts [:tags :environment :release :modules])
|
base-event
|
||||||
(filter (comp not nil? second))
|
(->> (select-keys opts [:tags :environment :release :modules])
|
||||||
(into {}))]
|
(filter (comp not nil? second))
|
||||||
{:enabled? true
|
(into {}))]
|
||||||
:async? true
|
|
||||||
:min-level :warn ; Sentry supports info and debug as well but warning
|
{:enabled? true
|
||||||
; is a reasonable default given how sentry works.
|
:async? true
|
||||||
:rate-limit nil
|
:min-level :warn ; Reasonable default given how Sentry works
|
||||||
:output-fn :inherit
|
:rate-limit nil
|
||||||
:fn
|
:output-fn :inherit
|
||||||
(fn [data]
|
:fn
|
||||||
(let [{:keys [instant level output_ ?err msg_ ?ns-str context]} data
|
(fn [data]
|
||||||
event (as-> base-event event
|
(let [{:keys [instant level output_ ?err msg_ ?ns-str context]} data
|
||||||
(merge event {:message (force msg_)
|
|
||||||
:logger ?ns-str
|
event
|
||||||
:level (get levels level :warning)}
|
(as-> base-event event
|
||||||
(when context
|
(merge event
|
||||||
{:extra context}))
|
{:message (force msg_)
|
||||||
(if ?err
|
:logger ?ns-str
|
||||||
(interfaces/stacktrace event ?err)
|
:level (get timbre->sentry-levels level)}
|
||||||
event)
|
|
||||||
(event-fn event))]
|
(when context {:extra context}))
|
||||||
(raven/capture dsn event)))}))
|
|
||||||
|
(if ?err
|
||||||
|
(interfaces/stacktrace event ?err)
|
||||||
|
event)
|
||||||
|
|
||||||
|
(event-fn event))]
|
||||||
|
|
||||||
|
(raven/capture dsn event)))}))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
;; Create an example appender with default options:
|
;; Create an example appender with default opts:
|
||||||
(sentry-appender "https://<key>:<secret>@sentry.io/<project>")
|
(sentry-appender "https://<key>:<secret>@sentry.io/<project>")
|
||||||
|
|
||||||
;; Create an example appender with default options, but override `:min-level`:
|
;; Create an example appender with default opts, but override `:min-level`:
|
||||||
(merge (sentry-appender "https://<key>:<secret>@sentry.io/<project>") {:min-level :debug}))
|
(merge (sentry-appender "https://<key>:<secret>@sentry.io/<project>")
|
||||||
|
{:min-level :debug}))
|
||||||
|
|
Loading…
Reference in New Issue