Makes logging unified

This commit is contained in:
2023-10-30 12:35:18 -07:00
parent f0a7c378f7
commit 930b900849
44 changed files with 485 additions and 555 deletions

View File

@@ -17,7 +17,7 @@
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]
[auto-ap.graphql.vendors :as gq-vendors]
[auto-ap.graphql.yodlee-merchants :as ym]
[auto-ap.logging :as alog :refer [error-event info-event warn-event]]
[auto-ap.logging :as alog]
[auto-ap.time :as time]
[clj-time.coerce :as coerce]
[clj-time.core :as t]
@@ -29,7 +29,6 @@
[com.walmartlabs.lacinia.parser :as p]
[com.walmartlabs.lacinia.schema :as schema]
[datomic.api :as dc]
[unilog.context :as lc]
[yang.time :refer [time-it]])
(:import
(clojure.lang IPersistentMap)))
@@ -807,36 +806,31 @@
([id q v]
(statsd/increment "query.graphql.count" {:tags #{(str "query:" (query-name q))}})
(statsd/time! [(str "query.graphql.time" ) {:tags #{(str "query:" (query-name q))}}]
(mu/with-context {:query-string q :user id}
(lc/with-context {:query q}
(alog/info ::executing-query
:query-name (query-name q))
(try
(let [[result time] (time-it (simplify (execute schema q (dissoc v
:clients) {:id id
:clients (:clients v)})))]
(info-event "Query completed"
{:time (:time time)
:errors (seq (:errors result))})
(when (seq (:errors result))
(throw (ex-info "GraphQL error" {:result result})))
result)
(mu/with-context {:query-name (query-name q) :user id :query q}
(mu/trace ::executing-query
[]
(try
(let [[result time] (time-it (simplify (execute schema q (dissoc v
:clients) {:id id
:clients (:clients v)
:log-context (or (mu/local-context) {})})))]
(when (seq (:errors result))
(throw (ex-info "GraphQL error" {:result result})))
result)
(catch Exception e
(if-let [v (or (:validation-error (ex-data e))
(:validation-error (ex-data (.getCause e))))]
(do
(alog/warn ::query-validation
:exception e)
(warn-event "validation error" {:validation-error v
:data (ex-data e)})
(throw e)
#_{:errors [{:message v}]})
(do
(error-event "query error" {:error e})
(alog/error ::query-error
:exception e)
(catch Exception e
(if-let [v (or (:validation-error (ex-data e))
(:validation-error (ex-data (.getCause e))))]
(do
(alog/warn ::query-validation
:exception e)
(throw e)
#_{:errors [{:message v}]})
(do
(alog/error ::query-error
:exception e)
(throw e))))))))))
(throw e))))))))))