@@ -155,6 +155,32 @@ def handler(request: httpx2.Request) -> httpx2.Response:
155155 assert _duration_metric (capfire )["data" ]["data_points" ][0 ]["attributes" ]["error.type" ] == "httpx2.ConnectError"
156156
157157
158+ def test_opentelemetry_records_propagation_injection_exceptions (
159+ capfire : CaptureLogfire ,
160+ monkeypatch : pytest .MonkeyPatch ,
161+ ) -> None :
162+ otel = otel_module .get_opentelemetry ()
163+ assert otel is not None
164+
165+ def inject (headers : httpx2 .Headers ) -> None :
166+ raise RuntimeError ("inject failed" )
167+
168+ def handler (request : httpx2 .Request ) -> httpx2 .Response :
169+ pytest .fail ("transport should not be called" ) # pragma: no cover
170+
171+ monkeypatch .setattr (otel ._propagate , "inject" , inject )
172+
173+ transport = httpx2 .MockTransport (handler )
174+ with httpx2 .Client (transport = transport ) as client :
175+ with pytest .raises (RuntimeError , match = "inject failed" ):
176+ client .get ("https://example.com/" )
177+
178+ [span ] = _httpx2_spans (capfire )
179+ assert span .attributes ["error.type" ] == "builtins.RuntimeError"
180+ assert span .status .status_code is StatusCode .ERROR
181+ assert _duration_metric (capfire )["data" ]["data_points" ][0 ]["attributes" ]["error.type" ] == "builtins.RuntimeError"
182+
183+
158184def test_opentelemetry_records_sync_body_read_exceptions (capfire : CaptureLogfire ) -> None :
159185 def handler (request : httpx2 .Request ) -> httpx2 .Response :
160186 return httpx2 .Response (200 , stream = FailingSyncStream ())
0 commit comments