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

Log Headers and Content of HTTP Requests in Trace Mode #368

Closed
Tracked by #241
vikman90 opened this issue Nov 29, 2024 · 0 comments · Fixed by #383
Closed
Tracked by #241

Log Headers and Content of HTTP Requests in Trace Mode #368

vikman90 opened this issue Nov 29, 2024 · 0 comments · Fixed by #383
Assignees
Labels
level/task Task issue module/agent mvp Minimum Viable Product refinement type/change Change performed in a resource or Wazuh Cloud environment

Comments

@vikman90
Copy link
Member

Parent Issue: #241

Description

Currently, the Wazuh Agent logs the endpoint, response status code, headers, and full response content of HTTP requests in debug mode. For example:

[2024-11-29 13:37:30.763] [wazuh-agent] [debug] [DEBUG] [http_client.cpp:352] [PerformHttpRequestInternal] Request endpoint: /api/v1/authentication
Response: HTTP/1.1 200 OK
X-Imposter-Request: 5c902f05-a0cc-45a3-b0b2-88993db93d17
Server: imposter
content-length: 316

{"token":"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJXYXp1aCIsImF1ZCI6IldhenVoIENvbW11bmljYXRpb25zIEFQSSIsImlhdCI6MTczMjg4Mzg1MCwiZXhwIjoxNzMyODg0NzUwLCJ1dWlkIjoiMGM5ZmQxZTctN2NiNi00Zjk4LWI4ZmEtNDlhNzE0OTA1ZGI0In0.MEUCIBZOtmWuLDJBxyECmjU4MKzKBL7xDPghhgSv_MvXVqq5AiEAmXMBbdBpYn3jeRqaEaYvyki4PKAeX-g3Klo1D7my8lQ"}

Logging headers and the full content of HTTP requests in debug mode generates excessive noise in the logs, making debugging harder rather than easier.

Expected Behavior

  • In debug mode:
    • Log the request endpoint and response status code.
  • In trace mode:
    • Log detailed information, including request headers, response headers, and the full response content.

Proposed Solution

Refactor the logging logic in the HTTP client to separate logging levels as follows:

  • Debug Mode:
    [2024-11-29 13:37:30.763] [wazuh-agent] [debug] [DEBUG] [http_client.cpp:352] [PerformHttpRequestInternal] Request endpoint: /api/v1/authentication
    [2024-11-29 13:37:30.763] [wazuh-agent] [debug] [DEBUG] [http_client.cpp:353] [PerformHttpRequestInternal] Response: HTTP/1.1 200 OK
    
  • Trace Mode:
    [2024-11-29 13:37:30.763] [wazuh-agent] [trace] [TRACE] [http_client.cpp:352] [PerformHttpRequestInternal] Request headers:
    Content-Type: application/json
    Authorization: Bearer <token>
    X-Imposter-Request: 5c902f05-a0cc-45a3-b0b2-88993db93d17
    
    [2024-11-29 13:37:30.763] [wazuh-agent] [trace] [TRACE] [http_client.cpp:353] [PerformHttpRequestInternal] Response headers:
    Server: imposter
    Content-Length: 316
    
    [2024-11-29 13:37:30.763] [wazuh-agent] [trace] [TRACE] [http_client.cpp:354] [PerformHttpRequestInternal] Response content:
    {"token":"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJXYXp1aCIsImF1ZCI6IldhenVoIENvbW11bmljYXRpb25zIEFQSSIsImlhdCI6MTczMjg4Mzg1MCwiZXhwIjoxNzMyODg0NzUwLCJ1dWlkIjoiMGM5ZmQxZTctN2NiNi00Zjk4LWI4ZmEtNDlhNzE0OTA1ZGI0In0.MEUCIBZOtmWuLDJBxyECmjU4MKzKBL7xDPghhgSv_MvXVqq5AiEAmXMBbdBpYn3jeRqaEaYvyki4PKAeX-g3Klo1D7my8lQ"}
    
@vikman90 vikman90 added level/task Task issue type/change Change performed in a resource or Wazuh Cloud environment module/agent mvp Minimum Viable Product refinement labels Nov 29, 2024
@wazuhci wazuhci moved this to Backlog in Release 5.0.0 Nov 29, 2024
@vikman90 vikman90 self-assigned this Dec 3, 2024
@wazuhci wazuhci moved this from Backlog to In progress in Release 5.0.0 Dec 3, 2024
@vikman90 vikman90 linked a pull request Dec 3, 2024 that will close this issue
@wazuhci wazuhci moved this from In progress to Done in Release 5.0.0 Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue module/agent mvp Minimum Viable Product refinement type/change Change performed in a resource or Wazuh Cloud environment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant