Skip to content

Commit fdcdfdf

Browse files
committed
fix tool description
1 parent cf5382f commit fdcdfdf

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -975,13 +975,14 @@ def _get_output_attributes(template, result):
975975
return attributes
976976

977977

978-
def _set_input_attributes(span, template, args, kwargs):
979-
# type: (Span, Union[str, "SpanTemplate"], tuple[Any, ...], dict[str, Any]) -> None
978+
def _set_input_attributes(span, template, f, args, kwargs):
979+
# type: (Span, Union[str, "SpanTemplate"], Any, tuple[Any, ...], dict[str, Any]) -> None
980980
"""
981981
Set span input attributes based on the given span template.
982982
983983
:param span: The span to set attributes on.
984984
:param template: The template to use to set attributes on the span.
985+
:param f: The wrapped function.
985986
:param args: The arguments to the wrapped function.
986987
:param kwargs: The keyword arguments to the wrapped function.
987988
"""
@@ -1002,6 +1003,10 @@ def _set_input_attributes(span, template, args, kwargs):
10021003
SPANDATA.GEN_AI_TOOL_NAME: span.description,
10031004
}
10041005

1006+
docstring = f.__doc__
1007+
if docstring is not None:
1008+
attributes[SPANDATA.GEN_AI_TOOL_DESCRIPTION] = docstring
1009+
10051010
attributes.update(_get_input_attributes(template, kwargs))
10061011
span.set_data(attributes)
10071012

@@ -1064,11 +1069,7 @@ async def async_wrapper(*args, **kwargs):
10641069
template, name or qualname_from_function(f), kwargs
10651070
),
10661071
) as span:
1067-
_set_input_attributes(span, template, args, kwargs)
1068-
1069-
docstring = getattr(f, "__doc__", None)
1070-
if template == SpanTemplate.AI_TOOL and docstring is not None:
1071-
span.set_data(SPANDATA.GEN_AI_TOOL_DESCRIPTION, docstring)
1072+
_set_input_attributes(span, template, f, args, kwargs)
10721073

10731074
result = await f(*args, **kwargs)
10741075

@@ -1103,7 +1104,7 @@ def sync_wrapper(*args, **kwargs):
11031104
op=_get_span_op(template),
11041105
name=_get_span_name(template, name or qualname_from_function(f)),
11051106
) as span:
1106-
_set_input_attributes(span, template, args, kwargs)
1107+
_set_input_attributes(span, template, f, args, kwargs)
11071108

11081109
result = f(*args, **kwargs)
11091110

0 commit comments

Comments
 (0)