From 92a7aee530ce9c7cc882d4e33e8406e43d70df85 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 6 Sep 2024 10:33:21 +0200 Subject: [PATCH] [fix] Signal fields: define based on target (not macro) platform Attempted fix for possible issue with "Electric Clojure" --- projects/main/src/taoensso/telemere/impl.cljc | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/projects/main/src/taoensso/telemere/impl.cljc b/projects/main/src/taoensso/telemere/impl.cljc index 2eea9a6..6813428 100644 --- a/projects/main/src/taoensso/telemere/impl.cljc +++ b/projects/main/src/taoensso/telemere/impl.cljc @@ -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) @@ -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] +#?(: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])] - Object (toString [sig] (str "#" `Signal (into {} sig)))) + `(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