extractToolInputForTelemetry function

String? extractToolInputForTelemetry(
  1. Object? input, {
  2. required bool isToolDetailsLoggingEnabled,
})

Serialize a tool's input arguments for the OTel tool_result event. Truncates long strings and deep nesting to keep the output bounded. Returns null when tool details logging is not enabled.

Implementation

String? extractToolInputForTelemetry(
  Object? input, {
  required bool isToolDetailsLoggingEnabled,
}) {
  if (!isToolDetailsLoggingEnabled) return null;
  final truncated = _truncateToolInputValue(input);
  var json = jsonEncode(truncated);
  if (json.length > _toolInputMaxJsonChars) {
    json = '${json.substring(0, _toolInputMaxJsonChars)}...[truncated]';
  }
  return json;
}