1
0
mirror of synced 2025-12-30 21:02:43 -05:00
Files
airbyte/airbyte-cdk/python/airbyte_cdk/sources/http_logger.py
Maxime Carbonneau-Leclerc df2a6e50bb Issue 21014/oauth requests (#27973)
* [ISSUE #27494] fix type issue caused by connector builder logging

* [ISSUE #21014] log request/response for oauth as 'global_requests'

* formatcdk

* [ISSUE #21014] support DeclarativeOauth2Authenticator as well

* [ISSUE #21014] improving message grouper tests

* formatcdk

* Test solution with logic in MessageRepository (#27990)

* Test solution with logic in MessageRepository

* Solution without creating a new ModelToComponentFactory

* [ISSUE #21014] adding tests

* [ISSUE #21014] add title and description to global requests

* Revert "Solution without creating a new ModelToComponentFactory"

This reverts commit f17799ecff.

* Automated Commit - Formatting Changes

* [ISSUE #21014] code review

* [ISSUE #21014] do not break on log appender conflict

* Automated Commit - Formatting Changes

* [ISSUE #21014] code review

* formatcdk

* [ISSUE #21014] moving is_global to is_auxiliary
2023-07-11 13:37:38 -04:00

48 lines
1.4 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from typing import Optional, Union
import requests
from airbyte_cdk.sources.message import LogMessage
def format_http_message(
response: requests.Response, title: str, description: str, stream_name: Optional[str], is_auxiliary: bool = None
) -> LogMessage:
request = response.request
log_message = {
"http": {
"title": title,
"description": description,
"request": {
"method": request.method,
"body": {
"content": _normalize_body_string(request.body),
},
"headers": dict(request.headers),
},
"response": {
"body": {
"content": response.text,
},
"headers": dict(response.headers),
"status_code": response.status_code,
},
},
"log": {
"level": "debug",
},
"url": {"full": request.url},
}
if is_auxiliary is not None:
log_message["http"]["is_auxiliary"] = is_auxiliary
if stream_name:
log_message["airbyte_cdk"] = {"stream": {"name": stream_name}}
return log_message
def _normalize_body_string(body_str: Optional[Union[str, bytes]]) -> Optional[str]:
return body_str.decode() if isinstance(body_str, (bytes, bytearray)) else body_str