{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

{- |
 Module      :  OpenTelemetry.Resource.Service
 Copyright   :  (c) Ian Duncan, 2021
 License     :  BSD-3
 Description :  Resource information about a "service"
 Maintainer  :  Ian Duncan
 Stability   :  experimental
 Portability :  non-portable (GHC extensions)
-}
module OpenTelemetry.Resource.Service where

import Data.Text
import OpenTelemetry.Resource


-- | A service instance
data Service = Service
  { Service -> Text
serviceName :: Text
  -- ^ Logical name of the service.
  --
  -- MUST be the same for all instances of horizontally scaled services.
  -- If the value was not specified, SDKs MUST fallback to unknown_service: concatenated with process.executable.name,
  -- e.g. unknown_service:bash. If process.executable.name is not available, the value MUST be set to unknown_service.
  --
  -- If using the built-in resource detectors, this can be specified via the
  -- @OTEL_SERVICE_NAME@ environment variable
  --
  -- Example: @shoppingcart@
  , Service -> Maybe Text
serviceNamespace :: Maybe Text
  -- ^ A namespace for service.name.
  --
  -- A string value having a meaning that helps to distinguish a group of services, for example the team name that owns a group of services. service.name is expected to be unique within the same namespace. If service.namespace is not specified in the Resource then service.name is expected to be unique for all services that have no explicit namespace defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length namespace string is assumed equal to unspecified namespace.
  --
  -- Example: @Shop@
  , Service -> Maybe Text
serviceInstanceId :: Maybe Text
  -- ^ The string ID of the service instance.
  --
  -- Example: @627cc493-f310-47de-96bd-71410b7dec09@
  , Service -> Maybe Text
serviceVersion :: Maybe Text
  -- ^ The version string of the service API or implementation.
  --
  -- Example: @2.0.0@
  }


instance ToResource Service where
  type ResourceSchema Service = 'Nothing
  toResource :: Service -> Resource (ResourceSchema Service)
toResource Service {Maybe Text
Text
serviceName :: Service -> Text
serviceNamespace :: Service -> Maybe Text
serviceInstanceId :: Service -> Maybe Text
serviceVersion :: Service -> Maybe Text
serviceName :: Text
serviceNamespace :: Maybe Text
serviceInstanceId :: Maybe Text
serviceVersion :: Maybe Text
..} =
    [Maybe (Text, Attribute)] -> Resource 'Nothing
forall (r :: Maybe Symbol). [Maybe (Text, Attribute)] -> Resource r
mkResource
      [ Text
"service.name" Text -> Text -> Maybe (Text, Attribute)
forall a. ToAttribute a => Text -> a -> Maybe (Text, Attribute)
.= Text
serviceName
      , Text
"service.namespace" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
serviceNamespace
      , Text
"service.instance.id" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
serviceInstanceId
      , Text
"service.version" Text -> Maybe Text -> Maybe (Text, Attribute)
forall a.
ToAttribute a =>
Text -> Maybe a -> Maybe (Text, Attribute)
.=? Maybe Text
serviceVersion
      ]