Skip to content

Commit

Permalink
Updates to request
Browse files Browse the repository at this point in the history
Updates the request as follows:
* Send the authentication token as a header
* `sha` is deprecated in favor of `code_version`
* add `haskell` as the `langauge`
  • Loading branch information
onslaughtq committed Nov 8, 2024
1 parent 784732b commit efbb889
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Rollbar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import qualified Data.Aeson as Aeson
import Data.Aeson.Types (parseMaybe)
import qualified Data.Maybe as Maybe
import qualified Data.Text as T
import qualified Data.Text.Encoding as Enc
import qualified Data.Vector as V
import GHC.Stack (CallStack, SrcLoc (..), getCallStack)
import Network.HTTP.Conduit
Expand All @@ -39,6 +40,7 @@ import Network.HTTP.Conduit
, httpLbs
, newManager
, parseUrlThrow
, requestHeaders
, tlsManagerSettings
)

Expand Down Expand Up @@ -70,7 +72,6 @@ data Settings = Settings
, hostName :: String
, reportErrors :: Bool
}
deriving (Show)

data Options = Options
{ optionsPerson :: Maybe Person
Expand Down Expand Up @@ -176,11 +177,16 @@ reportErrorSWithOptions settings opts section loggerS msg fingerprint callstack
do
logger msg
MIO.liftIO $ do
initReq <- parseUrlThrow "https://api.rollbar.com/api/1/item/"
unauthenticatedReq <- parseUrlThrow "https://api.rollbar.com/api/1/item/"
manager <- newManager tlsManagerSettings
let
req = initReq {method = "POST", requestBody = RequestBodyLBS $ Aeson.encode rollbarJson}
response <- httpLbs req manager
authenticatedRequest =
unauthenticatedReq
{ method = "POST"
, requestHeaders = [("X-Rollbar-Access-Token", Enc.encodeUtf8 . unApiToken $ token settings)]
, requestBody = RequestBodyLBS $ Aeson.encode rollbarJson
}
response <- httpLbs authenticatedRequest manager
let
body = responseBody response
uuid =
Expand Down Expand Up @@ -222,12 +228,13 @@ buildJSON ::
Aeson.Value
buildJSON settings opts section msg fingerprint callstack level =
Aeson.object
[ "access_token" .= unApiToken (token settings)
, "data"
[ "data"
.= Aeson.object
( [ "environment" .= T.toLower (unEnvironment $ environment settings)
, "level" .= Aeson.toJSON level
, "server" .= Aeson.object ["host" .= hostName settings, "sha" .= optionsRevisionSha opts]
, "code_version" .= optionsRevisionSha opts
, "language" .= ("haskell" :: T.Text)
, "server" .= Aeson.object ["host" .= hostName settings]
, "person" .= Aeson.toJSON (optionsPerson opts)
, "body"
.= Aeson.object
Expand Down

0 comments on commit efbb889

Please sign in to comment.