Add GenAI semantic-convention attributes to OpenTelemetryMiddleware
Merged
KL
5mo ago+137+137+012345678901234567890123456789-15-15-01234567890123456789
Adds the GenAI semantic-convention attributes from the MCP OTel spans spec (mcp.common.attributes) to OpenTelemetryMiddleware:
gen_ai.operation.name=execute_toolfortools/call(per the spec, set only for tool calls).gen_ai.tool.namefortools/call,gen_ai.prompt.nameforprompts/get.error.typeandrpc.response.status_codeset to the JSON-RPC error code on failures;error.type=tool_errorfor atools/callresult carryingis_error(spec:CallToolResultwithisErrortrue).mcp.protocol.version.
The span name now follows the spec's {mcp.method.name} {target} format (dropping the prior MCP handle prefix).
The tools/call result is matched against both the CallToolResult model and the dict shapes (isError/is_error) handlers may return, since result coercion happens after the middleware runs.
The sensitive opt_in attributes (gen_ai.tool.call.arguments/result, gen_ai.prompt.variable.*) are intentionally left out; they can be added later behind an opt-in flag.
AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.