|
2 | 2 | (:require
|
3 | 3 | [cheshire.core :as json]))
|
4 | 4 |
|
| 5 | +(defn ^:private trace-tag [at] |
| 6 | + (format "[Trace - %s]" |
| 7 | + (str (.truncatedTo at java.time.temporal.ChronoUnit/MILLIS)))) |
| 8 | + |
5 | 9 | (defn ^:private trace-header
|
6 |
| - ([at description method] |
7 |
| - (format "[Trace - %s] %s '%s'" |
8 |
| - (str (.truncatedTo at java.time.temporal.ChronoUnit/MILLIS)) |
9 |
| - description |
10 |
| - method)) |
11 |
| - ([at description method id] |
12 |
| - (format "[Trace - %s] %s '%s - (%s)'" |
13 |
| - (str (.truncatedTo at java.time.temporal.ChronoUnit/MILLIS)) |
14 |
| - description |
15 |
| - method |
16 |
| - id))) |
| 10 | + ([description method] |
| 11 | + (format "%s '%s'" description method)) |
| 12 | + ([description method id] |
| 13 | + (format "%s '%s - (%s)'" description method id))) |
17 | 14 |
|
18 | 15 | (defn ^:private trace-body
|
19 | 16 | ([params] (trace-body "Params" params))
|
20 | 17 | ([label params] (str label ": " (json/generate-string params {:pretty true}))))
|
21 | 18 |
|
22 | 19 | (defn ^:private trace-str
|
23 |
| - ([header latency body] |
24 |
| - (trace-str (str header latency) body)) |
25 |
| - ([header body] |
26 |
| - (str header "\n" |
| 20 | + ([tag header latency body] |
| 21 | + (trace-str tag (str header latency) body)) |
| 22 | + ([tag header body] |
| 23 | + (str tag " " header "\n" |
27 | 24 | body "\n\n\n")))
|
28 | 25 |
|
29 | 26 | (defn ^:private latency [started finished]
|
30 | 27 | (- (.toEpochMilli finished) (.toEpochMilli started)))
|
31 | 28 |
|
32 | 29 | (defn received-notification [method params at]
|
33 |
| - (trace-str (trace-header at "Received notification" method) |
| 30 | + (trace-str (trace-tag at) |
| 31 | + (trace-header "Received notification" method) |
34 | 32 | (trace-body params)))
|
35 | 33 |
|
36 | 34 | (defn received-request [id method params at]
|
37 |
| - (trace-str (trace-header at "Received request" method id) |
| 35 | + (trace-str (trace-tag at) |
| 36 | + (trace-header "Received request" method id) |
38 | 37 | (trace-body params)))
|
39 | 38 |
|
40 | 39 | (defn received-response [id method result error started finished]
|
41 |
| - (trace-str (trace-header finished "Received response" method id) |
| 40 | + (trace-str (trace-tag finished) |
| 41 | + (trace-header "Received response" method id) |
42 | 42 | (str (format " in %sms." (latency started finished))
|
43 | 43 | (when error (format " Request failed: %s (%s)." (:message error) (:code error))))
|
44 | 44 | (if error (trace-body "Error data" (:data error)) (trace-body "Result" result))))
|
45 | 45 |
|
| 46 | +(defn received-unmatched-response [at resp] |
| 47 | + (trace-str (trace-tag at) |
| 48 | + "Received response for unmatched request:" |
| 49 | + (trace-body "Body" resp))) |
| 50 | + |
46 | 51 | (defn sending-notification [method params at]
|
47 |
| - (trace-str (trace-header at "Sending notification" method) |
| 52 | + (trace-str (trace-tag at) |
| 53 | + (trace-header "Sending notification" method) |
48 | 54 | (trace-body params)))
|
49 | 55 |
|
50 | 56 | (defn sending-request [id method params at]
|
51 |
| - (trace-str (trace-header at "Sending request" method id) |
| 57 | + (trace-str (trace-tag at) |
| 58 | + (trace-header "Sending request" method id) |
52 | 59 | (trace-body params)))
|
53 | 60 |
|
54 | 61 | (defn sending-response [id method params started finished]
|
55 |
| - (trace-str (trace-header finished "Sending response" method id) |
| 62 | + (trace-str (trace-tag finished) |
| 63 | + (trace-header "Sending response" method id) |
56 | 64 | (format ". Processing request took %sms" (latency started finished))
|
57 | 65 | (trace-body "Result" params)))
|
0 commit comments