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

Allow person data to be sent through the API #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
34 changes: 21 additions & 13 deletions src/circleci/rollcage/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
:notifier {:name String}
:server {:host String
:root String
:code_version (s/maybe String)}}})
:code_version (s/maybe String)}}
(s/optional-key :person) {:id String
(s/optional-key :email) String
(s/optional-key :username) String}})

(defn- deep-merge
"Like merge, but merges maps recursively."
Expand Down Expand Up @@ -167,17 +170,22 @@
level :- String
exception :- Throwable
url :- (s/maybe String)
custom :- (s/maybe {s/Any s/Any})]
custom :- (s/maybe {s/Any s/Any})
& [person :- {:id String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make-rollbar is only called in one place, and it's private, so we should be able to make the new argument a required parameter, right?

(s/optional-key :email) (s/maybe String)
(s/optional-key :username) (s/maybe String)}]]
;; TODO: Pass request parameters through to here
;; TODO: add person here
(-> client
(dissoc :result-fn :send-fn)
(assoc-in [:data :body :trace_chain] (build-trace exception))
(assoc-in [:data :level] level)
(assoc-in [:data :timestamp] (timestamp))
(assoc-in [:data :uuid] (uuid))
(assoc-in [:data :custom] custom)
(assoc-in [:data :request :url] url)))
(let [item (-> client
(dissoc :result-fn :send-fn)
(assoc-in [:data :body :trace_chain] (build-trace exception))
(assoc-in [:data :level] level)
(assoc-in [:data :timestamp] (timestamp))
(assoc-in [:data :uuid] (uuid))
(assoc-in [:data :custom] custom)
(assoc-in [:data :request :url] url))]
(cond-> item
(some? person)
(assoc :person person))))

(def ^:private rollbar-to-logging
"A look-up table to map from Rollbar severity levels to tools.logging levels"
Expand Down Expand Up @@ -314,10 +322,10 @@
"Report an exception to Rollbar."
([^String level client ^Throwable exception]
(notify level client exception {}))
([^String level {:keys [result-fn send-fn block-fields] :as client} ^Throwable exception {:keys [url params]}]
([^String level {:keys [result-fn send-fn block-fields] :as client} ^Throwable exception {:keys [url params person]}]
(let [params (merge params (throwables/merged-ex-data exception))
scrubbed (scrub params block-fields)
item (make-rollbar client level exception url scrubbed)
item (make-rollbar client level exception url scrubbed person)
result (try
(send-fn endpoint exception item)
(catch Exception e
Expand Down
6 changes: 6 additions & 0 deletions test/circleci/rollcage/test_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@
(select-keys (#'client/make-rollbar c "error" (Exception.) nil nil)
[:access-token])))))

(deftest it-can-track-person
(let [c (client/client "access-token" {})]
(is (= {:person {:id "person"}}
(select-keys (#'client/make-rollbar c "error" (Exception.) nil nil {:id "person"})
[:person])))))

(deftest ^:integration test-environment-is-setup
(is (not (string/blank? (System/getenv "ROLLBAR_ACCESS_TOKEN")))
"You must specify a ROLLBAR_ACCESS_TOKEN with POST credentials"))
Expand Down