@@ -830,8 +830,8 @@ def _sample_rand_range(parent_sampled, sample_rate):
830830 return sample_rate , 1.0
831831
832832
833- def _get_span_name (template , name = None , kwargs = None ):
834- # type: (Union[str, "SpanTemplate"], Optional[ str] , Optional[dict[str, Any]]) -> str
833+ def _get_span_name (template , name , kwargs = None ):
834+ # type: (Union[str, "SpanTemplate"], str, Optional[dict[str, Any]]) -> str
835835 """
836836 Get the name of the span based on the template and the name.
837837 """
@@ -854,7 +854,7 @@ def _get_span_name(template, name=None, kwargs=None):
854854 elif template == SpanTemplate .AI_TOOL :
855855 span_name = f"execute_tool { name } "
856856
857- return span_name or ""
857+ return span_name
858858
859859
860860def _get_span_op (template ):
@@ -987,8 +987,8 @@ def _get_output_attributes(template, result):
987987 return attributes
988988
989989
990- def _set_input_attributes (span , template , f , args , kwargs ):
991- # type: (Span, Union[str, "SpanTemplate"], Any, tuple[Any, ...], dict[str, Any]) -> None
990+ def _set_input_attributes (span , template , name , f , args , kwargs ):
991+ # type: (Span, Union[str, "SpanTemplate"], str, Any, tuple[Any, ...], dict[str, Any]) -> None
992992 """
993993 Set span input attributes based on the given span template.
994994
@@ -1003,7 +1003,7 @@ def _set_input_attributes(span, template, f, args, kwargs):
10031003 if template == SpanTemplate .AI_AGENT :
10041004 attributes = {
10051005 SPANDATA .GEN_AI_OPERATION_NAME : "invoke_agent" ,
1006- SPANDATA .GEN_AI_AGENT_NAME : span . description ,
1006+ SPANDATA .GEN_AI_AGENT_NAME : name ,
10071007 }
10081008 elif template == SpanTemplate .AI_CHAT :
10091009 attributes = {
@@ -1012,7 +1012,7 @@ def _set_input_attributes(span, template, f, args, kwargs):
10121012 elif template == SpanTemplate .AI_TOOL :
10131013 attributes = {
10141014 SPANDATA .GEN_AI_OPERATION_NAME : "execute_tool" ,
1015- SPANDATA .GEN_AI_TOOL_NAME : span . description ,
1015+ SPANDATA .GEN_AI_TOOL_NAME : name ,
10161016 }
10171017
10181018 docstring = f .__doc__
@@ -1075,13 +1075,12 @@ async def async_wrapper(*args, **kwargs):
10751075 current_span .start_child if current_span else sentry_sdk .start_span
10761076 )
10771077
1078+ function_name = name or qualname_from_function (f ) or ""
10781079 with start_span_func (
10791080 op = _get_span_op (template ),
1080- name = _get_span_name (
1081- template , name or qualname_from_function (f ), kwargs
1082- ),
1081+ name = _get_span_name (template , function_name , kwargs ),
10831082 ) as span :
1084- _set_input_attributes (span , template , f , args , kwargs )
1083+ _set_input_attributes (span , template , function_name , f , args , kwargs )
10851084
10861085 result = await f (* args , ** kwargs )
10871086
@@ -1112,11 +1111,12 @@ def sync_wrapper(*args, **kwargs):
11121111 current_span .start_child if current_span else sentry_sdk .start_span
11131112 )
11141113
1114+ function_name = name or qualname_from_function (f ) or ""
11151115 with start_span_func (
11161116 op = _get_span_op (template ),
1117- name = _get_span_name (template , name or qualname_from_function ( f ) ),
1117+ name = _get_span_name (template , function_name ),
11181118 ) as span :
1119- _set_input_attributes (span , template , f , args , kwargs )
1119+ _set_input_attributes (span , template , function_name , f , args , kwargs )
11201120
11211121 result = f (* args , ** kwargs )
11221122
0 commit comments