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"
|
|
||||||
:info "info"
|
|
||||||
:debug "debug"
|
:debug "debug"
|
||||||
:trace "debug"})
|
:info "info"
|
||||||
|
:warn "warning"
|
||||||
|
: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
|
||||||
|
(->> (select-keys opts [:tags :environment :release :modules])
|
||||||
(filter (comp not nil? second))
|
(filter (comp not nil? second))
|
||||||
(into {}))]
|
(into {}))]
|
||||||
|
|
||||||
{:enabled? true
|
{:enabled? true
|
||||||
:async? true
|
:async? true
|
||||||
:min-level :warn ; Sentry supports info and debug as well but warning
|
:min-level :warn ; Reasonable default given how Sentry works
|
||||||
; is a reasonable default given how sentry works.
|
|
||||||
:rate-limit nil
|
:rate-limit nil
|
||||||
:output-fn :inherit
|
:output-fn :inherit
|
||||||
:fn
|
:fn
|
||||||
(fn [data]
|
(fn [data]
|
||||||
(let [{:keys [instant level output_ ?err msg_ ?ns-str context]} data
|
(let [{:keys [instant level output_ ?err msg_ ?ns-str context]} data
|
||||||
event (as-> base-event event
|
|
||||||
(merge event {:message (force msg_)
|
event
|
||||||
|
(as-> base-event event
|
||||||
|
(merge event
|
||||||
|
{:message (force msg_)
|
||||||
:logger ?ns-str
|
:logger ?ns-str
|
||||||
:level (get levels level :warning)}
|
:level (get timbre->sentry-levels level)}
|
||||||
(when context
|
|
||||||
{:extra context}))
|
(when context {:extra context}))
|
||||||
|
|
||||||
(if ?err
|
(if ?err
|
||||||
(interfaces/stacktrace event ?err)
|
(interfaces/stacktrace event ?err)
|
||||||
event)
|
event)
|
||||||
|
|
||||||
(event-fn event))]
|
(event-fn event))]
|
||||||
|
|
||||||
(raven/capture dsn 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