Skip to content

Commit 685d79e

Browse files
authored
feat(opencode): trace tool execution spans (#22531)
1 parent be9432a commit 685d79e

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

packages/opencode/src/tool/tool.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ export namespace Tool {
8080
Effect.gen(function* () {
8181
const toolInfo = init instanceof Function ? { ...(yield* init()) } : { ...init }
8282
const execute = toolInfo.execute
83-
toolInfo.execute = (args, ctx) =>
84-
Effect.gen(function* () {
83+
toolInfo.execute = (args, ctx) => {
84+
const attrs = {
85+
"tool.name": id,
86+
"session.id": ctx.sessionID,
87+
"message.id": ctx.messageID,
88+
...(ctx.callID ? { "tool.call_id": ctx.callID } : {}),
89+
}
90+
return Effect.gen(function* () {
8591
yield* Effect.try({
8692
try: () => toolInfo.parameters.parse(args),
8793
catch: (error) => {
@@ -109,7 +115,8 @@ export namespace Tool {
109115
...(truncated.truncated && { outputPath: truncated.outputPath }),
110116
},
111117
}
112-
}).pipe(Effect.orDie)
118+
}).pipe(Effect.orDie, Effect.withSpan("Tool.execute", { attributes: attrs }))
119+
}
113120
return toolInfo
114121
})
115122
}

0 commit comments

Comments
 (0)