Skip to content

Commit 3b27a9c

Browse files
committed
fix: parse trace logs before sending
style: rm opensearch secrets chore: squash commit with secrets
1 parent f1ba400 commit 3b27a9c

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/com/moclojer/components/logs.clj

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns com.moclojer.components.logs
22
(:require
3-
[com.moclojer.components.logs :as logs]
43
[com.stuartsierra.component :as component]
54
[clojure.core.async :as async]
65
[clojure.data.json :as json]
@@ -34,11 +33,17 @@
3433

3534
(defn signal->opensearch-log
3635
"Adapts a telemere signal to a pre-defined schema for OpenSearch."
37-
[{:keys [thread location] :as signal}]
38-
(-> (select-keys signal [:level :ctx :data :msg_ :uid :inst])
39-
(merge {"thread/group" (:group thread)
36+
[{:keys [thread location parent root msg_] :as signal}]
37+
(-> (select-keys signal [:level :ctx :data :uid :id
38+
:inst :end-inst :run-nsecs])
39+
(merge {"msg_" (when-not (delay? msg_) msg_)
40+
"thread/group" (:group thread)
4041
"thread/name" (:name thread)
4142
"thread/id" (:id thread)
43+
"parent/uid" (:uid parent)
44+
"parent/id" (:id parent)
45+
"root/uid" (:uid root)
46+
"root/id" (:id root)
4247
"location" (str (:ns location) ":"
4348
(:line location) "x"
4449
(:column location))})
@@ -99,6 +104,13 @@
99104
(t/remove-handler! ::opensearch)
100105
(update this :log-ch #(when % (async/close! %)))))
101106

107+
(defmacro trace
108+
[id data & body]
109+
`(taoensso.telemere/trace!
110+
{:id ~id
111+
:data ~data}
112+
(do ~@body)))
113+
102114
(defn log
103115
[level msg & [data ctx error]]
104116
(t/log! {:level level
@@ -111,17 +123,21 @@
111123
{:cid (str "cid-" (random-uuid) "-" (System/currentTimeMillis))})
112124

113125
(comment
114-
(component/start
115-
(map->Logger
116-
{:config
117-
{:env :prod
118-
:opensearch
119-
{:username "foobar"
120-
:password "foobar"
121-
:host "foobar"
122-
:port 25060
123-
:index "components-test-logs"}}}))
124-
125-
(log :error "something happened" {:hello true})
126+
(def logger
127+
(map->Logger
128+
{:config
129+
{:env :prod
130+
:opensearch
131+
{:username "foobar"
132+
:password "foobar"
133+
:host "foobar"
134+
:port 25060
135+
:index "components-test-logs"}}}))
136+
137+
(component/start logger)
138+
(component/stop logger)
139+
140+
(trace ::testing-stuff {:testing? :definitely}
141+
(log :error "aaaaa aaaa" {:hello true}))
126142
;;
127143
)

0 commit comments

Comments
 (0)