{- |
 Module      :  OpenTelemetry.Resource.Host
 Copyright   :  (c) Ian Duncan, 2021
 License     :  BSD-3
 Description :  Information about the underlying general computing instance
 Maintainer  :  Ian Duncan
 Stability   :  experimental
 Portability :  non-portable (GHC extensions)
-}
module OpenTelemetry.Resource.Host (
  Host (..),
) where

import Data.Text (Text)
import OpenTelemetry.Attributes.Key (unkey)
import OpenTelemetry.Resource (ToResource (..), mkResourceWithSchema, semConvSchemaUrl, (.=?))
import qualified OpenTelemetry.SemanticConventions as SC


{- | A host is defined as a general computing instance.

@since 0.0.1.0
-}
data Host = Host
  { Host -> Maybe Text
hostId :: Maybe Text
  -- ^ Unique host ID. For Cloud, this must be the instance_id assigned by the cloud provider.
  , Host -> Maybe Text
hostName :: Maybe Text
  -- ^ Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
  , Host -> Maybe Text
hostType :: Maybe Text
  -- ^ Type of host. For Cloud, this must be the machine type.
  , Host -> Maybe Text
hostArch :: Maybe Text
  -- ^ The CPU architecture the host system is running on.
  , Host -> Maybe Text
hostImageName :: Maybe Text
  -- ^ Name of the VM image or OS install the host was instantiated from.
  , Host -> Maybe Text
hostImageId :: Maybe Text
  -- ^ VM image ID. For Cloud, this value is from the provider.
  , Host -> Maybe Text
hostImageVersion :: Maybe Text
  -- ^ The version string of the VM image as defined in Version Attributes.
  , Host -> Maybe [Text]
hostIp :: Maybe [Text]
  -- ^ Host IP addresses.
  , Host -> Maybe [Text]
hostMac :: Maybe [Text]
  -- ^ MAC addresses of the host.
  }


instance ToResource Host where
  toResource :: Host -> Resource
toResource Host {Maybe [Text]
Maybe Text
hostId :: Host -> Maybe Text
hostName :: Host -> Maybe Text
hostType :: Host -> Maybe Text
hostArch :: Host -> Maybe Text
hostImageName :: Host -> Maybe Text
hostImageId :: Host -> Maybe Text
hostImageVersion :: Host -> Maybe Text
hostIp :: Host -> Maybe [Text]
hostMac :: Host -> Maybe [Text]
hostId :: Maybe Text
hostName :: Maybe Text
hostType :: Maybe Text
hostArch :: Maybe Text
hostImageName :: Maybe Text
hostImageId :: Maybe Text
hostImageVersion :: Maybe Text
hostIp :: Maybe [Text]
hostMac :: Maybe [Text]
..} =
    Maybe Text -> [Maybe (Text, Attribute)] -> Resource
mkResourceWithSchema
      (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
semConvSchemaUrl)
      [ AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_id Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostId
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_type Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostType
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_arch Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostArch
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_image_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostImageName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_image_id Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostImageId
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.host_image_version Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
hostImageVersion
      , AttributeKey [Text] -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey [Text]
SC.host_ip Text -> Maybe [Text] -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe [Text]
hostIp
      , AttributeKey [Text] -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey [Text]
SC.host_mac Text -> Maybe [Text] -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe [Text]
hostMac
      ]