@@ -3818,7 +3818,7 @@ def test_ai_client_span_responses_api_no_pii(
38183818 spans = [item .payload for item in items ]
38193819
38203820 assert len (spans ) == 2
3821- assert spans [ 0 ][ "attributes" ] = = {
3821+ expected_attributes = {
38223822 "gen_ai.operation.name" : "responses" ,
38233823 "gen_ai.request.max_tokens" : 100 ,
38243824 "gen_ai.request.temperature" : 0.7 ,
@@ -3832,24 +3832,18 @@ def test_ai_client_span_responses_api_no_pii(
38323832 "gen_ai.usage.output_tokens" : 10 ,
38333833 "gen_ai.usage.output_tokens.reasoning" : 8 ,
38343834 "gen_ai.usage.total_tokens" : 30 ,
3835- "process.runtime.name" : mock .ANY ,
3836- "process.runtime.version" : mock .ANY ,
3837- "sentry.environment" : "production" ,
38383835 "sentry.op" : "gen_ai.responses" ,
38393836 "sentry.origin" : "auto.ai.openai" ,
3840- "sentry.release" : mock .ANY ,
3841- "sentry.sdk.name" : "sentry.python" ,
3842- "sentry.sdk.version" : mock .ANY ,
3843- "sentry.segment.id" : mock .ANY ,
38443837 "sentry.segment.name" : "openai tx" ,
3845- "server.address" : mock .ANY ,
3846- "thread.id" : mock .ANY ,
3847- "thread.name" : mock .ANY ,
38483838 }
38493839
3840+ for attr , value in expected_attributes .items ():
3841+ assert spans [0 ]["attributes" ][attr ] == value
3842+
38503843 assert "gen_ai.system_instructions" not in spans [0 ]["attributes" ]
38513844 assert "gen_ai.request.messages" not in spans [0 ]["attributes" ]
38523845 assert "gen_ai.response.text" not in spans [0 ]["attributes" ]
3846+
38533847 elif stream_gen_ai_spans :
38543848 items = capture_items ("span" )
38553849
@@ -3866,7 +3860,7 @@ def test_ai_client_span_responses_api_no_pii(
38663860 spans = [item .payload for item in items ]
38673861
38683862 assert len (spans ) == 1
3869- assert spans [ 0 ][ "attributes" ] = = {
3863+ expected_attributes = {
38703864 "gen_ai.operation.name" : "responses" ,
38713865 "gen_ai.request.max_tokens" : 100 ,
38723866 "gen_ai.request.temperature" : 0.7 ,
@@ -3880,21 +3874,14 @@ def test_ai_client_span_responses_api_no_pii(
38803874 "gen_ai.usage.output_tokens" : 10 ,
38813875 "gen_ai.usage.output_tokens.reasoning" : 8 ,
38823876 "gen_ai.usage.total_tokens" : 30 ,
3883- "process.runtime.name" : mock .ANY ,
3884- "process.runtime.version" : mock .ANY ,
3885- "sentry.environment" : "production" ,
38863877 "sentry.op" : "gen_ai.responses" ,
38873878 "sentry.origin" : "auto.ai.openai" ,
3888- "sentry.release" : mock .ANY ,
3889- "sentry.sdk.name" : "sentry.python" ,
3890- "sentry.sdk.version" : mock .ANY ,
3891- "sentry.segment.id" : mock .ANY ,
38923879 "sentry.segment.name" : "openai tx" ,
3893- "server.address" : mock .ANY ,
3894- "thread.id" : mock .ANY ,
3895- "thread.name" : mock .ANY ,
38963880 }
38973881
3882+ for attr , value in expected_attributes .items ():
3883+ assert spans [0 ]["attributes" ][attr ] == value
3884+
38983885 assert "gen_ai.system_instructions" not in spans [0 ]["attributes" ]
38993886 assert "gen_ai.request.messages" not in spans [0 ]["attributes" ]
39003887 assert "gen_ai.response.text" not in spans [0 ]["attributes" ]
@@ -3917,7 +3904,7 @@ def test_ai_client_span_responses_api_no_pii(
39173904 assert len (spans ) == 1
39183905 assert spans [0 ]["op" ] == "gen_ai.responses"
39193906 assert spans [0 ]["origin" ] == "auto.ai.openai"
3920- assert spans [ 0 ][ "data" ] = = {
3907+ expected_data = {
39213908 "gen_ai.operation.name" : "responses" ,
39223909 "gen_ai.request.max_tokens" : 100 ,
39233910 "gen_ai.request.temperature" : 0.7 ,
@@ -3931,10 +3918,11 @@ def test_ai_client_span_responses_api_no_pii(
39313918 "gen_ai.usage.output_tokens" : 10 ,
39323919 "gen_ai.usage.output_tokens.reasoning" : 8 ,
39333920 "gen_ai.usage.total_tokens" : 30 ,
3934- "thread.id" : mock .ANY ,
3935- "thread.name" : mock .ANY ,
39363921 }
39373922
3923+ for key , value in expected_data .items ():
3924+ assert spans [0 ]["data" ][key ] == value
3925+
39383926 assert "gen_ai.system_instructions" not in spans [0 ]["data" ]
39393927 assert "gen_ai.request.messages" not in spans [0 ]["data" ]
39403928 assert "gen_ai.response.text" not in spans [0 ]["data" ]
@@ -4143,27 +4131,17 @@ def test_ai_client_span_responses_api(
41434131 "gen_ai.request.messages" : safe_serialize (expected_request_messages ),
41444132 "gen_ai.request.model" : "gpt-4o" ,
41454133 "gen_ai.response.text" : "the model response" ,
4146- "process.runtime.name" : mock .ANY ,
4147- "process.runtime.version" : mock .ANY ,
4148- "sentry.environment" : "production" ,
4149- "sentry.op" : "gen_ai.responses" ,
4150- "sentry.origin" : "auto.ai.openai" ,
4151- "sentry.release" : mock .ANY ,
4152- "sentry.sdk.name" : "sentry.python" ,
4153- "sentry.sdk.version" : mock .ANY ,
4154- "sentry.segment.id" : mock .ANY ,
41554134 "sentry.segment.name" : "openai tx" ,
4156- "server.address" : mock .ANY ,
4157- "thread.id" : mock .ANY ,
4158- "thread.name" : mock .ANY ,
41594135 }
41604136
41614137 if expected_system_instructions is not None :
41624138 expected_data ["gen_ai.system_instructions" ] = safe_serialize (
41634139 expected_system_instructions
41644140 )
41654141
4166- assert spans [0 ]["attributes" ] == expected_data
4142+ for attr , value in expected_data .items ():
4143+ assert spans [0 ]["attributes" ][attr ] == value
4144+
41674145 elif stream_gen_ai_spans :
41684146 items = capture_items ("span" )
41694147
@@ -4197,27 +4175,19 @@ def test_ai_client_span_responses_api(
41974175 "gen_ai.request.messages" : safe_serialize (expected_request_messages ),
41984176 "gen_ai.request.model" : "gpt-4o" ,
41994177 "gen_ai.response.text" : "the model response" ,
4200- "process.runtime.name" : mock .ANY ,
4201- "process.runtime.version" : mock .ANY ,
4202- "sentry.environment" : "production" ,
42034178 "sentry.op" : "gen_ai.responses" ,
42044179 "sentry.origin" : "auto.ai.openai" ,
4205- "sentry.release" : mock .ANY ,
4206- "sentry.sdk.name" : "sentry.python" ,
4207- "sentry.sdk.version" : mock .ANY ,
4208- "sentry.segment.id" : mock .ANY ,
42094180 "sentry.segment.name" : "openai tx" ,
4210- "server.address" : mock .ANY ,
4211- "thread.id" : mock .ANY ,
4212- "thread.name" : mock .ANY ,
42134181 }
42144182
42154183 if expected_system_instructions is not None :
42164184 expected_data ["gen_ai.system_instructions" ] = safe_serialize (
42174185 expected_system_instructions
42184186 )
42194187
4220- assert spans [0 ]["attributes" ] == expected_data
4188+ for attr , value in expected_data .items ():
4189+ assert spans [0 ]["attributes" ][attr ] == value
4190+
42214191 else :
42224192 events = capture_events ()
42234193
@@ -4254,16 +4224,15 @@ def test_ai_client_span_responses_api(
42544224 "gen_ai.request.messages" : safe_serialize (expected_request_messages [- 1 :]),
42554225 "gen_ai.request.model" : "gpt-4o" ,
42564226 "gen_ai.response.text" : "the model response" ,
4257- "thread.id" : mock .ANY ,
4258- "thread.name" : mock .ANY ,
42594227 }
42604228
42614229 if expected_system_instructions is not None :
42624230 expected_data ["gen_ai.system_instructions" ] = safe_serialize (
42634231 expected_system_instructions
42644232 )
42654233
4266- assert spans [0 ]["data" ] == expected_data
4234+ for attr , value in expected_data .items ():
4235+ assert spans [0 ]["data" ][attr ] == value
42674236
42684237
42694238@pytest .mark .parametrize ("span_streaming" , [True , False ])
@@ -4634,27 +4603,19 @@ async def test_ai_client_span_responses_async_api(
46344603 "gen_ai.usage.output_tokens.reasoning" : 8 ,
46354604 "gen_ai.usage.total_tokens" : 30 ,
46364605 "gen_ai.response.text" : "the model response" ,
4637- "process.runtime.name" : mock .ANY ,
4638- "process.runtime.version" : mock .ANY ,
4639- "sentry.environment" : "production" ,
46404606 "sentry.op" : "gen_ai.responses" ,
46414607 "sentry.origin" : "auto.ai.openai" ,
4642- "sentry.release" : mock .ANY ,
4643- "sentry.sdk.name" : "sentry.python" ,
4644- "sentry.sdk.version" : mock .ANY ,
4645- "sentry.segment.id" : mock .ANY ,
46464608 "sentry.segment.name" : "openai tx" ,
4647- "server.address" : mock .ANY ,
4648- "thread.id" : mock .ANY ,
4649- "thread.name" : mock .ANY ,
46504609 }
46514610
46524611 if expected_system_instructions is not None :
46534612 expected_data ["gen_ai.system_instructions" ] = safe_serialize (
46544613 expected_system_instructions
46554614 )
46564615
4657- assert spans [0 ]["attributes" ] == expected_data
4616+ for attr , value in expected_data .items ():
4617+ assert spans [0 ]["attributes" ][attr ] == value
4618+
46584619 elif stream_gen_ai_spans :
46594620 items = capture_items ("span" )
46604621
@@ -4688,27 +4649,19 @@ async def test_ai_client_span_responses_async_api(
46884649 "gen_ai.usage.output_tokens.reasoning" : 8 ,
46894650 "gen_ai.usage.total_tokens" : 30 ,
46904651 "gen_ai.response.text" : "the model response" ,
4691- "process.runtime.name" : mock .ANY ,
4692- "process.runtime.version" : mock .ANY ,
4693- "sentry.environment" : "production" ,
46944652 "sentry.op" : "gen_ai.responses" ,
46954653 "sentry.origin" : "auto.ai.openai" ,
4696- "sentry.release" : mock .ANY ,
4697- "sentry.sdk.name" : "sentry.python" ,
4698- "sentry.sdk.version" : mock .ANY ,
4699- "sentry.segment.id" : mock .ANY ,
47004654 "sentry.segment.name" : "openai tx" ,
4701- "server.address" : mock .ANY ,
4702- "thread.id" : mock .ANY ,
4703- "thread.name" : mock .ANY ,
47044655 }
47054656
47064657 if expected_system_instructions is not None :
47074658 expected_data ["gen_ai.system_instructions" ] = safe_serialize (
47084659 expected_system_instructions
47094660 )
47104661
4711- assert spans [0 ]["attributes" ] == expected_data
4662+ for attr , value in expected_data .items ():
4663+ assert spans [0 ]["attributes" ][attr ] == value
4664+
47124665 else :
47134666 events = capture_events ()
47144667
@@ -4745,16 +4698,15 @@ async def test_ai_client_span_responses_async_api(
47454698 "gen_ai.usage.output_tokens.reasoning" : 8 ,
47464699 "gen_ai.usage.total_tokens" : 30 ,
47474700 "gen_ai.response.text" : "the model response" ,
4748- "thread.id" : mock .ANY ,
4749- "thread.name" : mock .ANY ,
47504701 }
47514702
47524703 if expected_system_instructions is not None :
47534704 expected_data ["gen_ai.system_instructions" ] = safe_serialize (
47544705 expected_system_instructions
47554706 )
47564707
4757- assert spans [0 ]["data" ] == expected_data
4708+ for attr , value in expected_data .items ():
4709+ assert spans [0 ]["data" ][attr ] == value
47584710
47594711
47604712@pytest .mark .parametrize ("span_streaming" , [True , False ])
@@ -4996,6 +4948,7 @@ async def test_ai_client_span_streaming_responses_async_api(
49964948
49974949 for attr , value in expected_data .items ():
49984950 assert spans [0 ]["attributes" ][attr ] == value
4951+
49994952 else :
50004953 events = capture_events ()
50014954
0 commit comments