File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
tests/integrations/openai Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1031,3 +1031,35 @@ def test_ai_client_span_responses_api(sentry_init, capture_events):
10311031 "thread.id" : mock .ANY ,
10321032 "thread.name" : mock .ANY ,
10331033 }
1034+
1035+
1036+ @pytest .mark .skipif (SKIP_API_TESTS , reason = "Responses API not available" )
1037+ def test_error_in_responses_api (sentry_init , capture_events ):
1038+ sentry_init (
1039+ integrations = [OpenAIIntegration (include_prompts = True )],
1040+ traces_sample_rate = 1.0 ,
1041+ send_default_pii = True ,
1042+ )
1043+ events = capture_events ()
1044+
1045+ client = OpenAI (api_key = "z" )
1046+ client .responses ._post = mock .Mock (
1047+ side_effect = OpenAIError ("API rate limit reached" )
1048+ )
1049+
1050+ with start_transaction (name = "openai tx" ):
1051+ with pytest .raises (OpenAIError ):
1052+ client .responses .create (
1053+ model = "gpt-4o" ,
1054+ instructions = "You are a coding assistant that talks like a pirate." ,
1055+ input = "How do I check if a Python object is an instance of a class?" ,
1056+ )
1057+
1058+ (error_event , transaction_event ) = events
1059+ assert error_event ["level" ] == "error"
1060+ assert error_event ["exception" ]["values" ][0 ]["type" ] == "OpenAIError"
1061+ assert transaction_event ["type" ] == "transaction"
1062+ assert (
1063+ error_event ["contexts" ]["trace" ]["trace_id" ]
1064+ == transaction_event ["contexts" ]["trace" ]["trace_id" ]
1065+ )
You can’t perform that action at this time.
0 commit comments