Skip to content

Commit

Permalink
sentry: allow passing :tags in sentry config
Browse files Browse the repository at this point in the history
  • Loading branch information
mping-exo committed Mar 20, 2024
1 parent a8ea989 commit 0ae1325
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Reporter provides a [component](https://github.com/stuartsierra/component) in or

### Changelog

#### 1.0.2

- Migrating from `exoscale/raven` to `io.sentry/sentry-clj`
- Reporter's `sentry` config supports the following keys `:dsn, :environment, :release, :tags`
- `sentry-options` are deprecated

#### 1.0.0

- Migrating from `exoscale/raven` to `io.sentry/sentry-clj`
Expand Down
42 changes: 22 additions & 20 deletions src/spootnik/reporter/sentry.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns spootnik.reporter.sentry
(:require
[sentry-clj.core :as sentry-io]
[manifold.deferred :as d]
[clojure.string :as str]
[clojure.tools.logging :refer [error]]
[clojure.java.shell :as sh]))
[sentry-clj.core :as sentry]
[sentry-clj.core :as sentry-io]
[manifold.deferred :as d]
[clojure.string :as str]
[clojure.tools.logging :refer [error]]
[clojure.java.shell :as sh]))

(def http-requests-payload-stub
"Storage for stubbed http sentry events "
Expand Down Expand Up @@ -59,28 +60,30 @@
Supported event keys:
https://github.com/getsentry/sentry-clj/tree/master?tab=readme-ov-file#supported-event-keys
"

[e options tags]
(let [{:keys [message extra throwable]} e
(let [{:keys [message extra throwable fingerprint]} e
message (or message (ex-message e))
user (some-> extra :org/uuid str)
fingerprints (some-> options :fingerpint seq)
request (some-> extra :payload payload->sentry-request)]
fingerprints (some-> fingerprint seq)
request (some-> extra :payload payload->sentry-request)
;; override "base" tags with params
merged-tags (merge (:tags options) tags)]

(cond-> {:message message
:level :error
:platform "java"
:server-name (localhost)}

throwable (assoc :throwable throwable)
extra (assoc :extra extra)
(seq tags) (assoc :tags tags)
user (assoc :user user)
fingerprints (assoc :fingerprints fingerprints)
request (assoc :request request))))
throwable (assoc :throwable throwable)
extra (assoc :extra extra)
(seq merged-tags) (assoc :tags merged-tags)
user (assoc :user user)
fingerprints (assoc :fingerprints fingerprints)
request (assoc :request request))))

(defn send-event! [dsn options e tags]
(let [event (e->sentry-event e options tags)]
(defn send-event! [{:keys [dsn] :as sentry} legacy-options e tags]
;; sentry-options are legacy
(let [event (e->sentry-event e (merge legacy-options sentry) tags)]
(if-not (in-memory? dsn)
(-> (try
(sentry-io/send-event event)
Expand All @@ -93,8 +96,8 @@
event-id))

(d/catch (fn [e']
(error e "Failed to capture exception" {:tags tags :capture-exception e'})
(send-event! dsn options e' tags))))
(error e "Failed to capture exception" {:tags tags :throwble e'})
(send-event! sentry legacy-options e' tags))))

(swap! http-requests-payload-stub conj event))))

Expand All @@ -103,7 +106,6 @@
Additional options can be found here:
https://github.com/getsentry/sentry-clj/tree/master?tab=readme-ov-file#additional-initialisation-options
"

[{:keys [dsn] :as sentry}]
(if-not (in-memory? dsn)
(sentry-io/init! dsn sentry)
Expand Down

0 comments on commit 0ae1325

Please sign in to comment.