How to fix "This aggregator does not support recording long values" when using a gauge with callback? #4841
Answered
by
gabrielgiussi
gabrielgiussi
asked this question in
Q&A
-
I'm getting the following error but I don't know where should I configure a different kind of aggregator.
I've added the following dependencies to a clojure deps project.
And the code to trigger this exception is the following (ns otel
(:require [clojure.string :as str])
(:import (io.opentelemetry.api GlobalOpenTelemetry)
(io.opentelemetry.api.metrics Meter ObservableDoubleMeasurement)
(io.opentelemetry.sdk.metrics SdkMeterProvider)
(io.opentelemetry.sdk.metrics.export PeriodicMetricReader MetricExporter)
(io.opentelemetry.exporter.otlp.metrics OtlpGrpcMetricExporter)
(io.opentelemetry.sdk OpenTelemetrySdk)
(io.opentelemetry.sdk.common CompletableResultCode)
(io.opentelemetry.sdk.metrics.data AggregationTemporality)
(io.opentelemetry.exporter.logging LoggingMetricExporter)))
(defn getCpuUsage [] 42)
(let [sdk-provider (-> (SdkMeterProvider/builder)
(.registerMetricReader (.build (PeriodicMetricReader/builder (LoggingMetricExporter/create))))
(.build))]
(-> (OpenTelemetrySdk/builder)
(.setMeterProvider sdk-provider)
(.buildAndRegisterGlobal)))
(def ^Meter meter (-> (GlobalOpenTelemetry/get)
(.meterBuilder "poc")
(.setInstrumentationVersion "1.0.0")
(.build)))
(-> (.gaugeBuilder meter "some-instrument")
(.buildWithCallback (reify java.util.function.Consumer
(accept [_ measurement]
(println "observing measurement")
(.record measurement (getCpuUsage))))))
|
Beta Was this translation helpful? Give feedback.
Answered by
gabrielgiussi
Oct 12, 2022
Replies: 1 comment 1 reply
-
It was just a matter of returning a double in getCpuUsage instead of a long 🤦 , I can't delete this discussion though. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
gabrielgiussi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It was just a matter of returning a double in getCpuUsage instead of a long 🤦 , I can't delete this discussion though.