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

[logging] REST payloads are over-stringified and lose JSON structure #2276

Open
vchudnov-g opened this issue Dec 6, 2024 · 1 comment
Open
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@vchudnov-g
Copy link
Contributor

In the current version of #2270, the httpResponse.payload field is over-stringified: it's a single string with string-encoded JSON, rather than JSON object with the various fields. Since the response is coming back as JSON, we should ideally present that JSON, or at least recreate it from the response proto, without further stringifying it.

In other words, we're getting

  "httpResponse": {
    "payload": "{\n  \"content\": \"The hail in Wales falls mainly on the snails.\",\n  \"requestId\": \"some_value\",\n  \"severity\": 0,\n  \"otherRequestId\": \"\"\n}",
    "status": 200,
    // ...
    }

whereas it would be more useful to get

  "httpResponse": {
    "payload": {
      "content": "The hail in Wales falls mainly on the snails.",
      "requestId": "some_value",
      "severity": 0,
      "otherRequestId": "",
      },
    "status": 200,
   // ...
   }
@vchudnov-g
Copy link
Contributor Author

This might be happening because when populate payload in our _LOGGER.debug() statements, we convert it to JSON, and then our standard logging handler converts the resulting string to JSON yet again. In that case, it's like running json.dumps(json.dumps({"alpaha":"beta"}).

So the fix, then, would be that when we populate payload in the the _LOGGER.debug() statements, we convert the content into a Python dict (instead of a JSON string), so that when our default handler calls json.dumps(), it is handled correctly.

@vchudnov-g vchudnov-g added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants