@@ -62,7 +62,6 @@ def traced_method(wrapped, instance, args, kwargs):
6262
6363 def _fastmcp_tool_wrapper (self ):
6464 """Create wrapper for FastMCP tool execution."""
65- @dont_throw
6665 async def traced_method (wrapped , instance , args , kwargs ):
6766 if not self ._tracer :
6867 return await wrapped (* args , ** kwargs )
@@ -111,13 +110,25 @@ async def traced_method(wrapped, instance, args, kwargs):
111110
112111 try :
113112 result = await wrapped (* args , ** kwargs )
113+ except Exception as e :
114+ tool_span .set_attribute (ERROR_TYPE , type (e ).__name__ )
115+ tool_span .record_exception (e )
116+ tool_span .set_status (Status (StatusCode .ERROR , str (e )))
114117
118+ mcp_span .set_attribute (ERROR_TYPE , type (e ).__name__ )
119+ mcp_span .record_exception (e )
120+ mcp_span .set_status (Status (StatusCode .ERROR , str (e )))
121+ raise
122+
123+ try :
115124 # Add output in traceloop format to tool span
116125 if self ._should_send_prompts () and result :
117126 try :
118127 # Convert FastMCP Content objects to serializable format
128+ # Note: result.content for fastmcp 2.12.2+, fallback to result for older versions
119129 output_data = []
120- for item in result :
130+ result_items = result .content if hasattr (result , 'content' ) else result
131+ for item in result_items :
121132 if hasattr (item , 'text' ):
122133 output_data .append ({"type" : "text" , "content" : item .text })
123134 elif hasattr (item , '__dict__' ):
@@ -136,17 +147,9 @@ async def traced_method(wrapped, instance, args, kwargs):
136147
137148 tool_span .set_status (Status (StatusCode .OK ))
138149 mcp_span .set_status (Status (StatusCode .OK ))
139- return result
140-
141- except Exception as e :
142- tool_span .set_attribute (ERROR_TYPE , type (e ).__name__ )
143- tool_span .record_exception (e )
144- tool_span .set_status (Status (StatusCode .ERROR , str (e )))
145-
146- mcp_span .set_attribute (ERROR_TYPE , type (e ).__name__ )
147- mcp_span .record_exception (e )
148- mcp_span .set_status (Status (StatusCode .ERROR , str (e )))
149- raise
150+ except Exception :
151+ pass
152+ return result
150153
151154 return traced_method
152155
0 commit comments