otel-effectful-1.0.0: src/Effectful/OpenTelemetry/Metrics/Instrument.hs
{-# LANGUAGE GADTs #-}
module Effectful.OpenTelemetry.Metrics.Instrument where
import Data.Text (Text)
import Effectful.OpenTelemetry.Metrics.Measurement (Measurement)
import Effectful.OpenTelemetry.Timestamp (Timestamp)
import Prelude
-- | Used to report 'Measurement's.
--
-- See <https://opentelemetry.io/docs/specs/otel/metrics/api/#instrument the OpenTelemetry spec>.
class Instrument i where
-- | The name of the instrument.
name :: i -> Text
-- | Take a reading of the instrument, along with the time it was recorded.
--
-- An instrument may report several 'Measurement's: an asynchronous
-- instrument backed by a multiple-instrument callback reports one per
-- metric it covers. Reporting none means there is nothing to export yet.
sample :: i -> IO [(Timestamp, Measurement)]
-- | A wrapper type for any 'Instrument' @i@ for all @i@.
data SomeInstrument = forall i. (Instrument i) => SomeInstrument i
instance Instrument SomeInstrument where
name (SomeInstrument i) = name i
sample (SomeInstrument i) = sample i