Преглед изворни кода

feat(opencode): trace tool execution spans (#22531)

Kit Langton пре 4 месеци
родитељ
комит
685d79e953
1 измењених фајлова са 10 додато и 3 уклоњено
  1. 10 3
      packages/opencode/src/tool/tool.ts

+ 10 - 3
packages/opencode/src/tool/tool.ts

@@ -80,8 +80,14 @@ export namespace Tool {
       Effect.gen(function* () {
         const toolInfo = init instanceof Function ? { ...(yield* init()) } : { ...init }
         const execute = toolInfo.execute
-        toolInfo.execute = (args, ctx) =>
-          Effect.gen(function* () {
+        toolInfo.execute = (args, ctx) => {
+          const attrs = {
+            "tool.name": id,
+            "session.id": ctx.sessionID,
+            "message.id": ctx.messageID,
+            ...(ctx.callID ? { "tool.call_id": ctx.callID } : {}),
+          }
+          return Effect.gen(function* () {
             yield* Effect.try({
               try: () => toolInfo.parameters.parse(args),
               catch: (error) => {
@@ -109,7 +115,8 @@ export namespace Tool {
                 ...(truncated.truncated && { outputPath: truncated.outputPath }),
               },
             }
-          }).pipe(Effect.orDie)
+          }).pipe(Effect.orDie, Effect.withSpan("Tool.execute", { attributes: attrs }))
+        }
         return toolInfo
       })
   }