Skip to content

Commit d1fbdbd

Browse files
committed
[new] Add Telemere handler
1 parent aad06a6 commit d1fbdbd

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/taoensso/tufte/telemere.cljc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(ns taoensso.tufte.telemere
2+
"Handler for Telemere,
3+
Ref. <https://www.taoensso.com/telemere>."
4+
(:require
5+
[taoensso.encore :as enc]
6+
[taoensso.encore.signals :as sigs]
7+
[taoensso.tufte :as tufte]
8+
[taoensso.tufte.impl :as impl]
9+
[taoensso.telemere :as tel]))
10+
11+
(defn handler:telemere
12+
"Beta, subject to change.
13+
Returns a handler fn for use with `add-handler!` that creates a Telemere signal with:
14+
`:kind` - `:tufte`
15+
`:location` - Location of `profile` call
16+
`:id` - Id of `profile` call
17+
`:level` - Level of `profile` call (override with `:signal-level` opt)
18+
`:data` - {:keys [sample-rate ctx data pstats pstats-str_ ...]} `profile` info
19+
`:msg_` - pstats formatted as string table, may be a delay!
20+
21+
Options:
22+
`:telemere-level-fn` -- (fn [profiling-level]) => telemere-level (default to constantly `:info`)
23+
`:format-pstats-opts` - Opts map provided to `format-pstats` (default nil)"
24+
25+
([] (handler:telemere nil))
26+
([{:keys [telemere-level-fn format-pstats-opts incl-keys]
27+
:or {telemere-level-fn (fn [profiling-level] :info)}}]
28+
29+
(let []
30+
(fn a-handler:telemere [psignal]
31+
(when-let [{:keys [inst ns coords, id level, #?@(:clj [host thread]), ctx data,
32+
pstats format-pstats-fn]} psignal]
33+
34+
(taoensso.telemere/signal!
35+
{:inst inst
36+
:ns ns
37+
:coords coords
38+
:kind :tufte
39+
:id id
40+
:level (telemere-level-fn level)
41+
:data data
42+
:psignal psignal ; Won't be printed by default (good)
43+
:msg (when-let [ff format-pstats-fn] (delay (ff pstats format-pstats-opts)))
44+
:ctx+
45+
(fn [old]
46+
(if (or (nil? old) (map? old))
47+
(enc/merge-nx old ctx)
48+
(do old)))
49+
50+
#?@(:clj
51+
[:host host
52+
:thread thread])}))))))
53+
54+
(comment ((handler:telemere) (#'tufte/dummy-psignal)))

0 commit comments

Comments
 (0)