{- |
 Module      :  OpenTelemetry.Resource.OperatingSystem
 Copyright   :  (c) Ian Duncan, 2021
 License     :  BSD-3
 Description :  Information about the operating system (OS) on which the process represented by this resource is running.
 Maintainer  :  Ian Duncan
 Stability   :  experimental
 Portability :  non-portable (GHC extensions)

 In case of virtualized environments, this is the operating system as it is observed by the process, i.e., the virtualized guest rather than the underlying host.
-}
module OpenTelemetry.Resource.OperatingSystem where

import Data.Text (Text)
import OpenTelemetry.Attributes.Key (unkey)
import OpenTelemetry.Resource
import qualified OpenTelemetry.SemanticConventions as SC


{- | The operating system (OS) on which the process represented by this resource is running.

@since 0.0.1.0
-}
data OperatingSystem = OperatingSystem
  { OperatingSystem -> Text
osType :: Text
  {- ^ The operating system type.

  MUST be one of the following or, if none of the listed values apply, a custom value:

  +-----------------+---------------------------------------+
  | Value           | Description                           |
  +=================+=======================================+
  | @windows@       | Microsoft Windows                     |
  +-----------------+---------------------------------------+
  | @linux@         | Linux                                 |
  +-----------------+---------------------------------------+
  | @darwin@        | Apple Darwin                          |
  +-----------------+---------------------------------------+
  | @freebsd@       | FreeBSD                               |
  +-----------------+---------------------------------------+
  | @netbsd@        | NetBSD                                |
  +-----------------+---------------------------------------+
  | @openbsd@       | OpenBSD                               |
  +-----------------+---------------------------------------+
  | @dragonflybsd@  | DragonFly BSD                         |
  +-----------------+---------------------------------------+
  | @hpux@          | HP-UX (Hewlett Packard Unix)          |
  +-----------------+---------------------------------------+
  | @aix@           | AIX (Advanced Interactive eXecutive)  |
  +-----------------+---------------------------------------+
  | @solaris@       | Oracle Solaris                        |
  +-----------------+---------------------------------------+
  | @zos@           | IBM z/OS                              |
  +-----------------+---------------------------------------+
  -}
  , OperatingSystem -> Maybe Text
osDescription :: Maybe Text
  -- ^ Human readable (not intended to be parsed) OS version information, like e.g. reported by @ver@ or @lsb_release -a@ commands.
  , OperatingSystem -> Maybe Text
osName :: Maybe Text
  -- ^ Human readable operating system name.
  , OperatingSystem -> Maybe Text
osVersion :: Maybe Text
  -- ^ The version string of the operating system as defined in
  , OperatingSystem -> Maybe Text
osBuildId :: Maybe Text
  -- ^ Unique identifier for a particular build or compilation of the operating system.
  }


instance ToResource OperatingSystem where
  toResource :: OperatingSystem -> Resource
toResource OperatingSystem {Maybe Text
Text
osType :: OperatingSystem -> Text
osDescription :: OperatingSystem -> Maybe Text
osName :: OperatingSystem -> Maybe Text
osVersion :: OperatingSystem -> Maybe Text
osBuildId :: OperatingSystem -> Maybe Text
osType :: Text
osDescription :: Maybe Text
osName :: Maybe Text
osVersion :: Maybe Text
osBuildId :: 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.os_type Text -> Text -> Maybe (Text, Attribute)
forall a. ToAttribute a => Text -> a -> Maybe (Text, Attribute)
.= Text
osType
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.os_description Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
osDescription
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.os_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
osName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.os_version Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
osVersion
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.os_buildId Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
osBuildId
      ]