Skip to content

Commit

Permalink
[#349] [3rd-party] Pass ex-data on to Sentry as additional data field (
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Mar 22, 2022
1 parent c6cc231 commit 7340188
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/taoensso/timbre/appenders/3rd_party/sentry.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
Requires the DSN (e.g. \"https://<key>:<secret>@sentry.io/<project>\")
to be passed in, see Sentry documentation for details.
Timbre's `*context*` will be passed to Sentry as `:extra` data. When logging
an exception with ex-data attached, it will be stringified and added under
`: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 @@ -44,14 +48,21 @@
(fn [data]
(let [{:keys [instant level output_ ?err msg_ ?ns-str context]} data

?ex-data (ex-data ?err)
extra
(cond-> context
(and ?ex-data (not (contains? context :ex-data)))
(assoc :ex-data
(enc/get-substr (str ?ex-data) 0 4096)))

event
(as-> base-event event
(merge event
{:message (force msg_)
: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 7340188

Please sign in to comment.