@@ -151,8 +151,12 @@ def test_agent_custom_model():
151151
152152
153153@pytest .mark .asyncio
154+ @pytest .mark .parametrize (
155+ "send_default_pii" ,
156+ (True , False ),
157+ )
154158async def test_agent_invocation_span (
155- sentry_init , capture_events , test_agent , mock_model_response
159+ sentry_init , capture_events , test_agent , mock_model_response , send_default_pii
156160):
157161 """
158162 Test that the integration creates spans for agent invocations.
@@ -167,7 +171,7 @@ async def test_agent_invocation_span(
167171 sentry_init (
168172 integrations = [OpenAIAgentsIntegration ()],
169173 traces_sample_rate = 1.0 ,
170- send_default_pii = True ,
174+ send_default_pii = send_default_pii ,
171175 )
172176
173177 events = capture_events ()
@@ -187,21 +191,27 @@ async def test_agent_invocation_span(
187191 assert transaction ["contexts" ]["trace" ]["origin" ] == "auto.ai.openai_agents"
188192
189193 assert invoke_agent_span ["description" ] == "invoke_agent test_agent"
190- assert invoke_agent_span ["data" ]["gen_ai.request.messages" ] == safe_serialize (
191- [
192- {
193- "content" : [
194- {"text" : "You are a helpful test assistant." , "type" : "text" }
195- ],
196- "role" : "system" ,
197- },
198- {"content" : [{"text" : "Test input" , "type" : "text" }], "role" : "user" },
199- ]
200- )
201- assert (
202- invoke_agent_span ["data" ]["gen_ai.response.text" ]
203- == "Hello, how can I help you?"
204- )
194+
195+ if send_default_pii :
196+ assert invoke_agent_span ["data" ][
197+ SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS
198+ ] == safe_serialize (
199+ [{"type" : "text" , "content" : "You are a helpful test assistant." }]
200+ )
201+ assert invoke_agent_span ["data" ]["gen_ai.request.messages" ] == safe_serialize (
202+ [
203+ {"content" : [{"text" : "Test input" , "type" : "text" }], "role" : "user" },
204+ ]
205+ )
206+ assert (
207+ invoke_agent_span ["data" ]["gen_ai.response.text" ]
208+ == "Hello, how can I help you?"
209+ )
210+ else :
211+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS not in invoke_agent_span ["data" ]
212+ assert "gen_ai.request.messages" not in invoke_agent_span ["data" ]
213+ assert "gen_ai.response.text" not in invoke_agent_span ["data" ]
214+
205215 assert invoke_agent_span ["data" ]["gen_ai.operation.name" ] == "invoke_agent"
206216 assert invoke_agent_span ["data" ]["gen_ai.system" ] == "openai"
207217 assert invoke_agent_span ["data" ]["gen_ai.agent.name" ] == "test_agent"
0 commit comments