steffan-westcott / clj-otel

An idiomatic Clojure API for adding telemetry to your libraries and applications using OpenTelemetry.
https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api
Apache License 2.0
183 stars 12 forks source link

Gauge API Ergonomics #15

Closed rschmukler closed 6 months ago

rschmukler commented 6 months ago

Hey! Thank you for your work on the library. I am trying to use a gauge and having some trouble navigating the API.

1) It doesn't look like there's a synchronous version of the API yet. Is this something that you would be open to a PR adding support for?

2) If an async gauge has different attributes, what is the best way for the polling function function to submit multiple readings for the different attributes. eg. Imagine in your :location :reactor-core example we also wanted to submit a reading for :location :exterior - What would be the best way to do so?

steffan-westcott commented 6 months ago
  1. Synchronous gauges are a recent addition to the OpenTelemetry API, I will add support for these soon.
  2. When creating asynchronous instruments, the function observe may return either a single measurement (a map) or a sequence of measurements (a sequence of maps). In your example, I suggest returning both measurements as a vector:
    (defn read-temperatures []
    (let [core-temp (get-core-temp)
        exterior-temp (get-exterior-temp)]
    [{:value core-temp
      :attributes {:location :reactor-core}}
     {:value exterior-temp
      :attributes {:location :exterior}}]))
steffan-westcott commented 6 months ago

@rschmukler Looking a bit deeper into synchronous gauge support in OpenTelemetry Java, I see they are still in the incubator stage of the API. To date, clj-otel-api has the bare minimum of OpenTelemetry Java dependencies and is focussed on the stable parts of the API. Therefore, the opentelemetry-extension-incubator dependency is not likely to be added. Thank you for highlighting synchronous gauges (I had forgotten they are coming!) and please be assured I will add support when they come out of incubation.

rschmukler commented 6 months ago

Awesome! Thank you for the reply. I didn't know that multiple measurements could be returned. I will submit a PR to the guide highlighting this. Looking forward to sync gauges stabilizing. Thanks again for your work on this library, it has been great to use!