otel-effectful-1.0.0: src/Effectful/OpenTelemetry/Metrics/Metadata.hs
module Effectful.OpenTelemetry.Metrics.Metadata where
import Control.Applicative ((<|>))
import Data.Text (Text)
import Effectful.OpenTelemetry.Protocol.Attributes (Attributes)
import GHC.Generics (Generic)
import Prelude
-- | The optional descriptive parameters an instrument may carry.
--
-- See <https://opentelemetry.io/docs/specs/otel/metrics/api/#instrument the OpenTelemetry spec>.
data Metadata = Metadata
{ attributes :: Attributes
, description :: Maybe Text
, unit :: Maybe Text
}
deriving stock (Generic, Show, Eq)
-- | Merges 'attributes', right-biased for the 'Maybe' fields.
instance Semigroup Metadata where
a <> b =
Metadata
{ attributes = a.attributes <> b.attributes
, description = b.description <|> a.description
, unit = b.unit <|> a.unit
}
instance Monoid Metadata where
mempty =
Metadata
{ attributes = mempty
, description = Nothing
, unit = Nothing
}