module Rollbar.Item
(
debug
, info
, warning
, error
, critical
, Item(..)
, module Rollbar.AccessToken
, AccessToken(..)
, module Rollbar.Item.Data
, Data(..)
, Context(..)
, Fingerprint(..)
, Framework(..)
, Title(..)
, UUID4(..)
, module Rollbar.Item.Body
, Body(..)
, MessageBody(..)
, module Rollbar.Item.Environment
, Environment(..)
, module Rollbar.Item.Level
, Level(..)
, module Rollbar.Item.CodeVersion
, CodeVersion(..)
, module Rollbar.Item.Hardcoded
, Hardcoded(..)
, module Rollbar.Item.Person
, Person(..)
, Email(..)
, Id(..)
, Username(..)
, module Rollbar.Item.Request
, Get(..)
, Headers(..)
, IP(..)
, Method(..)
, QueryString(..)
, RawBody(..)
, URL(..)
, module Rollbar.Item.Server
, Server(..)
, Branch(..)
, Root(..)
) where
import Data.Aeson (KeyValue, ToJSON, object, pairs, toEncoding, toJSON, (.=))
import Data.Maybe (fromMaybe)
import Data.Version (showVersion)
import GHC.Generics (Generic)
import Prelude hiding (error)
import Rollbar.AccessToken
import Rollbar.Item.Body
import Rollbar.Item.CodeVersion
import Rollbar.Item.Data
import Rollbar.Item.Environment
import Rollbar.Item.Hardcoded
import Rollbar.Item.Level
import Rollbar.Item.Person
import Rollbar.Item.Request
import Rollbar.Item.Server
import Rollbar.Item.Internal.Notifier
import Rollbar.Item.Internal.Platform
import System.Info (os)
import qualified Data.Text as T
import qualified Paths_wai_middleware_rollbar
debug :: Environment -> Maybe MessageBody -> payload -> Data payload
debug environment messageBody payload =
Data
{ body = Message (fromMaybe "" messageBody) payload
, codeVersion =
SemVer . T.pack $ showVersion Paths_wai_middleware_rollbar.version
, context = Nothing
, custom = Nothing
, environment = environment
, fingerprint = Nothing
, framework = Nothing
, language = Hardcoded
, level = Debug
, notifier = Notifier Hardcoded Paths_wai_middleware_rollbar.version
, person = Nothing
, platform = Platform $ T.pack os
, request = Nothing
, server = Nothing
, timestamp = Nothing
, title = Nothing
, uuid = Nothing
}
info :: Environment -> Maybe MessageBody -> payload -> Data payload
info environment messageBody payload =
(debug environment messageBody payload) { level = Info }
warning :: Environment -> Maybe MessageBody -> payload -> Data payload
warning environment messageBody payload =
(debug environment messageBody payload) { level = Warning }
error :: Environment -> Maybe MessageBody -> payload -> Data payload
error environment messageBody payload =
(debug environment messageBody payload) { level = Error }
critical :: Environment -> Maybe MessageBody -> payload -> Data payload
critical environment messageBody payload =
(debug environment messageBody payload) { level = Critical }
data Item a
= Item
{ accessToken :: AccessToken
, itemData :: Data a
}
deriving (Eq, Generic, Show)
itemKVs :: (KeyValue kv, ToJSON v) => Item v -> [kv]
itemKVs Item{..} =
[ "access_token" .= accessToken
, "data" .= itemData
]
instance ToJSON a => ToJSON (Item a) where
toJSON = object . itemKVs
toEncoding = pairs . mconcat . itemKVs