Stop flagging snake_case is_error results as tool errors in OTel span (#2971)

This commit is contained in:
Marcelo Trylesinski 2026-06-25 17:24:45 +02:00 • committed by GitHub
commit 96bf22e57a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -59,8 +59,12 @@ class OpenTelemetryMiddleware(ServerMiddleware[Any]):
span.set_status(StatusCode.ERROR, str(e))
raise
if ctx.method == "tools/call":
# Tool errors are detected pre-serialization, so only shapes that reach the wire as an error
# count: the model, or the camelCase alias (`is_error` is dropped by the alias-only wire
# validation). A raw-dict `isError` is matched as a literal bool only - non-bool coercible
# values (1, "true") would serialize to an error but are rare enough to leave undetected.
match result:
case CallToolResult(is_error=True) | {"isError": True} | {"is_error": True}:
case CallToolResult(is_error=True) | {"isError": True}:
span.set_attribute("error.type", "tool_error")
span.set_status(StatusCode.ERROR)
case _: