Skip to content

Commit 2352acb

Browse files
committed
[core] Returning the wrong type on trace/capture fn causes mulog to silently stop recording logs and traces Fix #119
1 parent ac57949 commit 2352acb

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

mulog-core/src/com/brunobonacci/mulog.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ For more information, please visit: https://github.com/BrunoBonacci/mulog
392392
(core/log-trace ~event-name tid# ptid# (- (System/nanoTime) t0#) ts# :ok pairs#
393393
;; if there is something to capture form the evaluation result
394394
;; then use the capture function
395-
(core/on-error {:mulog/capture :error} (when capture# (capture# r#))))
395+
(core/on-error {:mulog/capture :error}
396+
(when capture#
397+
(let [captured# (capture# r#)]
398+
(if (or (map? captured#) (nil? captured#))
399+
captured#
400+
{:mulog/capture :error
401+
:mulog/capture-message "Invalid type returned, :capture fn must return a map!"})))))
396402
;; return the body result
397403
r#)
398404
;; If and exception occur, then log the error.

mulog-core/src/com/brunobonacci/mulog/core.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
(delay ;; Delay the task initialisation at runtime (GraalVM)
144144
(rb/recurring-task
145145
PUBLISH-INTERVAL
146-
(fn []
146+
(fn dispatch-publishers-task []
147147
(let [pubs @publishers
148148
;; group-by buffer
149149
pubs (group-by :buffer (map second pubs))]

mulog-core/test/com/brunobonacci/mulog_test.clj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,21 @@
506506
:mulog/capture :error})]))
507507

508508

509+
(fact "success case but failing extraction with wrong type returned"
510+
(tp/with-test-publisher
511+
(u/trace :test
512+
{:pairs [:key1 "value1"]
513+
:capture (constantly 1)}
514+
{:http-status 200 :body "OK"}))
515+
516+
=> (just
517+
[(contains
518+
{:mulog/event-name :test
519+
:key1 "value1"
520+
:mulog/capture :error
521+
:mulog/capture-message "Invalid type returned, :capture fn must return a map!"})]))
522+
523+
509524
(fact "extraction can redefine internal properties such as :outcome and :exception"
510525
(tp/with-test-publisher
511526
(u/trace :test

0 commit comments

Comments
 (0)