Skip to content

Commit

Permalink
Pass ex-data on to Sentry as additional data field
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGuteMoritz committed Mar 7, 2022
1 parent 7bb3d64 commit d368754
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/taoensso/timbre/appenders/3rd_party/sentry.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
:fatal "fatal"
:report "info"})

;; Copied from raven-clj.ring since it's private there, too.
(defn- truncate-extra-str [text]
(subs text 0 (min (count text) 4096)))

(defn sentry-appender
"Returns a raven-clj Sentry appender.
Requires the DSN (e.g. \"https://<key>:<secret>@sentry.io/<project>\")
to be passed in, see Sentry documentation for details.
A Timbre context map will be passed through to Sentry as additional
data.
When logging an exception which has ex-data attached, it will be
stringified and passed as part of the additional data map under
the :ex-data key (unless that key already exists in context).
Common options:
* :tags, :environment, :release, and :modules will be passed to Sentry
as attributes, Ref. https://docs.sentry.io/clientdev/attributes/.
Expand All @@ -43,6 +54,10 @@
:fn
(fn [data]
(let [{:keys [instant level output_ ?err msg_ ?ns-str context]} data
?ex-data (some-> ?err ex-data)
extra (cond-> context
(and ?ex-data (not (:ex-data context)))
(assoc :ex-data (truncate-extra-str (str ?ex-data))))

event
(as-> base-event event
Expand All @@ -51,7 +66,7 @@
:logger ?ns-str
:level (get timbre->sentry-levels level)}

(when context {:extra context}))
(when extra {:extra extra}))

(if ?err
(interfaces/stacktrace event ?err)
Expand Down

0 comments on commit d368754

Please sign in to comment.