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
|
||||
"Sentry appender
|
||||
|
||||
Requires https://github.com/sethtrain/raven-clj"
|
||||
"Sentry appender. Requires https://github.com/sethtrain/raven-clj."
|
||||
{:author "Samuel Otter (@samuelotter)"}
|
||||
(:require
|
||||
[taoensso.encore :as enc]
|
||||
|
@ -9,55 +7,64 @@
|
|||
[raven-clj.core :as raven]
|
||||
[raven-clj.interfaces :as interfaces]))
|
||||
|
||||
(def ^:private levels {:fatal "fatal"
|
||||
:error "error"
|
||||
:warn "warning"
|
||||
:info "info"
|
||||
(def ^:private timbre->sentry-levels
|
||||
{:trace "debug"
|
||||
:debug "debug"
|
||||
:trace "debug"})
|
||||
:info "info"
|
||||
:warn "warning"
|
||||
:error "error"
|
||||
:fatal "fatal"
|
||||
:report "info"})
|
||||
|
||||
(defn sentry-appender
|
||||
"Creates a sentry-appender. Requires the DSN (e.g.
|
||||
\"https://<key>:<secret>@sentry.io/<project>\", see sentry documentation) to
|
||||
be passed in.
|
||||
"Returns a raven-clj Sentry appender.
|
||||
|
||||
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]]
|
||||
(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))
|
||||
(into {}))]
|
||||
|
||||
{:enabled? true
|
||||
:async? true
|
||||
:min-level :warn ; Sentry supports info and debug as well but warning
|
||||
; is a reasonable default given how sentry works.
|
||||
:min-level :warn ; Reasonable default given how Sentry works
|
||||
:rate-limit nil
|
||||
:output-fn :inherit
|
||||
:fn
|
||||
(fn [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
|
||||
:level (get levels level :warning)}
|
||||
(when context
|
||||
{:extra context}))
|
||||
:level (get timbre->sentry-levels level)}
|
||||
|
||||
(when context {:extra context}))
|
||||
|
||||
(if ?err
|
||||
(interfaces/stacktrace event ?err)
|
||||
event)
|
||||
|
||||
(event-fn event))]
|
||||
|
||||
(raven/capture dsn event)))}))
|
||||
|
||||
(comment
|
||||
;; Create an example appender with default options:
|
||||
;; Create an example appender with default opts:
|
||||
(sentry-appender "https://<key>:<secret>@sentry.io/<project>")
|
||||
|
||||
;; Create an example appender with default options, but override `:min-level`:
|
||||
(merge (sentry-appender "https://<key>:<secret>@sentry.io/<project>") {:min-level :debug}))
|
||||
;; Create an example appender with default opts, but override `:min-level`:
|
||||
(merge (sentry-appender "https://<key>:<secret>@sentry.io/<project>")
|
||||
{:min-level :debug}))
|
||||
|
|
Loading…
Reference in New Issue