clj-otel

steffan 2025-06-14T22:12:25.425609Z

@devurandom I've added new middleware wrap-span and wrap-bound-span and updated the microservices examples to demonstrate recording of uncaught exceptions in https://github.com/steffan-westcott/clj-otel/commit/66e2447cc11c997b9b762696ce2a44a51180bbbd

❤️ 2
1
devurandom 2025-07-14T07:41:20.665239Z

Thanks! I'll more closely examine the behaviour with regards to different modes of launching the application. > How are you launching your application? I start an nREPL using clojure with an alias from a compose file, and then connect and start HTTP server (via a user/go function) from Cursive.

devurandom 2025-07-12T14:16:54.083149Z

Thanks! I'm using that code now in our service (copied it, until there is a clj-otel release) and so far it seems to work well! One issue I noticed is that code.file.path and code.line.number point at the wrap-span function (because they are inserted by the with-span! macro) and are thus not very useful. Then I tried inserting the middleware into the stack, with:

(defmacro span-opts-fn
  [span-name-fn]
  `(fn [request#]
     {:name   (~span-name-fn request#)
      :source {:line ~(:line (meta &form))
               :file ~*file*}}))
,,,
#(trace-span/wrap-span % (span-opts-fn (fn [{:keys             [request-method uri]
                                             {route :template} :reitit.core/match}]
                                         (format "handle %s %s" (str/upper-case (name request-method)) (or route uri)))))
The source map part is copied straight from steffan-westcott.clj-otel.api.trace.span/with-span!. This gives me a more useful file/line reference in the trace. But now I have a different oddity: Without overriding source, the code.file.path I see in OTel (Azure.Dashboard) is "nice", relative to the classpath. But when overriding source in my own code, I get an "ugly", absolute path. Any idea how to get both? Both a nice, short path, and file/line pointing to the place where I insert my middleware?

steffan 2025-07-13T20:42:33.481939Z

You may need to review how your application is launched. I've noticed that processes launched with the clojure or java command, *file* always gives the resource file path. On the other hand, processes launched with the IntelliJ/Cursive process launcher, *file* gives the absolute file path. I've also noticed that files read from JAR files on the classpath will always give resource file paths.

steffan 2025-07-13T20:43:29.386629Z

I don't fully understand this behaviour, this is based from observations.

steffan 2025-07-13T20:55:37.782549Z

How are you launching your application?