Skip to content

Commit

Permalink
[fix] Use same Signal record, regardless of platform
Browse files Browse the repository at this point in the history
Downside: Cljs will have some unused (nil) keys
Upside: possibly more robust in build environments that target
  both Clj and Cljs?
  • Loading branch information
ptaoussanis committed Sep 6, 2024
1 parent 96b0aff commit bf966c0
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 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 def-signal-record]])))
[taoensso.telemere.impl :refer [with-signal]])))

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

;;;; Main types

#?(: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))
(defrecord Signal
;; Telemere's main public data type, we avoid nesting and duplication
[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]

Object (toString [sig] (str "#" `Signal (into {} sig))))

(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 Expand Up @@ -641,9 +628,9 @@
(let [clause [(if run-form :run :no-run) (if clj? :clj :cljs)]]
(case clause
[:run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, (enc/host-info) ~'__thread ~'__otel-context1, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~run-form ~'_run-val ~'_end-inst ~'_run-nsecs)
[:run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~run-form ~'_run-val ~'_end-inst ~'_run-nsecs)
[:run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, nil nil nil ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~run-form ~'_run-val ~'_end-inst ~'_run-nsecs)
[:no-run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, (enc/host-info) ~'__thread ~'__otel-context1, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
[:no-run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
[:no-run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, nil nil nil ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
(enc/unexpected-arg! clause {:context :signal-constructor-args})))

record-form
Expand Down

0 comments on commit bf966c0

Please sign in to comment.