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

createItem not serializing Nothings correctly #23

Open
tillydray opened this issue Oct 29, 2021 · 1 comment
Open

createItem not serializing Nothings correctly #23

tillydray opened this issue Oct 29, 2021 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@tillydray
Copy link

We are using katip for logging. So we want to create a Rollbar.Item from a Katip.Item and we have this function

mkRollbarItem :: Katip.LogItem a => Katip.Item a -> Rollbar.Item
mkRollbarItem katipItem =
  let payload =
        Rollbar.PayloadMessage $
          Rollbar.Message
            { Rollbar.messageBody =
                LT.toStrict . TB.toLazyText . coerce $
                  Katip._itemMessage katipItem
            , Rollbar.messageMetadata = katipItemToObject katipItem
            }
   in
      Rollbar.Item
        { Rollbar.itemEnvironment = Rollbar.Environment "production"
        , Rollbar.itemBody = Rollbar.Body payload
        , Rollbar.itemLevel =
            katipSeverityToRollbarLevel $
              Katip._itemSeverity katipItem
        , Rollbar.itemPlatform = Nothing
        , Rollbar.itemLanguage = Just "Haskell"
        , Rollbar.itemFramework = Nothing
        , Rollbar.itemRequest = Nothing
        , Rollbar.itemServer = Nothing
        , Rollbar.itemNotifier = Rollbar.Notifier "" ""
        }

Note that both Rollbar.itemServer and Rollbar.itemPlatform are listed as Maybes in the Rollbar.Client docs. And yet, we get this error. The ellipsis is irrelevant stuff

(StatusCodeException (Response {responseStatus = Status {statusCode = 422, statusMessage = "Unprocessable Entity"}, ... "{\n \"err\": 1,\n \"message\": \"Invalid format. data.platform should be string. data.server should be object.\"\n}")))

So we did

let rollbarItem = mkRollbarItem katipItem
_ <- Debug.trace (LBS.unpack $ Aeson.encode rollbarItem) (Rollbar.createItem rollbarItem)

and noticed that platform, server, and other Nothings were serialized as {"server":null, "platform":null, ...}, which seems to make rollbar api unhappy.

@Centeno448 Centeno448 added good first issue Good for newcomers bug Something isn't working labels May 8, 2023
@DavidMazarro
Copy link
Member

A starting point for anyone that wants to tackle this issue: the create item docs of the Rollbar API states that some of the fields are optional, so instead of being serialized as "server": null or "platform": null like what's currently happening, they should be left out of the request when set to Nothing. This should be reflected in the ToJSON Item instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants