-
Notifications
You must be signed in to change notification settings - Fork 6
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
Migrate to sentry-clj. Getting rid of raven lib. #65
Merged
arthuraliiev
merged 6 commits into
master
from
aa/sc-90117/move-k2-apps-over-to-exoscale-sentry-io
Mar 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cadfcd8
Migrate to sentry-clj. Getting rid of raven lib.
2311f14
update ->sentry-event function.
12075d5
return event-id on capturing.
04708e0
update destructuring.
fa85dfe
some links add.
ff34689
raven-options -> sentry-options
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
(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])) | ||
|
||
(def http-requests-payload-stub | ||
"Storage for stubbed http sentry events " | ||
(atom nil)) | ||
|
||
(defn in-memory? [dsn] | ||
(or (= dsn ":memory:") | ||
(nil? dsn))) | ||
|
||
(def hostname-refresh-interval | ||
"How often to allow reading /etc/hostname, in seconds." | ||
60) | ||
|
||
(defn get-hostname | ||
"Get the current hostname by shelling out to 'hostname'" | ||
[] | ||
(or | ||
(try | ||
(let [{:keys [exit out]} (sh/sh "hostname")] | ||
(when (= exit 0) | ||
(str/trim out))) | ||
(catch Exception _)) | ||
"<unknown>")) | ||
|
||
(defn hostname | ||
"Fetches the hostname by shelling to 'hostname', whenever the given age | ||
is stale enough. If the given age is recent, as defined by | ||
hostname-refresh-interval, returns age and val instead." | ||
[[age val]] | ||
(if (and val (<= (* 1000 hostname-refresh-interval) | ||
(- (System/currentTimeMillis) age))) | ||
[age val] | ||
[(System/currentTimeMillis) (get-hostname)])) | ||
|
||
(let [cache (atom [nil nil])] | ||
(defn localhost | ||
"Returns the local host name." | ||
[] | ||
(if (re-find #"^Windows" (System/getProperty "os.name")) | ||
(or (System/getenv "COMPUTERNAME") "localhost") | ||
(or (System/getenv "HOSTNAME") | ||
(second (swap! cache hostname)))))) | ||
|
||
(defn- e->sentry-request [e] | ||
(let [payload (-> e :extra :payload)] | ||
{:url (-> payload :uri) | ||
:method (-> payload :request-method name clojure.string/upper-case) | ||
:query-string (-> payload :query-string) | ||
:headers (-> payload :headers)})) | ||
|
||
(defn e->sentry-event [e options tags] | ||
(let [{:keys [message extra throwable]} e] | ||
|
||
(if message | ||
arthuraliiev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{:message message} | ||
|
||
{:message (ex-message e) | ||
:request (e->sentry-request e) | ||
:level :error | ||
:platform "java" | ||
:user {:id (-> e :extra :org/uuid str)} | ||
:tags tags | ||
:server-name (localhost) | ||
:fingerprints (some-> options :fingerpint seq) | ||
:extra extra | ||
:throwable throwable}))) | ||
|
||
(defn send-event! [dsn options e tags] | ||
(let [event (e->sentry-event e options tags)] | ||
(if-not (in-memory? dsn) | ||
(-> (try | ||
(sentry-io/send-event event) | ||
(catch Exception e | ||
(d/error-deferred e))) | ||
(d/chain | ||
arthuraliiev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(fn [event-id] | ||
(error e (str "captured exception as sentry event: " event-id)))) | ||
(d/catch (fn [e'] | ||
(error e "Failed to capture exception" {:tags tags :capture-exception e'}) | ||
(send-event! dsn options e' tags)))) | ||
(swap! http-requests-payload-stub conj event)))) | ||
|
||
(defn init! [dsn sentry] | ||
(if-not (in-memory? dsn) | ||
arthuraliiev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(sentry-io/init! (:dsn sentry) sentry) | ||
(reset! http-requests-payload-stub []))) | ||
|
||
(defn close! [dsn] | ||
(if-not (in-memory? dsn) | ||
(sentry-io/close!) | ||
(reset! http-requests-payload-stub nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When migrating to the new reporter, we will have to provide the environment and release, instead of reading it off from
SENTRY_*
env vars right? Might be worth it to put it in the readme/changelogThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't get this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that we may want to update the README to say clients should specifically pass environment and release when sending events.
Eg blockproxy was relying on
SENTRY_
env vars: https://github.com/exoscale/blockstorage/blob/master/.kargo/collector.edn#L36 andio.sentry.logback.SentryAppender
, which would read off those env vars; when we move to the new reporter, we have to explicitly pass these variables to the sentry config