Skip to content

Commit 5d0971a

Browse files
committed
[new] Add Telemere handler
1 parent 063251d commit 5d0971a

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
:dependencies
4040
[[org.clojure/test.check "1.1.1"]
41+
[com.taoensso/telemere "1.0.0-RC5"]
4142
[com.taoensso/timbre "6.7.0"]]
4243

4344
:plugins

src/taoensso/tufte/telemere.cljc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
"Alpha, subject to change.
13+
Returns a signal handler that:
14+
- Takes a Tufte profiling signal (map).
15+
- Creates a corresponding Telemere signal for handling by Telemere.
16+
17+
The Telemere signal will include:
18+
As in Tufte signal: #{:inst :ns :coords :id :level :data :host :thread}
19+
And:
20+
`:kind` --------- `:tufte`
21+
`:msg_` --------- Delay of `pstats` formatted as string table
22+
`:ctx` ---------- (merge `telemere/*ctx*` `tufte/*ctx*`)
23+
`:tufte-signal` - Original Tufte signal (map)
24+
25+
Options:
26+
`:telemere-level-fn` -- (fn [profiling-level]) => telemere-level (default to constantly `:info`)
27+
`:format-pstats-opts` - Opts map provided to `format-pstats` (default nil)"
28+
29+
([] (handler:telemere nil))
30+
([{:keys [telemere-level-fn format-pstats-opts incl-keys]
31+
:or {telemere-level-fn (fn [profiling-level] profiling-level)}}]
32+
33+
(let []
34+
(fn a-handler:telemere [signal]
35+
(when-let [{:keys [inst ns coords, id level, #?@(:clj [host thread]), ctx data,
36+
pstats format-pstats-fn]} signal]
37+
38+
(taoensso.telemere/signal!
39+
{:inst inst
40+
:ns ns
41+
:coords coords
42+
:kind :tufte
43+
:id id
44+
:level (telemere-level-fn level)
45+
:data data
46+
:tufte-signal signal ; Won't be printed by default (good)
47+
:msg (when-let [ff format-pstats-fn] (delay (ff pstats format-pstats-opts)))
48+
:ctx+
49+
(fn [old]
50+
(if (or (nil? old) (map? old))
51+
(enc/merge-nx old ctx)
52+
(do old)))
53+
54+
#?@(:clj
55+
[:host host
56+
:thread thread])}))))))
57+
58+
(comment ((handler:telemere) (#'tufte/dummy-signal)))

0 commit comments

Comments
 (0)