@@ -279,6 +279,45 @@ async def test_chat_client_streaming_observability(
279279 assert span .attributes [OtelAttr .OUTPUT_MESSAGES ] is not None
280280
281281
282+ async def test_chat_client_without_model_id_observability (mock_chat_client , span_exporter : InMemorySpanExporter ):
283+ """Test telemetry shouldn't fail when the model_id is not provided for unknown reason."""
284+ client = use_observability (mock_chat_client )()
285+ messages = [ChatMessage (role = Role .USER , text = "Test" )]
286+ span_exporter .clear ()
287+ response = await client .get_response (messages = messages )
288+
289+ assert response is not None
290+ spans = span_exporter .get_finished_spans ()
291+ assert len (spans ) == 1
292+ span = spans [0 ]
293+
294+ assert span .name == "chat unknown"
295+ assert span .attributes [OtelAttr .OPERATION .value ] == OtelAttr .CHAT_COMPLETION_OPERATION
296+ assert span .attributes [SpanAttributes .LLM_REQUEST_MODEL ] == "unknown"
297+
298+
299+ async def test_chat_client_streaming_without_model_id_observability (
300+ mock_chat_client , span_exporter : InMemorySpanExporter
301+ ):
302+ """Test streaming telemetry shouldn't fail when the model_id is not provided for unknown reason."""
303+ client = use_observability (mock_chat_client )()
304+ messages = [ChatMessage (role = Role .USER , text = "Test" )]
305+ span_exporter .clear ()
306+ # Collect all yielded updates
307+ updates = []
308+ async for update in client .get_streaming_response (messages = messages ):
309+ updates .append (update )
310+
311+ # Verify we got the expected updates, this shouldn't be dependent on otel
312+ assert len (updates ) == 2
313+ spans = span_exporter .get_finished_spans ()
314+ assert len (spans ) == 1
315+ span = spans [0 ]
316+ assert span .name == "chat unknown"
317+ assert span .attributes [OtelAttr .OPERATION .value ] == OtelAttr .CHAT_COMPLETION_OPERATION
318+ assert span .attributes [SpanAttributes .LLM_REQUEST_MODEL ] == "unknown"
319+
320+
282321def test_prepend_user_agent_with_none_value ():
283322 """Test prepend user agent with None value in headers."""
284323 headers = {"User-Agent" : None }
@@ -368,6 +407,7 @@ def __init__(self):
368407 self .name = "test_agent"
369408 self .display_name = "Test Agent"
370409 self .description = "Test agent description"
410+ self .chat_options = ChatOptions (model_id = "TestModel" )
371411
372412 async def run (self , messages = None , * , thread = None , ** kwargs ):
373413 return AgentRunResponse (
@@ -405,7 +445,7 @@ async def test_agent_instrumentation_enabled(
405445 assert span .attributes [OtelAttr .AGENT_ID ] == "test_agent_id"
406446 assert span .attributes [OtelAttr .AGENT_NAME ] == "Test Agent"
407447 assert span .attributes [OtelAttr .AGENT_DESCRIPTION ] == "Test agent description"
408- assert span .attributes [SpanAttributes .LLM_REQUEST_MODEL ] == "unknown "
448+ assert span .attributes [SpanAttributes .LLM_REQUEST_MODEL ] == "TestModel "
409449 assert span .attributes [OtelAttr .INPUT_TOKENS ] == 15
410450 assert span .attributes [OtelAttr .OUTPUT_TOKENS ] == 25
411451 if enable_sensitive_data :
@@ -433,7 +473,7 @@ async def test_agent_streaming_response_with_diagnostics_enabled_via_decorator(
433473 assert span .attributes [OtelAttr .AGENT_ID ] == "test_agent_id"
434474 assert span .attributes [OtelAttr .AGENT_NAME ] == "Test Agent"
435475 assert span .attributes [OtelAttr .AGENT_DESCRIPTION ] == "Test agent description"
436- assert span .attributes [SpanAttributes .LLM_REQUEST_MODEL ] == "unknown "
476+ assert span .attributes [SpanAttributes .LLM_REQUEST_MODEL ] == "TestModel "
437477 if enable_sensitive_data :
438478 assert span .attributes .get (OtelAttr .OUTPUT_MESSAGES ) is not None # Streaming, so no usage yet
439479
0 commit comments