Skip to content

Commit

Permalink
set otel context from bindings when go block is started
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtharriger committed Feb 25, 2025
1 parent ec5667e commit 1d58bb0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
ch.qos.logback/logback-classic {:mvn/version "1.5.6"}
org.slf4j/slf4j-api {:mvn/version "2.0.13"}

;; distributed tracing
com.github.steffan-westcott/clj-otel-api {:mvn/version "0.2.7"}

;; Vector math, BM25
net.mikera/vectorz-clj {:mvn/version "0.48.0"}
com.github.rholder/snowball-stemmer {:mvn/version "1.3.0.581.1"}
Expand Down
17 changes: 14 additions & 3 deletions src/clj/fluree/db/util/async.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
[fluree.db.util.core :as util]
[fluree.db.util.log :as log]
[fluree.db.util.core #?(:clj :refer :cljs :refer-macros) [try* catch*]]
[clojure.core.async :refer [go <!] :as async]
[clojure.core.async.impl.protocols :as async-protocols])
[clojure.core.async :as async]
[clojure.core.async.impl.protocols :as async-protocols]
#?(:clj [steffan-westcott.clj-otel.context :as otel-context]))
#?(:cljs (:require-macros [fluree.db.util.async :refer [<? go-try]])))

#?(:clj (set! *warn-on-reflection* true))
Expand Down Expand Up @@ -50,6 +51,16 @@
`(let [[result# ch#] (clojure.core.async/alts!! ~ports ~@opts)]
[(throw-err result#) ch#])))

#?(:clj
(defmacro go
"Like go but catches the first thrown error and puts it on the returned channel."
[& body]
`(if-cljs
(cljs.core.async/go
(do ~@body))
(clojure.core.async/go
(otel-context/with-bound-context! ~@body)))))

#?(:clj
(defmacro go-try
"Like go but catches the first thrown error and puts it on the returned channel."
Expand All @@ -61,7 +72,7 @@
(catch js/Error e# e#)))
(clojure.core.async/go
(try
~@body
(otel-context/with-bound-context! ~@body)
(catch Throwable t# t#))))))

(defn throw-if-exception
Expand Down

0 comments on commit 1d58bb0

Please sign in to comment.