Skip to content

Commit

Permalink
[new] OpenTelemetry handler: try print map vals as EDN
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Oct 29, 2024
1 parent 5ef4f12 commit c1e1c1e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions projects/main/src/taoensso/telemere/open_telemetry.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@

clojure.lang.IPersistentCollection
(-put-attr! [v ^String k ^AttributesBuilder ab]
(when-some [v1 (if (indexed? v) (nth v 0 nil) (first v))]
;; Ignores nested maps
(if (map? v)
(when-let [^String s (enc/catching :common (enc/pr-edn* v))]
(.put ab k s))

(when-some [v1 (if (indexed? v) (nth v 0 nil) (first v))]
(or
(cond
(string? v1) (enc/catching :common (.put ab k ^"[Ljava.lang.String;" (into-array String v)))
Expand All @@ -75,7 +78,7 @@
(boolean? v1) (enc/catching :common (.put ab k (boolean-array v))))

(when-let [^String s (enc/catching :common (enc/pr-edn* v))]
(.put ab k s))))
(.put ab k s)))))
ab)

Object
Expand Down Expand Up @@ -221,7 +224,7 @@
(comment
(enc/qb 1e6 (span-attrs {:ns "ns1" :line 495})) ; 54.31
(span-attrs {:ns "ns1", :otel/attrs {:foo :bar}})
(span-attrs {:ns "ns1", :otel/attrs {:foo [5 :a :b]}}))
(span-attrs {:ns "ns1", :otel/attrs {:foo {:a :b}}}))

(defn handler:open-telemetry
"Highly experimental, possibly buggy, and subject to change!!
Expand Down Expand Up @@ -249,7 +252,7 @@
[1] `io.opentelemetry.api.common.Attributes` or Clojure map with str/kw keys and vals ∈
#{nil boolean keyword string UUID long double string-vec long-vec double-vec boolean-vec}.
(Nested) map vals will be ignored!"
Other val types (incl. maps) will be printed as EDN if possible, or skipped otherwise."

;; Notes:
;; - Multi-threaded handlers may see signals ~out of order
Expand Down

0 comments on commit c1e1c1e

Please sign in to comment.