@@ -189,16 +189,22 @@ func (p *adkObservabilityPlugin) AfterRun(ctx agent.InvocationContext) {
189189 RecordOperationDuration (context .Background (), elapsed , metricAttrs ... )
190190 RecordAPMPlusSpanLatency (context .Background (), elapsed , metricAttrs ... )
191191
192- agentKitsAttrs := []attribute.KeyValue {
193- attribute .String ("gen_ai_operation_name" , "chain" ),
194- attribute .String ("gen_ai_operation_type" , "workflow" ),
192+ if isAgentKitRuntime {
193+ agentKitsAttrs := []attribute.KeyValue {
194+ attribute .String ("gen_ai_operation_name" , "chain" ),
195+ attribute .String ("gen_ai_operation_type" , "workflow" ),
196+ }
197+
198+ var lastErr error
199+ if val , _ := ctx .Session ().State ().Get (stateKeyLastError ); val != nil {
200+ lastErr = val .(error )
201+ }
202+ if lastErr != nil {
203+ agentKitsAttrs = append (agentKitsAttrs , attribute .String ("error_type" , "invocation_error" ))
204+ }
205+ RecordAgentKitDuration (context .Background (), elapsed , agentKitsAttrs ... )
195206 }
196207
197- var lastErr error
198- if val , _ := ctx .Session ().State ().Get (stateKeyLastError ); val != nil {
199- lastErr = val .(error )
200- }
201- RecordAgentKitDuration (context .Background (), elapsed , lastErr , agentKitsAttrs ... )
202208 }
203209
204210 }
@@ -367,7 +373,7 @@ func (p *adkObservabilityPlugin) AfterModel(ctx agent.CallbackContext, resp *mod
367373 attribute .String ("gen_ai_response_model" , meta .ModelName ),
368374 attribute .String ("gen_ai_operation_name" , "chat" ),
369375 attribute .String ("gen_ai_operation_type" , "llm" ),
370- attribute .String ("error_type" , "error " ), // Simple error type
376+ attribute .String ("error_type" , "llm_error " ), // Simple error type
371377 }
372378 RecordExceptions (context .Context (ctx ), 1 , metricAttrs ... )
373379 p .recordFinalResponseMetrics (ctx , meta , meta .ModelName , err )
@@ -590,11 +596,16 @@ func (p *adkObservabilityPlugin) recordFinalResponseMetrics(ctx agent.CallbackCo
590596 RecordOperationDuration (context .Context (ctx ), duration , metricAttrs ... )
591597 RecordAPMPlusSpanLatency (context .Context (ctx ), duration , metricAttrs ... )
592598
593- agentKitsAttrs := []attribute.KeyValue {
594- attribute .String ("gen_ai_operation_name" , "chat" ),
595- attribute .String ("gen_ai_operation_type" , "llm" ),
599+ if isAgentKitRuntime {
600+ agentKitsAttrs := []attribute.KeyValue {
601+ attribute .String ("gen_ai_operation_name" , "chat" ),
602+ attribute .String ("gen_ai_operation_type" , "llm" ),
603+ }
604+ if err != nil {
605+ agentKitsAttrs = append (agentKitsAttrs , attribute .String ("error_type" , "llm_error" ))
606+ }
607+ RecordAgentKitDuration (context .Context (ctx ), duration , agentKitsAttrs ... )
596608 }
597- RecordAgentKitDuration (context .Context (ctx ), duration , err , agentKitsAttrs ... )
598609 }
599610 }
600611}
@@ -937,11 +948,16 @@ func (p *adkObservabilityPlugin) AfterTool(ctx tool.Context, tool tool.Tool, arg
937948 RecordOperationDuration (context .Background (), duration , metricAttrs ... )
938949 RecordAPMPlusSpanLatency (context .Background (), duration , metricAttrs ... )
939950
940- agentKitsAttrs := []attribute.KeyValue {
941- attribute .String ("gen_ai_operation_name" , tool .Name ()),
942- attribute .String ("gen_ai_operation_type" , "tool" ),
951+ if isAgentKitRuntime {
952+ agentKitsAttrs := []attribute.KeyValue {
953+ attribute .String ("gen_ai_operation_name" , tool .Name ()),
954+ attribute .String ("gen_ai_operation_type" , "tool" ),
955+ }
956+ if err == nil {
957+ agentKitsAttrs = append (agentKitsAttrs , attribute .String ("error_type" , "tool_error" ))
958+ }
959+ RecordAgentKitDuration (context .Background (), duration , agentKitsAttrs ... )
943960 }
944- RecordAgentKitDuration (context .Background (), duration , err , agentKitsAttrs ... )
945961 }
946962
947963 if p .isMetricsEnabled () {
@@ -1034,6 +1050,28 @@ func (p *adkObservabilityPlugin) AfterAgent(ctx agent.CallbackContext) (*genai.C
10341050 span .End ()
10351051 }
10361052 }
1053+
1054+ meta := p .getSpanMetadata (ctx .State ())
1055+ if ! meta .StartTime .IsZero () {
1056+ if p .isMetricsEnabled () {
1057+ if isAgentKitRuntime {
1058+ duration := time .Since (meta .StartTime ).Seconds ()
1059+ agentKitsAttrs := []attribute.KeyValue {
1060+ attribute .String ("gen_ai_operation_name" , "invoke_agent" ),
1061+ attribute .String ("gen_ai_operation_type" , "agent_server" ),
1062+ }
1063+ var lastErr error
1064+ if val , _ := ctx .State ().Get (stateKeyLastError ); val != nil {
1065+ lastErr = val .(error )
1066+ }
1067+
1068+ if lastErr != nil {
1069+ agentKitsAttrs = append (agentKitsAttrs , attribute .String ("error_type" , "invoke_agent_error" ))
1070+ }
1071+ RecordAgentKitDuration (context .Background (), duration , agentKitsAttrs ... )
1072+ }
1073+ }
1074+ }
10371075 return nil , nil
10381076}
10391077
0 commit comments