@@ -8,7 +8,7 @@ from logfire._internal.utils import handle_internal_errors as handle_internal_er
8
8
from logfire .integrations .httpx import AsyncRequestHook as AsyncRequestHook , AsyncResponseHook as AsyncResponseHook , RequestHook as RequestHook , RequestInfo as RequestInfo , ResponseHook as ResponseHook , ResponseInfo as ResponseInfo
9
9
from logfire .propagate import attach_context as attach_context , get_context as get_context
10
10
from opentelemetry .trace import Span
11
- from typing import Any , Callable , Literal , ParamSpec , TypeVar , TypedDict
11
+ from typing import Any , Callable , Literal , Mapping , ParamSpec , TypeVar , TypedDict
12
12
13
13
class AsyncClientKwargs (TypedDict , total = False ):
14
14
request_hook : RequestHook | AsyncRequestHook
@@ -32,28 +32,55 @@ Hook = TypeVar('Hook', RequestHook, ResponseHook)
32
32
AsyncHook = TypeVar ('AsyncHook' , AsyncRequestHook , AsyncResponseHook )
33
33
P = ParamSpec ('P' )
34
34
35
- def instrument_httpx (logfire_instance : Logfire , client : httpx .Client | httpx .AsyncClient | None , capture_headers : bool , capture_request_json_body : bool , capture_response_json_body : bool , capture_request_form_data : bool , ** kwargs : Any ) -> None :
35
+ 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 :
36
36
"""Instrument the `httpx` module so that spans are automatically created for each request.
37
37
38
38
See the `Logfire.instrument_httpx` method for details.
39
39
"""
40
- def make_request_hook (hook : RequestHook | None , should_capture_headers : bool , should_capture_json : bool , should_capture_form_data : bool ) -> RequestHook | None : ...
41
- def make_async_request_hook (hook : AsyncRequestHook | RequestHook | None , should_capture_headers : bool , should_capture_json : bool , should_capture_form_data : bool ) -> AsyncRequestHook | None : ...
42
- def capture_request (request : RequestInfo , span : Span , should_capture_headers : bool , should_capture_json : bool , should_capture_form_data : bool ) -> None : ...
40
+
41
+ class LogfireHttpxRequestInfo (RequestInfo ):
42
+ span : Span
43
+ def capture_headers (self ) -> None : ...
44
+ def capture_body_if_json (self , attr_name : str = 'http.request.body.json' ): ...
45
+ def capture_body_if_text (self , attr_name : str = 'http.request.body.text' ): ...
46
+ def capture_body_if_form (self , attr_name : str = 'http.request.body.form' ): ...
47
+ def capture_text_as_json (self , attr_name : str = 'http.request.body.json' , text : str | None = None ): ...
48
+ @property
49
+ def body_is_streaming (self ): ...
50
+ @property
51
+ def content_type_header_object (self ) -> ContentTypeHeader : ...
52
+ @property
53
+ def content_type_header_string (self ) -> str : ...
54
+ @property
55
+ def content_type_is_json (self ): ...
56
+ @property
57
+ def content_type_is_text (self ): ...
58
+ @property
59
+ def content_type_is_form (self ): ...
60
+ @property
61
+ def content_type_charset (self ): ...
62
+ @property
63
+ def content (self ) -> bytes : ...
64
+ @property
65
+ def text (self ) -> str : ...
66
+ @property
67
+ def form_data (self ) -> Mapping [str , Any ] | None : ...
68
+ def set_complex_span_attributes (self , attributes : dict [str , Any ]): ...
69
+
70
+ 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 : ...
71
+ 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 : ...
72
+ def capture_request (request : LogfireHttpxRequestInfo , should_capture_headers : bool , should_capture_json : bool , should_capture_text : bool , should_capture_form_data : bool ) -> None : ...
43
73
def make_response_hook (hook : ResponseHook | None , should_capture_headers : bool , should_capture_json : bool , logfire_instance : Logfire ) -> ResponseHook | None : ...
44
74
def make_async_response_hook (hook : ResponseHook | AsyncResponseHook | None , should_capture_headers : bool , should_capture_json : bool , logfire_instance : Logfire ) -> AsyncResponseHook | None : ...
45
75
def capture_response_json (logfire_instance : Logfire , response_info : ResponseInfo , is_async : bool ) -> None : ...
46
76
async def run_async_hook (hook : Callable [P , Any ] | None , * args : P .args , ** kwargs : P .kwargs ) -> None : ...
47
77
def run_hook (hook : Callable [P , Any ] | None , * args : P .args , ** kwargs : P .kwargs ) -> None : ...
48
78
def capture_response_headers (span : Span , response : ResponseInfo ) -> None : ...
49
- def capture_request_headers (span : Span , request : RequestInfo ) -> None : ...
50
79
def capture_headers (span : Span , headers : httpx .Headers , request_or_response : Literal ['request' , 'response' ]) -> None : ...
51
80
def decode_body (body : bytes , charset : str ): ...
52
- def capture_request_body (span : Span , request : RequestInfo ) -> None : ...
53
81
54
82
CODES_FOR_METHODS_WITH_DATA_PARAM : Incomplete
55
83
56
- def capture_request_form_data (span : Span , request : RequestInfo ) -> None : ...
57
84
def content_type_header_from_string (content_type : str ) -> ContentTypeHeader : ...
58
85
def content_type_subtypes (subtype : str ) -> set [str ]: ...
59
86
def is_json_type (content_type : str ) -> bool : ...
0 commit comments