@@ -399,20 +399,31 @@ export async function executeToolAndReport(
399399 } ,
400400 async ( otelSpan ) => {
401401 const startedAt = Date . now ( )
402- const completion = await executeToolAndReportInner ( toolCall , context , execContext , options )
403- const durationMs = Date . now ( ) - startedAt
404- otelSpan . setAttribute ( TraceAttr . ToolOutcome , completion . status )
405- otelSpan . setAttribute ( TraceAttr . ToolDurationMs , durationMs )
406- if ( completion . message ) {
407- otelSpan . setAttribute (
408- TraceAttr . ToolOutcomeMessage ,
409- String ( completion . message ) . slice ( 0 , 500 )
410- )
402+ try {
403+ const completion = await executeToolAndReportInner ( toolCall , context , execContext , options )
404+ const durationMs = Date . now ( ) - startedAt
405+ otelSpan . setAttribute ( TraceAttr . ToolOutcome , completion . status )
406+ otelSpan . setAttribute ( TraceAttr . ToolDurationMs , durationMs )
407+ if ( completion . message ) {
408+ otelSpan . setAttribute (
409+ TraceAttr . ToolOutcomeMessage ,
410+ String ( completion . message ) . slice ( 0 , 500 )
411+ )
412+ }
413+ // Durable Grafana signal for "which Sim tool is slowest" (executor=sim);
414+ // pairs with the Go executor-boundary metric (U15) as one series set.
415+ recordSimToolMetric ( toolCall . name , completion . status , durationMs )
416+ return completion
417+ } catch ( err ) {
418+ // executeToolAndReportInner threw (infra/unexpected error, not a normal
419+ // 'error' completion). Still stamp the span + record the dispatch so
420+ // copilot.tool.* isn't silently biased toward successful calls.
421+ const durationMs = Date . now ( ) - startedAt
422+ otelSpan . setAttribute ( TraceAttr . ToolOutcome , 'error' )
423+ otelSpan . setAttribute ( TraceAttr . ToolDurationMs , durationMs )
424+ recordSimToolMetric ( toolCall . name , 'error' , durationMs )
425+ throw err
411426 }
412- // Durable Grafana signal for "which Sim tool is slowest" (executor=sim);
413- // pairs with the Go executor-boundary metric (U15) as one series set.
414- recordSimToolMetric ( toolCall . name , completion . status , durationMs )
415- return completion
416427 }
417428 )
418429}
0 commit comments