@@ -103,13 +103,15 @@ def _start_span(
103103        span_name : str ,
104104        parent_span : Optional [Span ] =  None ,
105105        attributes : Optional [Dict [str , AttributeValue ]] =  None ,
106+         span_kind : trace_api .SpanKind  =  trace_api .SpanKind .INTERNAL ,
106107    ) ->  Optional [Span ]:
107108        """Generic helper method to start a span with common attributes. 
108109
109110        Args: 
110111            span_name: Name of the span to create 
111112            parent_span: Optional parent span to link this span to 
112113            attributes: Dictionary of attributes to set on the span 
114+             span_kind: enum of OptenTelemetry SpanKind 
113115
114116        Returns: 
115117            The created span, or None if tracing is not enabled 
@@ -118,7 +120,7 @@ def _start_span(
118120            return  None 
119121
120122        context  =  trace_api .set_span_in_context (parent_span ) if  parent_span  else  None 
121-         span  =  self .tracer .start_span (name = span_name , context = context )
123+         span  =  self .tracer .start_span (name = span_name , context = context ,  kind = span_kind )
122124
123125        # Set start time as a common attribute 
124126        span .set_attribute ("gen_ai.event.start_time" , datetime .now (timezone .utc ).isoformat ())
@@ -230,7 +232,7 @@ def start_model_invoke_span(
230232        # Add additional kwargs as attributes 
231233        attributes .update ({k : v  for  k , v  in  kwargs .items () if  isinstance (v , (str , int , float , bool ))})
232234
233-         return  self ._start_span ("Model invoke" , parent_span , attributes )
235+         return  self ._start_span ("Model invoke" , parent_span , attributes ,  span_kind = trace_api . SpanKind . CLIENT )
234236
235237    def  end_model_invoke_span (
236238        self , span : Span , message : Message , usage : Usage , error : Optional [Exception ] =  None 
@@ -274,7 +276,7 @@ def start_tool_call_span(self, tool: ToolUse, parent_span: Optional[Span] = None
274276        attributes .update (kwargs )
275277
276278        span_name  =  f"Tool: { tool ['name' ]}  
277-         return  self ._start_span (span_name , parent_span , attributes )
279+         return  self ._start_span (span_name , parent_span , attributes ,  span_kind = trace_api . SpanKind . INTERNAL )
278280
279281    def  end_tool_call_span (
280282        self , span : Span , tool_result : Optional [ToolResult ], error : Optional [Exception ] =  None 
@@ -335,7 +337,7 @@ def start_event_loop_cycle_span(
335337        attributes .update ({k : v  for  k , v  in  kwargs .items () if  isinstance (v , (str , int , float , bool ))})
336338
337339        span_name  =  f"Cycle { event_loop_cycle_id }  
338-         return  self ._start_span (span_name , parent_span , attributes )
340+         return  self ._start_span (span_name , parent_span , attributes ,  span_kind = trace_api . SpanKind . INTERNAL )
339341
340342    def  end_event_loop_cycle_span (
341343        self ,
@@ -405,7 +407,7 @@ def start_agent_span(
405407        # Add additional kwargs as attributes 
406408        attributes .update ({k : v  for  k , v  in  kwargs .items () if  isinstance (v , (str , int , float , bool ))})
407409
408-         return  self ._start_span (agent_name , attributes = attributes )
410+         return  self ._start_span (agent_name , attributes = attributes ,  span_kind = trace_api . SpanKind . CLIENT )
409411
410412    def  end_agent_span (
411413        self ,
0 commit comments