Skip to content

Conversation

@elaine-mattos
Copy link
Contributor

Description

After the recent logging changes in PR #1340, Winston started throwing Converting circular structure to JSON errors when logging HTTP requests/responses or Axios errors. This was caused by req, res, and config objects containing circular references that cannot be stringified directly.

Changes made

  1. Introduced a new sanitizeMeta Winston format to safely summarize log metadata.
  2. Summarizes the following objects instead of logging them directly:
    • req → only logs { method, url, requestId, correlationId }
    • res → only logs { statusCode }
    • config (Axios request config) → only logs { method, url, headers['X-Api-Key'] }
  3. Generic request/response aliases are replaced with "[request omitted]" / "[response omitted]" when no req/res exist.
  4. Keeps stack traces and main error message intact.

Log examples

Before this fix:

2026-01-02T16:55:40.936Z [error]: SvcRequestFailure: /status/toolsranperday Converting circular structure to JSON
Exception: 
Error: SvcRequestFailure: /status/toolsranperday Converting circular structure to JSON
    --> starting at object with constructor 'ClientRequest'
    |     property 'res' -> object with constructor 'IncomingMessage'
    --- property 'req' closes the circle
GET /status/toolsranperday 500 31.963 ms

After this fix:

2026-01-02T16:52:49.612Z [error]: Status service failed for toolsranperday Request failed with status code 404
{
  "name": "AxiosError",
  "code": "ERR_BAD_REQUEST",
  "config": {
    "method": "post",
    "url": "https://api.applicationinsights.io/v1/apps/<APP_ID>/query",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json; charset=utf-8",
      "User-Agent": "clearlydefined.io crawler",
      "X-Api-Key": "<REDACTED>",
      "Content-Length": "349",
      "Accept-Encoding": "gzip, compress, deflate, br"
    }
  },
  "request": "[request omitted]",
  "response": "[response omitted]",
  "status": 404,
  "statusCode": 404,
  "stack": "AxiosError: Request failed with status code 404\n    at async callFetch (...) \n    at async StatusService._toolsranperday (...) \n    at async StatusService.get (...) \n    at async getRequests (...)"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant