Make tool-result telemetry limits configurable (#39779)

## What changed

- Add `otel.tool_result.max_bytes`, defaulting to 2048 bytes, to control the
  text included in `codex.tool_result` logs independently of model-visible
  output limits.
- Apply truncation centrally when emitting telemetry, preserve UTF-8
  boundaries, and report whether the logged output was truncated.
- Record typed tool names and namespaces, agent names, and process-local result
  sequence numbers while keeping tool arguments and output out of trace events.

## Testing

- Cover configuration propagation, UTF-8-safe truncation, raw tool-output
  logging, and log/trace event routing and fields.

GitOrigin-RevId: 89ca76e55f1a09b729e7770ce01f2e4d98f9a22d
This commit is contained in:
tongzhou wang authored and copyberry committed 2026-08-20 19:09:04 +00:00
1 parent 5663754f62
commit 854cbb2fd4
39 files changed
+583 -310

No files matched your search

@@ -25,7 +25,7 @@ const TOOL_NAME: &str = "curr_time";
struct CurrentTimeOutput(CurrentTimeReminder);
impl ToolOutput for CurrentTimeOutput {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
self.0.body()
}
@@ -36,7 +36,7 @@ impl GetContextRemainingOutput {
}
impl ToolOutput for GetContextRemainingOutput {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
self.fragment()
}
@@ -141,7 +141,7 @@ pub(crate) struct CloseAgentResult {
}
impl ToolOutput for CloseAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "close_agent")
}
@@ -168,7 +168,7 @@ pub(crate) struct ResumeAgentResult {
}
impl ToolOutput for ResumeAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "resume_agent")
}
@@ -145,7 +145,7 @@ pub(crate) struct SendInputResult {
}
impl ToolOutput for SendInputResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "send_input")
}
@@ -245,7 +245,7 @@ pub(crate) struct SpawnAgentResult {
}
impl ToolOutput for SpawnAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "spawn_agent")
}
@@ -284,7 +284,7 @@ pub(crate) struct WaitAgentResult {
}
impl ToolOutput for WaitAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "wait_agent")
}
@@ -113,7 +113,7 @@ pub(crate) struct InterruptAgentResult {
}
impl ToolOutput for InterruptAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "interrupt_agent")
}
@@ -65,7 +65,7 @@ pub(crate) struct ListAgentsResult {
}
impl ToolOutput for ListAgentsResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "list_agents")
}
@@ -330,7 +330,7 @@ pub(crate) enum SpawnAgentResult {
}
impl ToolOutput for SpawnAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "spawn_agent")
}
@@ -157,7 +157,7 @@ impl WaitAgentResult {
}
impl ToolOutput for WaitAgentResult {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
tool_output_json_text(self, "wait_agent")
}
+1 -1
View File
@@ -22,7 +22,7 @@ pub struct PlanToolOutput;
const PLAN_UPDATED_MESSAGE: &str = "Plan updated";
impl ToolOutput for PlanToolOutput {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
PLAN_UPDATED_MESSAGE.to_string()
}
@@ -223,7 +223,7 @@ pub struct ViewImageOutput {
}
impl ToolOutput for ViewImageOutput {
fn log_preview(&self) -> String {
fn log_output(&self) -> String {
format!("<image data URL omitted: {} bytes>", self.image_url.len())
}
@@ -323,7 +323,7 @@ mod tests {
unified_image_budget: false,
};
assert_eq!(output.log_preview(), "<image data URL omitted: 25 bytes>");
assert_eq!(output.log_output(), "<image data URL omitted: 25 bytes>");
}
#[test]