From c56e69f8e7600cabed17f80c997bdef40a4ad9bd Mon Sep 17 00:00:00 2001 From: Casey Link Date: Thu, 16 May 2024 13:51:41 +0200 Subject: [PATCH] Improve formatting of mulog events --- .clj-kondo/config.edn | 1 + resources/config.edn | 2 ++ src/clj/app/errors.clj | 10 +++++----- src/clj/app/ig.clj | 7 ++++++- src/clj/app/interceptors.clj | 3 +-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index b8bfa4e..3a6e474 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -1,4 +1,5 @@ {:skip-comments true + :lint-as {io.pedestal.interceptor.error/error-dispatch clj-kondo.lint-as/def-catch-all} :linters {:unused-value {:level :off} :unused-binding {:level :off} :unused-import {:level :off} diff --git a/resources/config.edn b/resources/config.edn index d7ef29b..e66b706 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -1,4 +1,6 @@ {:name "SNOrga" + :git-hash #or [#env GIT_HASH "unknown"] + :build-date #or [#env BUILD_DATE "unknown"] :secrets #include #or [#env APP_SECRETS_FILE "../secrets.edn"] :admin-email #ref [:secrets :admin-email] :app-base-url #ref [:secrets :app-base-url] diff --git a/src/clj/app/errors.clj b/src/clj/app/errors.clj index 19a1a6f..f68f8dc 100644 --- a/src/clj/app/errors.clj +++ b/src/clj/app/errors.clj @@ -1,10 +1,9 @@ (ns app.errors (:require - [medley.core :as m] - [com.brunobonacci.mulog :as μ] [app.config :as config] [app.util :as util] - [clojure.set :as set])) + [com.brunobonacci.mulog :as μ] + [medley.core :as m])) (def dangerous-keys #{:datomic-conn @@ -67,9 +66,10 @@ (assoc :will-change-lang (:will-change-lang req)) (assoc :form-params (:form-params req)) (assoc :path-params (:path-params req))))) - (update :request-method name) + ;; (update :request-method name) (select-keys [:uri :query-string :request-method :headers :params :member-id :user-email]) - (set/rename-keys {:request-method :method :params :data :uri :url}))) + ;; (set/rename-keys {:request-method :method :params :data :uri :url}) + )) (defn send-event! "Sends a telemetry event asynchronously" diff --git a/src/clj/app/ig.clj b/src/clj/app/ig.clj index 9fc8e93..f28ccfe 100644 --- a/src/clj/app/ig.clj +++ b/src/clj/app/ig.clj @@ -36,7 +36,12 @@ profile) (defmethod ig/init-key ::env [_ profile] - (system/config profile)) + (let [env (system/config profile)] + (μ/set-global-context! {:app-name (:name env) + :git-hash (:git-hash env) + :build-date (:build-date env) + :env (-> env :ig/system :app.ig/profile)}) + env)) (defmethod ig/init-key ::handler [_ system] (routes/default-handler system)) diff --git a/src/clj/app/interceptors.clj b/src/clj/app/interceptors.clj index 3d79c2f..c5f0c1c 100644 --- a/src/clj/app/interceptors.clj +++ b/src/clj/app/interceptors.clj @@ -161,9 +161,8 @@ user-email (auth/get-current-email req) finish (System/currentTimeMillis) total (- finish start-time)] - (μ/log :http/request :msg "request completed" - :method (str/upper-case (name request-method)) + :request-method request-method :uri uri :human-id human-id :user-email user-email