Skip to content

Commit 8aad922

Browse files
authored
adding image generation tracing support (#43883)
1 parent 1464d5d commit 8aad922

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_responses_instrumentor.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,35 @@ def _add_tool_call_events( # pylint: disable=too-many-branches
869869

870870
self._emit_tool_call_event(span, tool_call, conversation_id)
871871

872+
# Handle image_generation_call type
873+
elif item_type == "image_generation_call":
874+
tool_call = {
875+
"type": "image_generation",
876+
}
877+
878+
if hasattr(output_item, "id"):
879+
tool_call["id"] = output_item.id
880+
elif hasattr(output_item, "call_id"):
881+
tool_call["id"] = output_item.call_id
882+
883+
# Only include image generation details if content recording is enabled
884+
if _trace_responses_content:
885+
# Include metadata fields
886+
if hasattr(output_item, "prompt"):
887+
tool_call["prompt"] = output_item.prompt
888+
if hasattr(output_item, "quality"):
889+
tool_call["quality"] = output_item.quality
890+
if hasattr(output_item, "size"):
891+
tool_call["size"] = output_item.size
892+
if hasattr(output_item, "style"):
893+
tool_call["style"] = output_item.style
894+
895+
# Include the result (image data) only if binary data tracing is enabled
896+
if _trace_binary_data and hasattr(output_item, "result") and output_item.result:
897+
tool_call["result"] = output_item.result
898+
899+
self._emit_tool_call_event(span, tool_call, conversation_id)
900+
872901
# Handle mcp_call type (Model Context Protocol)
873902
elif item_type == "mcp_call":
874903
tool_call = {
@@ -2616,6 +2645,46 @@ def _add_conversation_item_event( # pylint: disable=too-many-branches
26162645

26172646
event_name = "gen_ai.assistant.message"
26182647

2648+
elif item_type == "image_generation_call":
2649+
# Image generation tool call
2650+
role = "assistant" # Override role for image generation calls
2651+
if _trace_responses_content:
2652+
tool_call = {
2653+
"type": "image_generation",
2654+
}
2655+
2656+
# Add call_id as "id"
2657+
if hasattr(item, "call_id"):
2658+
tool_call["id"] = item.call_id
2659+
elif hasattr(item, "id"):
2660+
tool_call["id"] = item.id
2661+
2662+
# Add image generation details
2663+
image_gen_details: Dict[str, Any] = {}
2664+
2665+
if hasattr(item, "prompt"):
2666+
image_gen_details["prompt"] = item.prompt
2667+
2668+
if hasattr(item, "quality"):
2669+
image_gen_details["quality"] = item.quality
2670+
2671+
if hasattr(item, "size"):
2672+
image_gen_details["size"] = item.size
2673+
2674+
if hasattr(item, "style"):
2675+
image_gen_details["style"] = item.style
2676+
2677+
# Include the result (image data) only if binary data tracing is enabled
2678+
if _trace_binary_data and hasattr(item, "result") and item.result:
2679+
image_gen_details["result"] = item.result
2680+
2681+
if image_gen_details:
2682+
tool_call["image_generation"] = image_gen_details
2683+
2684+
event_body["tool_calls"] = [tool_call]
2685+
2686+
event_name = "gen_ai.assistant.message"
2687+
26192688
elif item_type == "message":
26202689
# Regular message - use text format
26212690
if _trace_responses_content and hasattr(item, "content") and item.content:

0 commit comments

Comments
 (0)