|
14 | 14 | from typing import Any, Callable, Dict, List, Optional, Tuple, Union, cast, TYPE_CHECKING |
15 | 15 | from urllib.parse import urlparse |
16 | 16 |
|
17 | | -from azure.ai.agents.models import AgentRunStream, AsyncAgentRunStream, _models |
| 17 | +from azure.ai.agents.models import AgentRunStream, AsyncAgentRunStream, RunStepMessageCreationDetails, _models |
18 | 18 | from azure.ai.agents.models._enums import ( |
19 | 19 | AgentsResponseFormatMode, |
20 | 20 | MessageRole, |
@@ -596,8 +596,9 @@ def _add_tool_assistant_message_event(self, span, step: RunStep) -> None: |
596 | 596 | def set_end_run(self, span: "AbstractSpan", run: Optional[ThreadRun]) -> None: |
597 | 597 | if run and span and span.span_instance.is_recording: |
598 | 598 | span.add_attribute(GEN_AI_THREAD_RUN_STATUS, self._status_to_string(run.status)) |
| 599 | + span.add_attribute(GEN_AI_THREAD_RUN_ID, self._status_to_string(run.id)) |
599 | 600 | span.add_attribute(GEN_AI_RESPONSE_MODEL, run.model) |
600 | | - if run and run.usage: |
| 601 | + if run.usage: |
601 | 602 | span.add_attribute(GEN_AI_USAGE_INPUT_TOKENS, run.usage.prompt_tokens) |
602 | 603 | span.add_attribute(GEN_AI_USAGE_OUTPUT_TOKENS, run.usage.completion_tokens) |
603 | 604 |
|
@@ -1121,6 +1122,7 @@ async def trace_create_run_async(self, operation_name, function, *args, **kwargs |
1121 | 1122 | result = await function(*args, **kwargs) |
1122 | 1123 | if span.span_instance.is_recording: |
1123 | 1124 | span.add_attribute(GEN_AI_THREAD_RUN_STATUS, self._status_to_string(result.status)) |
| 1125 | + span.add_attribute(GEN_AI_THREAD_RUN_ID, self._status_to_string(result.id)) |
1124 | 1126 | span.add_attribute(GEN_AI_RESPONSE_MODEL, result.model) |
1125 | 1127 | if result.usage: |
1126 | 1128 | span.add_attribute(GEN_AI_USAGE_INPUT_TOKENS, result.usage.prompt_tokens) |
@@ -2040,6 +2042,13 @@ def on_run_step(self, step: "RunStep") -> None: # type: ignore[func-returns-val |
2040 | 2042 | ) |
2041 | 2043 | elif step.type == "message_creation" and step.status == RunStepStatus.COMPLETED: |
2042 | 2044 | self.instrumentor.add_thread_message_event(self.span, cast(ThreadMessage, self.last_message), step.usage) |
| 2045 | + if ( |
| 2046 | + self.span |
| 2047 | + and self.span.span_instance.is_recording |
| 2048 | + and isinstance(step.step_details, RunStepMessageCreationDetails) |
| 2049 | + ): |
| 2050 | + self.span.add_attribute(GEN_AI_MESSAGE_ID, step.step_details.message_creation.message_id) |
| 2051 | + |
2043 | 2052 | self.last_message = None |
2044 | 2053 |
|
2045 | 2054 | return retval # type: ignore |
@@ -2152,6 +2161,13 @@ async def on_run_step(self, step: "RunStep") -> None: # type: ignore[func-retur |
2152 | 2161 | ) |
2153 | 2162 | elif step.type == "message_creation" and step.status == RunStepStatus.COMPLETED: |
2154 | 2163 | self.instrumentor.add_thread_message_event(self.span, cast(ThreadMessage, self.last_message), step.usage) |
| 2164 | + if ( |
| 2165 | + self.span |
| 2166 | + and self.span.span_instance.is_recording |
| 2167 | + and isinstance(step.step_details, RunStepMessageCreationDetails) |
| 2168 | + ): |
| 2169 | + self.span.add_attribute(GEN_AI_MESSAGE_ID, step.step_details.message_creation.message_id) |
| 2170 | + |
2155 | 2171 | self.last_message = None |
2156 | 2172 |
|
2157 | 2173 | return retval # type: ignore |
|
0 commit comments