@@ -2358,41 +2358,6 @@ async def test_model_name_extraction_fallback_to_str(sentry_init, capture_items)
23582358 assert isinstance (result , str )
23592359
23602360
2361- @pytest .mark .asyncio
2362- async def test_model_settings_object_style (sentry_init , capture_items ):
2363- """
2364- Test that object-style model settings (non-dict) are handled correctly.
2365- """
2366- from unittest .mock import MagicMock
2367-
2368- import sentry_sdk
2369- from sentry_sdk .integrations .pydantic_ai .utils import _set_model_data
2370-
2371- sentry_init (
2372- integrations = [PydanticAIIntegration ()],
2373- traces_sample_rate = 1.0 ,
2374- )
2375-
2376- with sentry_sdk .start_transaction (op = "test" , name = "test" ) as transaction :
2377- span = sentry_sdk .start_span (op = "test_span" )
2378-
2379- # Create mock settings object (not a dict)
2380- mock_settings = MagicMock ()
2381- mock_settings .temperature = 0.8
2382- mock_settings .max_tokens = 200
2383- mock_settings .top_p = 0.95
2384- mock_settings .frequency_penalty = 0.5
2385- mock_settings .presence_penalty = 0.3
2386-
2387- # Set model data with object-style settings
2388- _set_model_data (span , None , mock_settings )
2389-
2390- span .finish ()
2391-
2392- # Should not crash and should set the settings
2393- assert transaction is not None
2394-
2395-
23962361@pytest .mark .parametrize ("span_streaming" , [True , False ])
23972362@pytest .mark .parametrize ("stream_gen_ai_spans" , [True , False ])
23982363@pytest .mark .asyncio
@@ -3397,105 +3362,6 @@ async def test_get_model_name_with_none(sentry_init, capture_items):
33973362 assert result is None
33983363
33993364
3400- @pytest .mark .asyncio
3401- async def test_set_model_data_with_system (sentry_init , capture_items ):
3402- """
3403- Test that _set_model_data captures system from model.
3404- """
3405- from unittest .mock import MagicMock
3406-
3407- import sentry_sdk
3408- from sentry_sdk .integrations .pydantic_ai .utils import _set_model_data
3409-
3410- sentry_init (
3411- integrations = [PydanticAIIntegration ()],
3412- traces_sample_rate = 1.0 ,
3413- )
3414-
3415- with sentry_sdk .start_transaction (op = "test" , name = "test" ) as transaction :
3416- span = sentry_sdk .start_span (op = "test_span" )
3417-
3418- # Create model with system
3419- mock_model = MagicMock ()
3420- mock_model .system = "openai"
3421- mock_model .model_name = "gpt-4"
3422-
3423- # Set model data
3424- _set_model_data (span , mock_model , None )
3425-
3426- span .finish ()
3427-
3428- # Should not crash
3429- assert transaction is not None
3430-
3431-
3432- @pytest .mark .asyncio
3433- async def test_set_model_data_from_agent_scope (sentry_init , capture_items ):
3434- """
3435- Test that _set_model_data retrieves model from agent in scope when not passed.
3436- """
3437- from unittest .mock import MagicMock
3438-
3439- import sentry_sdk
3440- from sentry_sdk .integrations .pydantic_ai .utils import _set_model_data
3441-
3442- sentry_init (
3443- integrations = [PydanticAIIntegration ()],
3444- traces_sample_rate = 1.0 ,
3445- )
3446-
3447- with sentry_sdk .start_transaction (op = "test" , name = "test" ) as transaction :
3448- # Set agent in scope
3449- scope = sentry_sdk .get_current_scope ()
3450- mock_agent = MagicMock ()
3451- mock_agent .model = MagicMock ()
3452- mock_agent .model .model_name = "test-model"
3453- mock_agent .model_settings = {"temperature" : 0.5 }
3454- scope ._contexts ["pydantic_ai_agent" ] = {"_agent" : mock_agent }
3455-
3456- span = sentry_sdk .start_span (op = "test_span" )
3457-
3458- # Pass None for model, should get from scope
3459- _set_model_data (span , None , None )
3460-
3461- span .finish ()
3462-
3463- # Should not crash
3464- assert transaction is not None
3465-
3466-
3467- @pytest .mark .asyncio
3468- async def test_set_model_data_with_none_settings_values (sentry_init , capture_items ):
3469- """
3470- Test that _set_model_data skips None values in settings.
3471- """
3472- import sentry_sdk
3473- from sentry_sdk .integrations .pydantic_ai .utils import _set_model_data
3474-
3475- sentry_init (
3476- integrations = [PydanticAIIntegration ()],
3477- traces_sample_rate = 1.0 ,
3478- )
3479-
3480- with sentry_sdk .start_transaction (op = "test" , name = "test" ) as transaction :
3481- span = sentry_sdk .start_span (op = "test_span" )
3482-
3483- # Create settings with None values
3484- settings = {
3485- "temperature" : 0.7 ,
3486- "max_tokens" : None , # Should be skipped
3487- "top_p" : None , # Should be skipped
3488- }
3489-
3490- # Set model data
3491- _set_model_data (span , None , settings )
3492-
3493- span .finish ()
3494-
3495- # Should not crash
3496- assert transaction is not None
3497-
3498-
34993365@pytest .mark .asyncio
35003366async def test_should_send_prompts_without_pii (sentry_init , capture_items ):
35013367 """
0 commit comments