@@ -178,6 +178,34 @@ async def test_turn_span_preserves_existing_data(self):
178178 assert ended_span .data ["custom" ] == "value"
179179 assert ended_span .data ["usage" ] == {"prompt_tokens" : 3 , "completion_tokens" : 4 }
180180
181+ async def test_turn_span_warns_and_replaces_non_dict_data (self , caplog ):
182+ mock_service , module = _make_module ()
183+ started = _make_span (data = [{"item" : 1 }])
184+ mock_service .start_span .return_value = started
185+ mock_service .end_span .return_value = started
186+
187+ with patch .object (_tracing_mod , "in_temporal_workflow" , return_value = False ):
188+ async with module .turn_span (trace_id = "trace-123" , name = "turn" ) as turn :
189+ with caplog .at_level ("WARNING" ):
190+ turn .record_usage (usage = {"input_tokens" : 1 , "output_tokens" : 2 })
191+
192+ assert any ("existing data will be replaced" in message for message in caplog .messages )
193+ ended_span = mock_service .end_span .call_args .kwargs ["span" ]
194+ assert ended_span .data == {"usage" : {"input_tokens" : 1 , "output_tokens" : 2 }}
195+
196+ async def test_turn_span_dict_data_does_not_warn (self , caplog ):
197+ mock_service , module = _make_module ()
198+ started = _make_span (data = {"custom" : "value" })
199+ mock_service .start_span .return_value = started
200+ mock_service .end_span .return_value = started
201+
202+ with patch .object (_tracing_mod , "in_temporal_workflow" , return_value = False ):
203+ async with module .turn_span (trace_id = "trace-123" , name = "turn" ) as turn :
204+ with caplog .at_level ("WARNING" ):
205+ turn .record_usage (usage = {"input_tokens" : 1 })
206+
207+ assert not any ("existing data will be replaced" in message for message in caplog .messages )
208+
181209 async def test_turn_span_cost_only (self ):
182210 mock_service , module = _make_module ()
183211 started = _make_span ()
0 commit comments