From aaea038b9ebded2e6fbb3e9898f9302ca23195d0 Mon Sep 17 00:00:00 2001 From: Maxwell Calkin Date: Sun, 8 Mar 2026 12:17:07 -0400 Subject: [PATCH] fix: use request.content instead of request._content in otel span enrichment httpx 0.28.1 removed the private `_content` attribute from Request objects, causing an AttributeError in `enrich_span_from_request()` and `get_response_and_error()`. Use the public `.content` property instead, which is the stable httpx API for accessing raw request/response bytes. Fixes #347 Co-Authored-By: Claude Opus 4.6 --- src/mistralai/extra/observability/otel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mistralai/extra/observability/otel.py b/src/mistralai/extra/observability/otel.py index 4a8808ce..e1791713 100644 --- a/src/mistralai/extra/observability/otel.py +++ b/src/mistralai/extra/observability/otel.py @@ -91,8 +91,8 @@ def enrich_span_from_request(span: Span, request: httpx.Request) -> Span: server_attributes.SERVER_ADDRESS: request.headers.get("host", ""), server_attributes.SERVER_PORT: port }) - if request._content: - request_body = json.loads(request._content) + if request.content: + request_body = json.loads(request.content) attributes = { gen_ai_attributes.GEN_AI_REQUEST_CHOICE_COUNT: request_body.get("n", None), @@ -301,8 +301,8 @@ def get_response_and_error( if error: span.record_exception(error) span.set_status(Status(StatusCode.ERROR, str(error))) - if hasattr(response, "_content") and response._content: - response_body = json.loads(response._content) + if response.content: + response_body = json.loads(response.content) if response_body.get("object", "") == "error": if error_msg := response_body.get("message", ""): attributes = {