@@ -20,38 +20,6 @@ class FastMCPInstrumentor:
2020 def __init__ (self ):
2121 self ._tracer = None
2222
23- def _find_fastmcp_server_name (self , instance ):
24- """Find the FastMCP server name by inspecting the call stack and garbage collector."""
25- try :
26- # First, try to find the server by checking if this tool manager belongs to a FastMCP server
27- for obj in gc .get_objects ():
28- # Look for FastMCP instances that have this tool manager
29- print ("NOMI - _find_fastmcp_server_name: obj:" , obj )
30- if (hasattr (obj , '__class__' ) and
31- obj .__class__ .__name__ == 'FastMCP' and
32- hasattr (obj , '_tool_manager' ) and
33- obj ._tool_manager is instance ):
34- if hasattr (obj , 'name' ) and obj .name :
35- print ("NOMI - _find_fastmcp_server_name: obj.name:" , obj .name )
36- return obj .name
37- break
38-
39- # Fallback: Try to find any FastMCP server in the current frame stack
40- current_frame = inspect .currentframe ()
41- while current_frame :
42- for local_var in current_frame .f_locals .values ():
43- if (hasattr (local_var , '__class__' ) and
44- local_var .__class__ .__name__ == 'FastMCP' and
45- hasattr (local_var , 'name' ) and local_var .name ):
46- print ("NOMI - _find_fastmcp_server_name: local_var.name:" , local_var .name )
47- return local_var .name
48- current_frame = current_frame .f_back
49-
50- except Exception :
51- pass
52-
53- return None
54-
5523 def instrument (self , tracer : Tracer ):
5624 """Apply FastMCP-specific instrumentation."""
5725 self ._tracer = tracer
@@ -74,8 +42,6 @@ def _fastmcp_tool_wrapper(self):
7442 """Create wrapper for FastMCP tool execution."""
7543 @dont_throw
7644 async def traced_method (wrapped , instance , args , kwargs ):
77- print ("NOMI - _fastmcp_tool_wrapper: args:" , args )
78- print ("NOMI - _fastmcp_tool_wrapper: kwargs:" , kwargs )
7945 if not self ._tracer :
8046 return await wrapped (* args , ** kwargs )
8147
@@ -94,29 +60,13 @@ async def traced_method(wrapped, instance, args, kwargs):
9460
9561 entity_name = tool_key if tool_key else "unknown_tool"
9662
97- # Best practice: read FastMCP server name from execution context
98- context = None
99- if kwargs and 'context' in kwargs :
100- context = kwargs .get ('context' )
101- elif args and len (args ) >= 3 :
102- # call_tool(self, key, arguments, context=...)
103- context = args [2 ]
104-
105- server_name = None
106- if context is not None :
107- fastmcp_obj = getattr (context , 'fastmcp' , None )
108- if fastmcp_obj is not None :
109- server_name = getattr (fastmcp_obj , 'name' , None )
110- print ("NOMI - _fastmcp_tool_wrapper: server_name:" , server_name )
111-
11263 # Create parent server.mcp span
11364 with self ._tracer .start_as_current_span ("mcp.server" ) as mcp_span :
65+ mcp_span .set_attribute (SpanAttributes .TRACELOOP_WORKFLOW_NAME , str (instance ))
11466 mcp_span .set_attribute (SpanAttributes .TRACELOOP_SPAN_KIND , "server" )
11567 mcp_span .set_attribute (SpanAttributes .TRACELOOP_ENTITY_NAME , "mcp.server" )
11668
117- # # Try to set the FastMCP server name as workflow name (prefer context, fallback to discovery)
118- # if not server_name:
119- # server_name = self._find_fastmcp_server_name(instance)
69+ server_name = instance .name if hasattr (instance , 'name' ) else "unknown_instance"
12070 if server_name :
12171 mcp_span .set_attribute (SpanAttributes .TRACELOOP_WORKFLOW_NAME , f"{ server_name } .mcp" )
12272
@@ -126,10 +76,6 @@ async def traced_method(wrapped, instance, args, kwargs):
12676 tool_span .set_attribute (SpanAttributes .TRACELOOP_SPAN_KIND , TraceloopSpanKindValues .TOOL .value )
12777 tool_span .set_attribute (SpanAttributes .TRACELOOP_ENTITY_NAME , entity_name )
12878
129- # Set workflow name on tool span as well if we found it
130- if server_name :
131- tool_span .set_attribute (SpanAttributes .TRACELOOP_WORKFLOW_NAME , server_name )
132-
13379 if self ._should_send_prompts ():
13480 try :
13581 input_data = {
0 commit comments