Skip to content

refactor(trace): move tool spans onto 0.16.6 end() options - #173

Draft
rgao-coreweave wants to merge 1 commit into
turn-record-output-messagesfrom
tool-end-options
Draft

refactor(trace): move tool spans onto 0.16.6 end() options#173
rgao-coreweave wants to merge 1 commit into
turn-record-output-messagesfrom
tool-end-options

Conversation

@rgao-coreweave

@rgao-coreweave rgao-coreweave commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

0.16.6 deprecates the Tool.result setter and replaces it with ToolEndOptions:

end(opts?: { result?: JsonValue; errorType?: string } & SpanEndOptions)

It also widens startTool({ args }) from string to JsonObject | string. This drops the deprecated setter at all three sites and the manual error.type writes that errorType now covers.

// before
call.span.result = error;
call.span.setAttributes({ [ATTR.ERROR_TYPE]: errorType(error) });
call.span.end({ error: new Error(error) });

// after
call.span.end({ result: error, error: new Error(error), errorType: errorType(error) });

args: jsonStr(args.input) becomes args: args.input, letting the SDK serialize.

Wire format checked, not assumed

Ran both paths side by side through an in-memory exporter and compared gen_ai.tool.call.arguments and gen_ai.tool.call.result:

OK   object  {"command":"echo hi","n":3,"deep":{"a":[1,"x",null]}}  identical
OK   string  "plain text"                                           identical
OK   number  "0"                                                    identical
OK   false   "false"                                                identical
OK   array   "[1,2,\"three\"]"                                       identical
DIFF null    args "" -> "null"

Two edges came out of that, both handled:

  • args with a null input is the only divergence, and it is unreachable: hookHandler already rejects a non-object tool_input via isJsonObject (which returns false for null) before beginCall runs, so args.input is always a plain object.
  • A null tool result would serialize to the string "null" under the SDK, where our jsonStr returned "". Kept as "" with result: outcome.output ?? '' so this PR stays a pure API migration. Worth revisiting separately if "null" is actually preferable.

SubAgent spans keep setAttributes({ [ATTR.ERROR_TYPE]: … }), since errorType exists only on ToolEndOptions.

Verification

npm run check

tsc clean, 203/203 pass.

🤖 Generated with Claude Code

0.16.6 deprecates the Tool.result setter and adds ToolEndOptions
{result, errorType}, plus args accepting a JSON object instead of a
pre-serialized string. Drops the deprecated setter and the manual
error.type writes.

Wire format verified identical for object/string/number/false/array
inputs. Two edges handled: tool_input is already guaranteed non-null by
isJsonObject, and a null result keeps the historical empty string rather
than serializing to "null".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant