diff --git a/lib/host/otel.sx b/lib/host/otel.sx index 7feb890f..0154971b 100644 --- a/lib/host/otel.sx +++ b/lib/host/otel.sx @@ -399,18 +399,28 @@ (define otel/recent-traces (fn () (reverse (map otel/trace-summary (otel/-trace-ids))))) ;; the dashboard's own endpoints — excluded from the "latest trace" so the -;; waterfall shows the latest REAL request (a page) instead of the 3s poll. +;; waterfall shows a real request, not the 3s poll. (define otel/-self-route? (fn (route) (or (= route "/otel") (= route "/otel/fragment") (= route "/otel/stream")))) -;; the most recent NON-self trace (fall back to any trace if all are self). +(define otel/-trace-route + (fn (trace-id) + (let ((roots (filter (fn (s) (nil? (get s :parent))) (otel/trace-spans trace-id)))) + (if (empty? roots) nil (get (get (first roots) :attrs) :http.route))))) +;; which trace the waterfall shows: prefer the newest MULTI-span trace (an +;; instrumented page render — the interesting one), else the newest non-self trace +;; (skip the poll), else the newest trace. Single-span assets/polls lose to a real +;; page render even when they're more recent. (define otel/latest-trace (fn () - (let ((real (filter (fn (s) (not (otel/-self-route? (get (get s :attrs) :http.route)))) (otel/recent)))) - (cond - ((not (empty? real)) (get (last real) :trace)) - ((not (empty? (otel/recent))) (get (last (otel/recent)) :trace)) - (else nil))))) + (let ((newest-first (reverse (otel/-trace-ids)))) + (let ((multi (filter (fn (tid) (> (len (otel/trace-spans tid)) 1)) newest-first)) + (real (filter (fn (tid) (not (otel/-self-route? (otel/-trace-route tid)))) newest-first))) + (cond + ((not (empty? multi)) (first multi)) + ((not (empty? real)) (first real)) + ((not (empty? newest-first)) (first newest-first)) + (else nil)))))) ;; ── SSE span events (SXTP) ──────────────────────────────────────────── (define otel/span-event