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 ddc6029
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 @@ -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/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 All @@ -68,3 +79,7 @@
;; Create an example appender with default opts, but override `:min-level`:
(merge (sentry-appender "https://<key>:<secret>@sentry.io/<project>")
{:min-level :debug}))


(cond->
)

0 comments on commit ddc6029

Please sign in to comment.