Skip to content

Commit

Permalink
[fix] Define Signal fields based on target (not macro) platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Sep 6, 2024
1 parent fabaae6 commit 96b0aff
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions projects/main/src/taoensso/telemere/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#?(:cljs
(:require-macros
[taoensso.telemere.impl :refer [with-signal]])))
[taoensso.telemere.impl :refer [with-signal def-signal-record]])))

(comment
(remove-ns 'taoensso.telemere.impl)
Expand Down Expand Up @@ -231,14 +231,27 @@

;;;; Main types

(defrecord Signal
;; Telemere's main public data type, we avoid nesting and duplication
[^long schema inst uid,
location ns line column file, #?@(:clj [host thread _otel-context]),
sample-rate, kind id level, ctx parent root, data kvs msg_,
error run-form run-val end-inst run-nsecs]

Object (toString [sig] (str "#" `Signal (into {} sig))))
#?(:clj
(defmacro def-signal-record
"Defines Telemere's main public data type, we avoid nesting and duplication."
[]
(let [fields
(if (:ns &env)
'[schema inst uid,
location ns line column file,
;; host thread _otel-context,
sample-rate, kind id level, ctx parent root, data kvs msg_,
error run-form run-val end-inst run-nsecs]
'[schema inst uid,
location ns line column file,
host thread _otel-context,
sample-rate, kind id level, ctx parent root, data kvs msg_,
error run-form run-val end-inst run-nsecs])]

`(defrecord ~'Signal ~fields
~'Object (~'toString [sig#] (str "#taoensso.telemere.impl.Signal" (into {} sig#)))))))

(defonce __def-signal-record (def-signal-record))

(do (enc/def-print-impl [sig Signal] (str "#" `Signal (pr-str (into {} sig)))))
#?(:clj (enc/def-print-dup [sig Signal] (str "#" `Signal (pr-str (into {} sig))))) ; NB intentionally verbose, to support extra keys
Expand Down

0 comments on commit 96b0aff

Please sign in to comment.