{- |
 Module      :  OpenTelemetry.Resource.Container
 Copyright   :  (c) Ian Duncan, 2021
 License     :  BSD-3
 Description :  Detect & provide resource info about a container
 Maintainer  :  Ian Duncan
 Stability   :  experimental
 Portability :  non-portable (GHC extensions)
-}
module OpenTelemetry.Resource.Container where

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


{- | A container instance.

@since 0.0.1.0
-}
data Container = Container
  { Container -> Maybe Text
containerName :: Maybe Text
  {- ^ Container name used by container runtime.

  Examples: 'opentelemetry-autoconf'
  -}
  , Container -> Maybe Text
containerId :: Maybe Text
  -- ^ Container ID. Usually a UUID, as for example used to identify Docker containers. The UUID might be abbreviated.
  , Container -> Maybe Text
containerRuntime :: Maybe Text
  -- ^ The container runtime managing this container.
  , Container -> Maybe Text
containerImageName :: Maybe Text
  -- ^ Name of the image the container was built on.
  , Container -> Maybe Text
containerImageTag :: Maybe Text
  -- ^ Container image tag.
  , Container -> Maybe Text
containerImageId :: Maybe Text
  -- ^ Runtime-specific image identifier (e.g., digest).
  , Container -> Maybe Text
ociManifestDigest :: Maybe Text
  -- ^ The digest of the OCI image manifest.
  , Container -> Maybe [Text]
containerImageRepoDigests :: Maybe [Text]
  -- ^ Repo digests of the container image.
  }


instance ToResource Container where
  toResource :: Container -> Resource
toResource Container {Maybe [Text]
Maybe Text
containerName :: Container -> Maybe Text
containerId :: Container -> Maybe Text
containerRuntime :: Container -> Maybe Text
containerImageName :: Container -> Maybe Text
containerImageTag :: Container -> Maybe Text
containerImageId :: Container -> Maybe Text
ociManifestDigest :: Container -> Maybe Text
containerImageRepoDigests :: Container -> Maybe [Text]
containerName :: Maybe Text
containerId :: Maybe Text
containerRuntime :: Maybe Text
containerImageName :: Maybe Text
containerImageTag :: Maybe Text
containerImageId :: Maybe Text
ociManifestDigest :: Maybe Text
containerImageRepoDigests :: 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.container_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.container_id Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerId
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.container_runtime_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerRuntime
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.container_runtime Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerRuntime
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.container_image_name Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerImageName
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.container_image_id Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
containerImageId
      , AttributeKey [Text] -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey [Text]
SC.container_image_tags Text -> Maybe [Text] -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? ((Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: []) (Text -> [Text]) -> Maybe Text -> Maybe [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
containerImageTag)
      , AttributeKey Text -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey Text
SC.oci_manifest_digest Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
ociManifestDigest
      , AttributeKey [Text] -> Text
forall a. AttributeKey a -> Text
unkey AttributeKey [Text]
SC.container_image_repoDigests Text -> Maybe [Text] -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe [Text]
containerImageRepoDigests
      ]