Skip to content

Commit

Permalink
Don't fail when getting posix user isn't possible
Browse files Browse the repository at this point in the history
  • Loading branch information
iand675 committed Dec 25, 2021
1 parent 902ea73 commit 63cffbf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sdk/hs-opentelemetry-sdk.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.22
-- see: https://github.com/sol/hpack

name: hs-opentelemetry-sdk
version: 0.0.2.1
version: 0.0.2.2
synopsis: OpenTelemetry SDK for use in applications.
description: Please see the README on GitHub at <https://github.com/iand675/hs-opentelemetry/tree/main/sdk#readme>
category: OpenTelemetry, Telemetry, Monitoring, Observability, Metrics
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_common/lib: !include "../package-common.yaml"

name: hs-opentelemetry-sdk
version: 0.0.2.1
version: 0.0.2.2

<<: *preface

Expand Down
13 changes: 12 additions & 1 deletion sdk/src/OpenTelemetry/Resource/Process/Detector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import System.Posix.User (getEffectiveUserName)
import System.Info
import Data.Version
import OpenTelemetry.Resource.Process
import Control.Exception (try, throwIO)
import System.IO.Error

-- | Create a 'Process' 'Resource' based off of the current process' knowledge
-- of itself.
Expand All @@ -22,7 +24,16 @@ detectProcess = do
pure Nothing <*>
pure Nothing <*>
(Just . map T.pack <$> getArgs) <*>
(Just . T.pack <$> getEffectiveUserName)
tryGetUser

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

-- | A 'ProcessRuntime' 'Resource' populated with the current process' knoweldge
-- of itself.
Expand Down

0 comments on commit 63cffbf

Please sign in to comment.