(
input: {
toolName: string
toolCallId: string
runId?: string
chatId?: string
argsBytes?: number
argsPreview?: string
},
fn: (span: Span) => Promise<T>
)
| 277 | // External OTel `tool.execute` span for Sim-side tool work (the Go |
| 278 | // side's `tool.execute` is just the enqueue, stays ~0ms). |
| 279 | export async function withCopilotToolSpan<T>( |
| 280 | input: { |
| 281 | toolName: string |
| 282 | toolCallId: string |
| 283 | runId?: string |
| 284 | chatId?: string |
| 285 | argsBytes?: number |
| 286 | argsPreview?: string |
| 287 | }, |
| 288 | fn: (span: Span) => Promise<T> |
| 289 | ): Promise<T> { |
| 290 | const tracer = getTracer() |
| 291 | return tracer.startActiveSpan( |
| 292 | `tool.execute ${input.toolName}`, |
| 293 | { |
| 294 | attributes: { |
| 295 | [TraceAttr.ToolName]: input.toolName, |
| 296 | [TraceAttr.ToolCallId]: input.toolCallId, |
| 297 | [TraceAttr.ToolExecutor]: 'sim', |
| 298 | ...(input.runId ? { [TraceAttr.RunId]: input.runId } : {}), |
| 299 | ...(input.chatId ? { [TraceAttr.ChatId]: input.chatId } : {}), |
| 300 | ...(typeof input.argsBytes === 'number' |
| 301 | ? { [TraceAttr.ToolArgsBytes]: input.argsBytes } |
| 302 | : {}), |
| 303 | // argsPreview can leak pasted credentials in tool args; gate |
| 304 | // behind the GenAI content-capture env var. |
| 305 | ...(input.argsPreview && isGenAIMessageCaptureEnabled() |
| 306 | ? { [TraceAttr.ToolArgsPreview]: input.argsPreview } |
| 307 | : {}), |
| 308 | }, |
| 309 | }, |
| 310 | async (span) => { |
| 311 | try { |
| 312 | const result = await fn(span) |
| 313 | span.setStatus({ code: SpanStatusCode.OK }) |
| 314 | return result |
| 315 | } catch (error) { |
| 316 | markSpanForError(span, error) |
| 317 | throw error |
| 318 | } finally { |
| 319 | span.end() |
| 320 | } |
| 321 | } |
| 322 | ) |
| 323 | } |
| 324 | |
| 325 | function isValidSpanContext(spanContext: SpanContext): boolean { |
| 326 | return ( |
no test coverage detected