otel P2: now-ns wraps host clock-milliseconds as epoch nanoseconds

Clamp against a high-water mark so the clock never steps backwards; span
durations stay non-negative. Real ns-scale timestamps replace the P1
placeholder counter.
This commit is contained in:
2026-07-01 14:24:54 +00:00
parent c8cc4a70dc
commit 51d4224a55
2 changed files with 28 additions and 6 deletions

View File

@@ -64,6 +64,22 @@
(host-ot-test "newest kept" (get (last (otel/recent)) :span) 5)
(otel/set-cap! 1000)
;; ── P2: now-ns wraps the host monotonic clock ──────────────────────
;; now-ns is real epoch NANOSECONDS (clock-milliseconds * 1e6), clamped so it
;; never goes backwards. Non-negative, non-decreasing, nanosecond-scale.
(define host-ot-n0 (otel/now-ns))
(define host-ot-n1 (otel/now-ns))
(host-ot-test "now-ns non-negative" (>= host-ot-n0 0) true)
(host-ot-test "now-ns monotonic non-decreasing" (>= host-ot-n1 host-ot-n0) true)
(host-ot-test "now-ns is nanosecond-scale" (> host-ot-n0 1000000000000000) true)
;; a real with-span straddles the host clock
(otel/reset!)
(otel/with-span "timed" {} (fn () nil))
(define host-ot-timed (first (otel/recent)))
(host-ot-test "timed span t1 >= t0" (>= (get host-ot-timed :t1) (get host-ot-timed :t0)) true)
(host-ot-test "timed span t0 nanosecond-scale" (> (get host-ot-timed :t0) 1000000000000000) true)
(define
host-ot-tests-run!
(fn