           (swap! traces conj (assoc ~trace
                                :duration duration#
                                :end (interop/now)))
-          (run-tracing-callbacks!))))
+          (run-tracing-callbacks! end#))))
 
  (defmacro with-trace
      "Create a trace inside the scope of the with-trace macro

   :child-of  (or child-of (:id *current-trace*))
   :start     (interop/now)})

(defn debounce [f interval]
  #?(:cljs (goog.functions/debounce f interval)
     :clj  (f)))

(def run-tracing-callbacks!
  (debounce
    (fn tracing-cb-debounced []
      (doseq [[k cb] @trace-cbs]


(def trace-cbs (atom {}))
(defonce traces (atom []))
(defonce next-delivery (atom 0))

(defn register-trace-cb
  "Registers a tracing callback function which will receive a collection of one or more traces.
