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

Add HTTP Request and Response Logging #380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jvr2022
Copy link
Contributor

@Jvr2022 Jvr2022 commented Oct 16, 2024

This PR introduces a new logging feature for HTTP requests and responses. It adds a new abstract logger interface in the abstractions package, implements it in the HTTP package, and integrates it with the HttpxRequestAdapter.

Changes:

  1. Add new abstract RequestResponseLogger class
  2. Implement HttpxRequestResponseLogger in HTTP package
  3. Integrate logger in HttpxRequestAdapter
  4. Add JSON formatting support for log messages
  5. Update relevant tests

Files changed:

  • /packages/abstractions/kiota_abstractions/request_response_logger.py (new file)
  • /packages/http/httpx/kiota_http/httpx_request_response_logger.py (new file)
  • /packages/http/httpx/kiota_http/httpx_request_adapter.py
  • /packages/serialization/json/kiota_serialization_json/json_serialization_writer.py
  • /packages/http/httpx/tests/test_httpx_request_adapter.py

This PR introduces a new logging feature for HTTP requests and responses. It adds a new abstract logger interface in the abstractions package, implements it in the HTTP package, and integrates it with the HttpxRequestAdapter.

Changes:
1. Add new abstract RequestResponseLogger class
2. Implement HttpxRequestResponseLogger in HTTP package
3. Integrate logger in HttpxRequestAdapter
4. Add JSON formatting support for log messages
5. Update relevant tests

Files changed:
- /packages/abstractions/kiota_abstractions/request_response_logger.py (new file)
- /packages/http/httpx/kiota_http/httpx_request_response_logger.py (new file)
- /packages/http/httpx/kiota_http/httpx_request_adapter.py
- /packages/serialization/json/kiota_serialization_json/json_serialization_writer.py
- /packages/http/httpx/tests/test_httpx_request_adapter.py
@Jvr2022 Jvr2022 requested a review from a team as a code owner October 16, 2024 10:44
Copy link

sonarcloud bot commented Oct 16, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I did leave a couple of questions and suggestions for improvements in the implementation.
Let us know if you have any additional comments or questions.

@@ -525,6 +528,20 @@ async def get_http_response_message(

self.set_base_url_for_request_information(request_info)

self.logger.log_request({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the logging logic here instead of in a middleware handler?

@@ -387,6 +387,10 @@ def get_serialized_content(self) -> bytes:
stream = json_string.encode('utf-8')
return stream

@staticmethod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid expanding the API surface and look into an alternative here please?

from abc import ABC, abstractmethod
from typing import Any, Dict

class RequestResponseLogger(ABC):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we look into an alternative that does not expand the public API surface here please?

@Jvr2022
Copy link
Contributor Author

Jvr2022 commented Oct 18, 2024

I will take a look

Copy link
Contributor

github-actions bot commented Nov 9, 2024

This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress 🚧
Development

Successfully merging this pull request may close these issues.

2 participants