3333
3434logger = get_logger (__name__ )
3535
36+ meter_uploader = None
3637
37- def _upload_metrics (
38+
39+ def _upload_call_llm_metrics (
3840 invocation_context : InvocationContext ,
3941 event_id : str ,
4042 llm_request : LlmRequest ,
@@ -47,11 +49,27 @@ def _upload_metrics(
4749 for tracer in tracers :
4850 for exporter in getattr (tracer , "exporters" , []):
4951 if getattr (exporter , "meter_uploader" , None ):
50- exporter .meter_uploader .record (
52+ global meter_uploader
53+ meter_uploader = exporter .meter_uploader
54+ exporter .meter_uploader .record_call_llm (
5155 invocation_context , event_id , llm_request , llm_response
5256 )
5357
5458
59+ def _upload_tool_call_metrics (
60+ tool : BaseTool ,
61+ args : dict [str , Any ],
62+ function_response_event : Event ,
63+ ):
64+ global meter_uploader
65+ if meter_uploader :
66+ meter_uploader .record_tool_call (tool , args , function_response_event )
67+ else :
68+ logger .warning (
69+ "Meter uploader is not initialized yet. Skip recording tool call metrics."
70+ )
71+
72+
5573def _set_agent_input_attribute (
5674 span : Span , invocation_context : InvocationContext
5775) -> None :
@@ -203,6 +221,8 @@ def trace_tool_call(
203221 response : ExtractorResponse = attr_extractor (params )
204222 ExtractorResponse .update_span (span , attr_name , response )
205223
224+ _upload_tool_call_metrics (tool , args , function_response_event )
225+
206226
207227def trace_call_llm (
208228 invocation_context : InvocationContext ,
@@ -252,7 +272,7 @@ def trace_call_llm(
252272 response : ExtractorResponse = attr_extractor (params )
253273 ExtractorResponse .update_span (span , attr_name , response )
254274
255- _upload_metrics (invocation_context , event_id , llm_request , llm_response )
275+ _upload_call_llm_metrics (invocation_context , event_id , llm_request , llm_response )
256276
257277
258278# Do not modify this function
0 commit comments