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

Support arbitrary cgi-data metadata #3

Open
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ all possible metadata values:
(hb/notify hb-config
(Exception. "Vapor Lock")
{:tags [:serious :business]
:cgi-data {"SERVER_NAME" "crywolf.dev"
"SERVER_PORT" "80"}
:component "robot-brain" ; ~= a Rails controller
:action "think" ; ~= a Rails action
:context {:name "Winston"
Expand Down
14 changes: 7 additions & 7 deletions src/honeybadger/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,18 @@
(defn- error-patch [notifiable]
{:error (error-map notifiable)})

(defn- metadata-patch [{:keys [tags context component action request]}]
(let [{:keys [method url params session]} request]
(defn- metadata-patch [{:keys [tags cgi-data component context action request]}]
(let [{:keys [method url params session]} request
cgi-data' (cond-> cgi-data
method (assoc "REQUEST_METHOD" (str/upper-case (name method))))]
{:error {:tags tags}
:request {:url url
:component component
:action action
:params params
:context (or context {}) ; diplays differently if nil
:session session
:cgi-data (some->> method
name
str/upper-case
(array-map "REQUEST_METHOD"))}}))
:cgi-data cgi-data'}}))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down Expand Up @@ -109,7 +108,8 @@
(update-contained-in [:metadata :request :method] keyword)
(update-contained-in [:metadata :request :params] #(or % {}))
(update-contained-in [:metadata :request :session] #(or % {}))
(->> (deep-merge {:metadata {:tags #{}
(->> (deep-merge {:metadata {:cgi-data {}
:tags #{}
:request {}
:context {}
:component nil
Expand Down
1 change: 1 addition & 0 deletions src/honeybadger/schemas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
(s/optional-key :url) s/Str
(s/optional-key :params) {s/Keyword s/Any}
(s/optional-key :session) {s/Keyword s/Any}}
:cgi-data {s/Keyword s/Any}
:context {s/Keyword s/Any}
:component (s/maybe s/Str)
:action (s/maybe s/Str)}})
Expand Down
19 changes: 19 additions & 0 deletions test/honeybadger/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns honeybadger.core-test
(:require [clojure.test :refer :all]
[honeybadger.core :as hb]))

(defn- format-metadata [metadata]
(-> (#'hb/event->notice
(#'hb/normalize-event "123"
"development"
"test"
metadata))
:request
:cgi-data))

(deftest cgi-data
(are [out in] (= out (format-metadata in))
{} {}
{:foo "bar"} {:cgi-data {"foo" "bar"}}
{"REQUEST_METHOD" "GET"} {:request {:method :get}}
{"REQUEST_METHOD" "GET", :foo "bar"} {:request {:method :get} :cgi-data {"foo" "bar"}}))