Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass ex-data on to Sentry as additional data field #349

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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