hs-opentelemetry-sdk-1.0.0.0: src/platform/unix/OpenTelemetry/Platform.hs
{- |
Module : OpenTelemetry.Platform
Description : Unix-specific platform utilities for the OpenTelemetry SDK.
Stability : experimental
-}
module OpenTelemetry.Platform where
import Control.Exception (throwIO, try)
import qualified Data.Text as T
import System.IO.Error (isDoesNotExistError)
import System.Posix.Process (getParentProcessID)
import System.Posix.User (getEffectiveUserName)
tryGetUser :: IO (Maybe T.Text)
tryGetUser = do
eResult <- try getEffectiveUserName
case eResult of
Left err ->
if isDoesNotExistError err
then pure Nothing
else throwIO err
Right ok -> pure $ Just $ T.pack ok
tryGetParentProcessID :: IO (Maybe Int)
tryGetParentProcessID =
Just . fromIntegral <$> getParentProcessID