@@ -57,6 +57,66 @@ def before_breadcrumb(crumb, hint):
5757 )
5858
5959
60+ @pytest .mark .parametrize (
61+ "httpx_client" ,
62+ (httpx .Client (), httpx .AsyncClient ()),
63+ )
64+ @pytest .mark .parametrize (
65+ "status_code,level" ,
66+ [
67+ (200 , None ),
68+ (301 , None ),
69+ (403 , "warning" ),
70+ (405 , "warning" ),
71+ (500 , "error" ),
72+ ],
73+ )
74+ def test_crumb_capture_client_error (
75+ sentry_init , capture_events , httpx_client , httpx_mock , status_code , level
76+ ):
77+ httpx_mock .add_response (status_code = status_code )
78+
79+ sentry_init (integrations = [HttpxIntegration ()])
80+
81+ url = "http://example.com/"
82+
83+ with start_transaction ():
84+ events = capture_events ()
85+
86+ if asyncio .iscoroutinefunction (httpx_client .get ):
87+ response = asyncio .get_event_loop ().run_until_complete (
88+ httpx_client .get (url )
89+ )
90+ else :
91+ response = httpx_client .get (url )
92+
93+ assert response .status_code == status_code
94+ capture_message ("Testing!" )
95+
96+ (event ,) = events
97+
98+ crumb = event ["breadcrumbs" ]["values" ][0 ]
99+ assert crumb ["type" ] == "http"
100+ assert crumb ["category" ] == "httplib"
101+
102+ if level is None :
103+ assert "level" not in crumb
104+ else :
105+ assert crumb ["level" ] == level
106+
107+ assert crumb ["data" ] == ApproxDict (
108+ {
109+ "url" : url ,
110+ SPANDATA .HTTP_METHOD : "GET" ,
111+ SPANDATA .HTTP_FRAGMENT : "" ,
112+ SPANDATA .HTTP_QUERY : "" ,
113+ SPANDATA .HTTP_STATUS_CODE : status_code ,
114+ "reason" : "OK" ,
115+ "extra" : "foo" ,
116+ }
117+ )
118+
119+
60120@pytest .mark .parametrize (
61121 "httpx_client" ,
62122 (httpx .Client (), httpx .AsyncClient ()),
0 commit comments