Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require ErrorLevel as argument #11

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rollbar
version: 2.1.1
version: 2.2.0
synopsis: error tracking through rollbar.com
homepage: https://github.com/flipstone/rollbar-haskell
license: MIT
Expand All @@ -22,15 +22,14 @@ ghc-options:
- -fno-warn-orphans
dependencies:
- base >=4.6 && < 5
- text >=1.2 && < 2.1
- aeson >=1.2 && < 2.2
- text >=1.2 && < 2.2
- aeson >=1.2 && < 2.3
- vector >=0.12 && < 0.14
- network >=2.6 && < 3.2
- network >=2.6 && < 3.3
- monad-control >=1.0.2 && < 1.0.4
- resourcet >=1.1 && < 1.4
- http-conduit >=2.2 && < 2.4
- lifted-base == 0.2.3.*
- network-bsd == 2.8.*

library:
source-dirs: src
Expand Down
9 changes: 4 additions & 5 deletions rollbar.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: rollbar
version: 2.1.1
version: 2.2.0
synopsis: error tracking through rollbar.com
category: Logging
homepage: https://github.com/flipstone/rollbar-haskell
Expand All @@ -27,14 +27,13 @@ library
OverloadedStrings
ghc-options: -Wall -Werror -Wcpp-undef -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -fno-warn-orphans
build-depends:
aeson >=1.2 && <2.2
aeson >=1.2 && <2.3
, base >=4.6 && <5
, http-conduit >=2.2 && <2.4
, lifted-base ==0.2.3.*
, monad-control >=1.0.2 && <1.0.4
, network >=2.6 && <3.2
, network-bsd ==2.8.*
, network >=2.6 && <3.3
, resourcet >=1.1 && <1.4
, text >=1.2 && <2.1
, text >=1.2 && <2.2
, vector >=0.12 && <0.14
default-language: Haskell2010
44 changes: 33 additions & 11 deletions src/Rollbar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Rollbar
, Person (..)
, Settings (..)
, Options (..)
, ErrorLevel (..)
, emptyOptions
, simpleLogMessage
, reportErrorS
Expand All @@ -31,7 +32,6 @@ import qualified Data.Maybe as Maybe
import qualified Data.Text as T
import qualified Data.Vector as V
import GHC.Stack (CallStack, SrcLoc (..), getCallStack)
import Network.BSD (HostName)
import Network.HTTP.Conduit
( Request (method, requestBody)
, RequestBody (RequestBodyLBS)
Expand Down Expand Up @@ -67,7 +67,7 @@ instance Aeson.ToJSON Person where
data Settings = Settings
{ environment :: Environment
, token :: ApiToken
, hostName :: HostName
, hostName :: String
, reportErrors :: Bool
}
deriving (Show)
Expand All @@ -78,6 +78,23 @@ data Options = Options
}
deriving (Show)

data ErrorLevel
= Critical
| Error
| Warning
| Info
| Debug

instance Aeson.ToJSON ErrorLevel where
toJSON lvl =
Aeson.String $
case lvl of
Critical -> "critical"
Error -> "error"
Warning -> "warning"
Info -> "info"
Debug -> "debug"

emptyOptions :: Options
emptyOptions = Options Nothing Nothing

Expand All @@ -93,6 +110,7 @@ reportErrorS ::
-- | log section
T.Text ->
Maybe CallStack ->
ErrorLevel ->
-- | log message
T.Text ->
m ()
Expand All @@ -109,11 +127,12 @@ reportLoggerErrorS ::
-- | logger that takes the section and the message
(T.Text -> T.Text -> m ()) ->
Maybe CallStack ->
ErrorLevel ->
-- | log message
T.Text ->
m ()
reportLoggerErrorS settings opts section loggerS callstack msg =
Monad.void $ reportErrorSWithOptions settings opts section (Just loggerS) msg Nothing callstack
reportLoggerErrorS settings opts section loggerS callstack errorLevel msg =
Monad.void $ reportErrorSWithOptions settings opts section (Just loggerS) msg Nothing callstack errorLevel

-- | Pass in custom fingerprint for grouping on rollbar
reportErrorSCustomFingerprint ::
Expand All @@ -125,12 +144,13 @@ reportErrorSCustomFingerprint ::
-- | logger that takes the section and the message
Maybe (T.Text -> T.Text -> m ()) ->
Maybe CallStack ->
ErrorLevel ->
-- | log message
T.Text ->
T.Text -> -- fingerprint
m ()
reportErrorSCustomFingerprint settings opts section loggerS callstack msg fingerprint =
Monad.void $ reportErrorSWithOptions settings opts section loggerS msg (Just fingerprint) callstack
reportErrorSCustomFingerprint settings opts section loggerS callstack errorLevel msg fingerprint =
Monad.void $ reportErrorSWithOptions settings opts section loggerS msg (Just fingerprint) callstack errorLevel

-- | Pass in custom fingerprint for grouping on rollbar or a custom logger
reportErrorSWithOptions ::
Expand All @@ -145,8 +165,9 @@ reportErrorSWithOptions ::
T.Text ->
Maybe T.Text -> -- fingerprint
Maybe CallStack ->
ErrorLevel ->
m (Maybe UUID)
reportErrorSWithOptions settings opts section loggerS msg fingerprint callstack =
reportErrorSWithOptions settings opts section loggerS msg fingerprint callstack errorLevel =
if reportErrors settings
then go
else pure Nothing
Expand Down Expand Up @@ -175,7 +196,7 @@ reportErrorSWithOptions settings opts section loggerS msg fingerprint callstack

logger = Maybe.fromMaybe defaultLogger loggerS section
defaultLogger message = pure $ simpleLogMessage section message
rollbarJson = buildJSON settings opts section msg fingerprint callstack
rollbarJson = buildJSON settings opts section msg fingerprint callstack errorLevel

buildFrameJSON :: (String, SrcLoc) -> Aeson.Value
buildFrameJSON (name, srcLoc) =
Expand All @@ -197,14 +218,15 @@ buildJSON ::
-- | fingerprint
Maybe T.Text ->
Maybe CallStack ->
ErrorLevel ->
Aeson.Value
buildJSON settings opts section msg fingerprint callstack =
buildJSON settings opts section msg fingerprint callstack level =
Aeson.object
[ "access_token" .= unApiToken (token settings)
, "data"
.= Aeson.object
( [ "environment" .= T.toLower (unEnvironment $ environment settings)
, "level" .= ("error" :: T.Text)
, "level" .= Aeson.toJSON level
, "server" .= Aeson.object ["host" .= hostName settings, "sha" .= optionsRevisionSha opts]
, "person" .= Aeson.toJSON (optionsPerson opts)
, "body"
Expand All @@ -222,7 +244,7 @@ buildJSON settings opts section msg fingerprint callstack =
, "notifier"
.= Aeson.object
[ "name" .= ("rollbar-haskell" :: T.Text)
, "version" .= ("2.1.0" :: T.Text)
, "version" .= ("2.2.0" :: T.Text)
]
]
where
Expand Down
1 change: 1 addition & 0 deletions src/Rollbar/MonadLogger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ reportErrorS ::
-- | monad-logger logging function. takes a section and a message
(T.Text -> T.Text -> IO ()) ->
Maybe CallStack ->
Rollbar.ErrorLevel ->
-- | message
T.Text ->
IO ()
Expand Down
Loading