{-# LANGUAGE DeriveGeneric #-}
module Instana.SDK.Span.RootEntry
( RootEntry(..)
, spanId
, traceId
, addData
, addToErrorCount
, setServiceName
) where
import Data.Aeson (Value)
import qualified Data.Aeson.Extra.Merge as AesonExtra
import Data.Text (Text)
import GHC.Generics
import Instana.SDK.Internal.Id (Id)
data RootEntry =
RootEntry
{
spanAndTraceId :: Id
, spanName :: Text
, timestamp :: Int
, errorCount :: Int
, serviceName :: Maybe Text
, spanData :: Value
} deriving (Eq, Generic, Show)
traceId :: RootEntry -> Id
traceId = spanAndTraceId
spanId :: RootEntry -> Id
spanId = spanAndTraceId
addToErrorCount :: Int -> RootEntry -> RootEntry
addToErrorCount increment rootEntry =
let
ec = errorCount rootEntry
in
rootEntry { errorCount = ec + increment }
setServiceName :: Text -> RootEntry -> RootEntry
setServiceName serviceName_ rootEntry =
rootEntry { serviceName = Just serviceName_ }
addData :: Value -> RootEntry -> RootEntry
addData newData rootEntry =
let
currentData = spanData rootEntry
mergedData = AesonExtra.lodashMerge currentData newData
in
rootEntry { spanData = mergedData }