@@ -36,33 +36,33 @@ def create_span_for_message(
3636 root_value = message .root
3737
3838 if isinstance (root_value , types .JSONRPCRequest ):
39- span = self .tracer .start_span ("request" )
40- span .set_attribute ("jsonrpc. type" , "request" )
41- span .set_attribute ("jsonrpc. id" , str (root_value .id ))
42- span .set_attribute ("jsonrpc. method" , root_value .method )
39+ span = self .tracer .start_span (root_value . method )
40+ span .set_attribute ("type" , "request" )
41+ span .set_attribute ("id" , str (root_value .id ))
42+ span .set_attribute ("method" , root_value .method )
4343 self ._add_request_attributes (span , root_value )
4444
4545 elif isinstance (root_value , types .JSONRPCNotification ):
46- span = self .tracer .start_span ("notification" )
47- span .set_attribute ("jsonrpc. type" , "notification" )
48- span .set_attribute ("jsonrpc. method" , root_value .method )
46+ span = self .tracer .start_span (root_value . method )
47+ span .set_attribute ("type" , "notification" )
48+ span .set_attribute ("method" , root_value .method )
4949 self ._add_notification_attributes (span , root_value )
5050
5151 elif isinstance (root_value , types .JSONRPCResponse ):
5252 span = self .tracer .start_span ("response" )
53- span .set_attribute ("jsonrpc. type" , "response" )
54- span .set_attribute ("jsonrpc. id" , str (root_value .id ))
53+ span .set_attribute ("type" , "response" )
54+ span .set_attribute ("id" , str (root_value .id ))
5555 self ._add_response_attributes (span , root_value )
5656
5757 elif isinstance (root_value , types .JSONRPCError ):
5858 span = self .tracer .start_span ("error" )
59- span .set_attribute ("jsonrpc. type" , "error" )
60- span .set_attribute ("jsonrpc. id" , str (root_value .id ))
61- span .set_attribute ("jsonrpc.error.code " , root_value .error .code )
62- span .set_attribute ("jsonrpc.error.message " , root_value .error .message )
59+ span .set_attribute ("type" , "error" )
60+ span .set_attribute ("id" , str (root_value .id ))
61+ span .set_attribute ("error_code " , root_value .error .code )
62+ span .set_attribute ("error_message " , root_value .error .message )
6363 else :
6464 span = self .tracer .start_span ("unknown" )
65- span .set_attribute ("jsonrpc.unknown_type " , str (type (root_value ).__name__ ))
65+ span .set_attribute ("type " , str (type (root_value ).__name__ ))
6666
6767 # Add context attributes
6868 for key , value in context .items ():
@@ -77,29 +77,29 @@ def _add_request_attributes(
7777 if request .params :
7878 # Add basic param information
7979 if isinstance (request .params , dict ):
80- span .set_attribute ("jsonrpc. params" , json .dumps (request .params ))
80+ span .set_attribute ("params" , json .dumps (request .params ))
8181
8282 # Handle specific request types based on method
8383 if request .method == "tools/call" and isinstance (request .params , dict ):
8484 if "name" in request .params :
85- span .set_attribute ("tool.name " , request .params ["name" ])
85+ span .set_attribute ("tool_name " , request .params ["name" ])
8686 if "arguments" in request .params and isinstance (
8787 request .params ["arguments" ], dict
8888 ):
8989 span .set_attribute (
90- "tool.args " , json .dumps (request .params ["arguments" ])
90+ "tool_args " , json .dumps (request .params ["arguments" ])
9191 )
9292
9393 # Handle specific tracing for other method types
9494 elif request .method == "resources/read" and isinstance (
9595 request .params , dict
9696 ):
9797 if "uri" in request .params :
98- span .set_attribute ("resource.uri " , str (request .params ["uri" ]))
98+ span .set_attribute ("resource_uri " , str (request .params ["uri" ]))
9999
100100 elif request .method == "prompts/get" and isinstance (request .params , dict ):
101101 if "name" in request .params :
102- span .set_attribute ("prompt.name " , str (request .params ["name" ]))
102+ span .set_attribute ("prompt_name " , str (request .params ["name" ]))
103103
104104 def _add_notification_attributes (
105105 self , span : Span , notification : types .JSONRPCNotification
@@ -109,38 +109,38 @@ def _add_notification_attributes(
109109 # Add general params attribute
110110 if isinstance (notification .params , dict ):
111111 span .set_attribute (
112- "notification.params " , json .dumps (notification .params )
112+ "notification_params " , json .dumps (notification .params )
113113 )
114114
115115 # Handle specific notification types
116116 if notification .method == "notifications/resources/updated" and isinstance (
117117 notification .params , dict
118118 ):
119119 if "uri" in notification .params :
120- span .set_attribute ("resource.uri " , str (notification .params ["uri" ]))
120+ span .set_attribute ("resource_uri " , str (notification .params ["uri" ]))
121121
122122 elif notification .method == "notifications/progress" and isinstance (
123123 notification .params , dict
124124 ):
125125 if "progress" in notification .params :
126126 span .set_attribute (
127- "progress.value " , float (notification .params ["progress" ])
127+ "progress_value " , float (notification .params ["progress" ])
128128 )
129129 if "total" in notification .params :
130130 span .set_attribute (
131- "progress.total " , float (notification .params ["total" ])
131+ "progress_total " , float (notification .params ["total" ])
132132 )
133133
134134 elif notification .method == "notifications/cancelled" and isinstance (
135135 notification .params , dict
136136 ):
137137 if "requestId" in notification .params :
138138 span .set_attribute (
139- "cancelled.requestId " , str (notification .params ["requestId" ])
139+ "cancelled_requestId " , str (notification .params ["requestId" ])
140140 )
141141 if "reason" in notification .params :
142142 span .set_attribute (
143- "cancelled.reason " , str (notification .params ["reason" ])
143+ "cancelled_reason " , str (notification .params ["reason" ])
144144 )
145145
146146 def _add_response_attributes (
@@ -149,25 +149,25 @@ def _add_response_attributes(
149149 """Add response-specific attributes to the span."""
150150 # Add any relevant attributes from the response result
151151 if isinstance (response .result , dict ):
152- span .set_attribute ("jsonrpc. result" , json .dumps (response .result ))
152+ span .set_attribute ("result" , json .dumps (response .result ))
153153
154154 def record_http_error (self , span : Span , status_code : int , text : str ) -> None :
155155 """Record HTTP error details in a span."""
156156 span .set_status (StatusCode .ERROR , f"HTTP status { status_code } " )
157- span .set_attribute ("error.type " , "http" )
158- span .set_attribute ("error.status_code " , status_code )
157+ span .set_attribute ("error_type " , "http" )
158+ span .set_attribute ("error_status_code " , status_code )
159159 span .set_attribute (
160- "error.message " , text [:1000 ] if text else ""
160+ "error_message " , text [:1000 ] if text else ""
161161 ) # Limit error message length
162162 self .logger .error (f"HTTP error: { status_code } { text } " )
163163
164164 def record_exception (self , span : Span , exception : Exception ) -> None :
165165 """Record exception details in a span."""
166166 span .set_status (StatusCode .ERROR , str (exception ))
167- span .set_attribute ("error.type " , "exception" )
168- span .set_attribute ("error.class " , exception .__class__ .__name__ )
167+ span .set_attribute ("error_type " , "exception" )
168+ span .set_attribute ("error_class " , exception .__class__ .__name__ )
169169 span .set_attribute (
170- "error.message " , str (exception )[:1000 ]
170+ "error_message " , str (exception )[:1000 ]
171171 ) # Limit error message length
172172 span .record_exception (exception )
173173 self .logger .error (f"Exception: { exception } " , exc_info = True )
0 commit comments