Hoist ToolError imports to module level, add rpc.* migration note

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
William Easton 2026-04-14 13:30:40 -05:00
commit 63744015c5
No known key found for this signature in database
3 changed files with 6 additions and 6 deletions

View file

@ -193,6 +193,10 @@ def risky_operation() -> str:
## Attributes Reference
<Warning>
**Migrating from v3.1 or earlier:** The `rpc.system`, `rpc.service`, and `rpc.method` span attributes were removed in favor of the [MCP semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/mcp/) listed below. If you have dashboards or alerts keyed on those `rpc.*` attributes, update them to use `mcp.method.name` and the `fastmcp.*` attributes instead.
</Warning>
### MCP Semantic Conventions
FastMCP implements the [OpenTelemetry MCP semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/mcp/):

View file

@ -5,6 +5,7 @@ from contextlib import contextmanager
from opentelemetry.trace import Span, SpanKind, Status, StatusCode
from fastmcp.exceptions import ToolError as _ToolError
from fastmcp.telemetry import get_tracer
@ -44,8 +45,6 @@ def client_span(
yield span
except Exception as e:
if span.is_recording():
from fastmcp.exceptions import ToolError as _ToolError
error_type = (
"tool_error" if isinstance(e, _ToolError) else type(e).__qualname__
)

View file

@ -7,6 +7,7 @@ from mcp.server.lowlevel.server import request_ctx
from opentelemetry.context import Context
from opentelemetry.trace import Span, SpanKind, Status, StatusCode
from fastmcp.exceptions import ToolError as _ToolError
from fastmcp.telemetry import extract_trace_context, get_tracer
@ -95,8 +96,6 @@ def server_span(
yield span
except Exception as e:
if span.is_recording():
from fastmcp.exceptions import ToolError as _ToolError
error_type = (
"tool_error" if isinstance(e, _ToolError) else type(e).__qualname__
)
@ -132,8 +131,6 @@ def delegate_span(
yield span
except Exception as e:
if span.is_recording():
from fastmcp.exceptions import ToolError as _ToolError
error_type = (
"tool_error" if isinstance(e, _ToolError) else type(e).__qualname__
)