-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f9dd90
commit 15718a0
Showing
19 changed files
with
218 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,74 @@ | ||
import httpx | ||
from _typeshed import Incomplete | ||
from collections.abc import Generator | ||
from email.headerregistry import ContentTypeHeader | ||
from logfire import Logfire as Logfire | ||
from functools import cached_property | ||
from logfire import Logfire as Logfire, LogfireSpan as LogfireSpan | ||
from logfire._internal.main import set_user_attributes_on_raw_span as set_user_attributes_on_raw_span | ||
from logfire._internal.stack_info import warn_at_user_stacklevel as warn_at_user_stacklevel | ||
from logfire._internal.utils import handle_internal_errors as handle_internal_errors | ||
from logfire.integrations.httpx import AsyncRequestHook as AsyncRequestHook, AsyncResponseHook as AsyncResponseHook, RequestHook as RequestHook, RequestInfo as RequestInfo, ResponseHook as ResponseHook, ResponseInfo as ResponseInfo | ||
from logfire.propagate import attach_context as attach_context, get_context as get_context | ||
from opentelemetry.trace import Span | ||
from typing import Any, Callable, Literal, Mapping, ParamSpec, TypeVar, TypedDict | ||
from typing import Any, Awaitable, Callable, Literal, Mapping, ParamSpec | ||
|
||
class AsyncClientKwargs(TypedDict, total=False): | ||
request_hook: RequestHook | AsyncRequestHook | ||
response_hook: ResponseHook | AsyncResponseHook | ||
skip_dep_check: bool | ||
|
||
class ClientKwargs(TypedDict, total=False): | ||
request_hook: RequestHook | ||
response_hook: ResponseHook | ||
skip_dep_check: bool | ||
|
||
class HTTPXInstrumentKwargs(TypedDict, total=False): | ||
request_hook: RequestHook | ||
response_hook: ResponseHook | ||
async_request_hook: AsyncRequestHook | ||
async_response_hook: AsyncResponseHook | ||
skip_dep_check: bool | ||
AnyRequestHook = TypeVar('AnyRequestHook', RequestHook, AsyncRequestHook) | ||
AnyResponseHook = TypeVar('AnyResponseHook', ResponseHook, AsyncResponseHook) | ||
Hook = TypeVar('Hook', RequestHook, ResponseHook) | ||
AsyncHook = TypeVar('AsyncHook', AsyncRequestHook, AsyncResponseHook) | ||
P = ParamSpec('P') | ||
|
||
def instrument_httpx(logfire_instance: Logfire, client: httpx.Client | httpx.AsyncClient | None, capture_headers: bool, capture_request_json_body: bool, capture_request_text_body: bool, capture_response_json_body: bool, capture_request_form_data: bool, **kwargs: Any) -> None: | ||
def instrument_httpx(logfire_instance: Logfire, client: httpx.Client | httpx.AsyncClient | None, capture_headers: bool, capture_request_body: bool, capture_response_body: bool, request_hook: RequestHook | AsyncRequestHook | None, response_hook: ResponseHook | AsyncResponseHook | None, async_request_hook: AsyncRequestHook | None, async_response_hook: AsyncResponseHook | None, **kwargs: Any) -> None: | ||
"""Instrument the `httpx` module so that spans are automatically created for each request. | ||
See the `Logfire.instrument_httpx` method for details. | ||
""" | ||
|
||
class LogfireHttpxRequestInfo(RequestInfo): | ||
span: Span | ||
def capture_headers(self) -> None: ... | ||
def capture_body_if_json(self, attr_name: str = 'http.request.body.json'): ... | ||
def capture_body_if_text(self, attr_name: str = 'http.request.body.text'): ... | ||
def capture_body_if_form(self, attr_name: str = 'http.request.body.form'): ... | ||
def capture_text_as_json(self, attr_name: str = 'http.request.body.json', text: str | None = None): ... | ||
@property | ||
def body_is_streaming(self): ... | ||
class LogfireHttpxInfoMixin: | ||
headers: httpx.Headers | ||
@property | ||
def content_type_header_object(self) -> ContentTypeHeader: ... | ||
@property | ||
def content_type_header_string(self) -> str: ... | ||
|
||
class LogfireHttpxRequestInfo(RequestInfo, LogfireHttpxInfoMixin): | ||
span: Span | ||
def capture_headers(self) -> None: ... | ||
def capture_body(self) -> None: ... | ||
def capture_body_if_text(self, attr_name: str = 'http.request.body.text'): ... | ||
def capture_body_if_form(self, attr_name: str = 'http.request.body.form') -> bool: ... | ||
def capture_text_as_json(self, attr_name: str, text: str): ... | ||
@property | ||
def content_type_is_json(self): ... | ||
@property | ||
def content_type_is_text(self): ... | ||
@property | ||
def content_type_is_form(self): ... | ||
def body_is_streaming(self): ... | ||
@property | ||
def content_type_charset(self): ... | ||
@property | ||
def content(self) -> bytes: ... | ||
@property | ||
def text(self) -> str: ... | ||
@property | ||
@cached_property | ||
def form_data(self) -> Mapping[str, Any] | None: ... | ||
def set_complex_span_attributes(self, attributes: dict[str, Any]): ... | ||
|
||
def make_request_hook(hook: RequestHook | None, should_capture_headers: bool, should_capture_json: bool, should_capture_text: bool, should_capture_form_data: bool) -> RequestHook | None: ... | ||
def make_async_request_hook(hook: AsyncRequestHook | RequestHook | None, should_capture_headers: bool, should_capture_json: bool, should_capture_text: bool, should_capture_form_data: bool) -> AsyncRequestHook | None: ... | ||
def capture_request(request: LogfireHttpxRequestInfo, should_capture_headers: bool, should_capture_json: bool, should_capture_text: bool, should_capture_form_data: bool) -> None: ... | ||
def make_response_hook(hook: ResponseHook | None, should_capture_headers: bool, should_capture_json: bool, logfire_instance: Logfire) -> ResponseHook | None: ... | ||
def make_async_response_hook(hook: ResponseHook | AsyncResponseHook | None, should_capture_headers: bool, should_capture_json: bool, logfire_instance: Logfire) -> AsyncResponseHook | None: ... | ||
def capture_response_json(logfire_instance: Logfire, response_info: ResponseInfo, is_async: bool) -> None: ... | ||
class LogfireHttpxResponseInfo(ResponseInfo, LogfireHttpxInfoMixin): | ||
span: Span | ||
logfire_instance: Logfire | ||
is_async: bool | ||
def capture_headers(self) -> None: ... | ||
def capture_body_if_text(self, attr_name: str = 'http.response.body.text'): ... | ||
@cached_property | ||
def response(self) -> httpx.Response: ... | ||
def on_response_read(self, hook: Callable[[LogfireSpan], None]): ... | ||
def wrap_response_read(self, hook: Callable[[Callable[[], bytes]], bytes]): ... | ||
def wrap_response_aread(self, hook: Callable[[Callable[[], Awaitable[bytes]]], Awaitable[bytes]]): ... | ||
def attach_original_span_context(self) -> Generator[None]: ... | ||
def capture_text_as_json(self, span: LogfireSpan, *, text: str, attr_name: str): ... | ||
|
||
def make_request_hook(hook: RequestHook | None, capture_headers: bool, capture_body: bool) -> RequestHook | None: ... | ||
def make_async_request_hook(hook: AsyncRequestHook | RequestHook | None, should_capture_headers: bool, should_capture_body: bool) -> AsyncRequestHook | None: ... | ||
def make_response_hook(hook: ResponseHook | None, capture_headers: bool, capture_body: bool, logfire_instance: Logfire) -> ResponseHook | None: ... | ||
def make_async_response_hook(hook: ResponseHook | AsyncResponseHook | None, should_capture_headers: bool, should_capture_body: bool, logfire_instance: Logfire) -> AsyncResponseHook | None: ... | ||
def capture_request(span: Span, request: RequestInfo, should_capture_headers: bool, should_capture_body: bool) -> LogfireHttpxRequestInfo: ... | ||
def capture_response(span: Span, request: RequestInfo, response: ResponseInfo, logfire_instance: Logfire, capture_headers: bool, capture_body: bool, *, is_async: bool) -> tuple[LogfireHttpxRequestInfo, LogfireHttpxResponseInfo]: ... | ||
async def run_async_hook(hook: Callable[P, Any] | None, *args: P.args, **kwargs: P.kwargs) -> None: ... | ||
def run_hook(hook: Callable[P, Any] | None, *args: P.args, **kwargs: P.kwargs) -> None: ... | ||
def capture_response_headers(span: Span, response: ResponseInfo) -> None: ... | ||
def capture_headers(span: Span, headers: httpx.Headers, request_or_response: Literal['request', 'response']) -> None: ... | ||
def decode_body(body: bytes, charset: str): ... | ||
def capture_request_or_response_headers(span: Span, headers: httpx.Headers, request_or_response: Literal['request', 'response']) -> None: ... | ||
|
||
CODES_FOR_METHODS_WITH_DATA_PARAM: Incomplete | ||
|
||
def content_type_header_from_string(content_type: str) -> ContentTypeHeader: ... | ||
def content_type_subtypes(subtype: str) -> set[str]: ... | ||
def is_json_type(content_type: str) -> bool: ... | ||
|
||
TEXT_SUBTYPES: Incomplete | ||
|
||
def is_text_type(content_type: str) -> bool: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.