Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: json parse error in middleware (#8187)

cthomas9fbefb62a0ba
diff --git a/letta/otel/tracing.py b/letta/otel/tracing.py
index 68217f58e..a2b8c86a1 100644
--- a/letta/otel/tracing.py
+++ b/letta/otel/tracing.py
@@ -112,14 +112,17 @@ async def _update_trace_attributes(request: Request):
if header_value:
span.set_attribute(span_key, header_value)
- # Add request body if available
- try:
- with tracer.start_as_current_span("trace.request_body"):
- body = await request.json()
- for key, value in body.items():
- span.set_attribute(f"http.request.body.{key}", str(value))
- except Exception:
- pass
+ # Add request body if available (only for JSON requests)
+ content_type = request.headers.get("content-type", "")
+ if "application/json" in content_type and request.method in ("POST", "PUT", "PATCH"):
+ try:
+ with tracer.start_as_current_span("trace.request_body"):
+ body = await request.json()
+ for key, value in body.items():
+ span.set_attribute(f"http.request.body.{key}", str(value))
+ except Exception:
+ # Ignore JSON parsing errors (empty body, invalid JSON, etc.)
+ pass
async def _trace_error_handler(_request: Request, exc: Exception) -> JSONResponse: