Python: fix circular reference error in KernelArguments.dumps() during OTel diagnostics by MaxwellCalkin · Pull Request #13642 · microsoft/semantic-kernel

@MaxwellCalkin

…g OTel diagnostics

When SEMANTICKERNEL_EXPERIMENTAL_GENAI_ENABLE_OTEL_DIAGNOSTICS_SENSITIVE
is enabled, KernelFunction.invoke() calls arguments.dumps() to serialize
function arguments for OpenTelemetry spans. If the arguments contain
objects with circular references (e.g., KernelProcessStepContext, whose
step_message_channel holds back-references to the process graph), this
causes json.dumps to raise 'Circular reference detected'.

The fix adds defensive handling in KernelArguments.dumps():
- Track seen object IDs to detect circular references in the custom
  default serializer
- Catch ValueError from json.dumps and fall back to per-key
  serialization, replacing un-serializable values with their type name

Fixes microsoft#13393