@@ -200,6 +200,53 @@ def test_request_attributes_set_on_span(self):
200200 input_messages ,
201201 )
202202
203+ def test_invoke_agent_scope_span_kind (self ):
204+ """Test that InvokeAgentScope creates spans with the correct SpanKind."""
205+ # Create scope
206+ scope = InvokeAgentScope .start (
207+ invoke_agent_details = self .invoke_details ,
208+ tenant_details = self .tenant_details ,
209+ request = self .test_request ,
210+ )
211+
212+ if scope is not None :
213+ scope .dispose ()
214+
215+ # Check that span was created with correct SpanKind
216+ finished_spans = self .span_exporter .get_finished_spans ()
217+ self .assertTrue (finished_spans , "Expected at least one span to be created" )
218+
219+ # Get the span and verify its kind
220+ span = finished_spans [- 1 ]
221+ self .assertEqual (
222+ span .kind ,
223+ SpanKind .CLIENT ,
224+ "InvokeAgentScope defaults to CLIENT spans (can be overridden with span_kind parameter)" ,
225+ )
226+
227+ # Test SERVER span kind override
228+ scope_server = InvokeAgentScope .start (
229+ invoke_agent_details = self .invoke_details ,
230+ tenant_details = self .tenant_details ,
231+ request = self .test_request ,
232+ span_kind = SpanKind .SERVER ,
233+ )
234+
235+ if scope_server is not None :
236+ scope_server .dispose ()
237+
238+ # Check that SERVER span was created
239+ finished_spans = self .span_exporter .get_finished_spans ()
240+ self .assertTrue (len (finished_spans ) >= 2 , "Expected at least two spans to be created" )
241+
242+ # Get the most recent span and verify it's SERVER
243+ server_span = finished_spans [- 1 ]
244+ self .assertEqual (
245+ server_span .kind ,
246+ SpanKind .SERVER ,
247+ "InvokeAgentScope should create SERVER spans when span_kind parameter is set" ,
248+ )
249+
203250
204251if __name__ == "__main__" :
205252 # Run pytest only on the current file
0 commit comments