|
20 | 20 | logger, |
21 | 21 | match_regex_list, |
22 | 22 | qualname_from_function, |
| 23 | + safe_repr, |
23 | 24 | to_string, |
24 | 25 | try_convert, |
25 | 26 | is_sentry_url, |
@@ -876,19 +877,15 @@ def _get_span_op(template): |
876 | 877 | return op |
877 | 878 |
|
878 | 879 |
|
879 | | -def _get_input_attributes(template, kwargs): |
880 | | - # type: (Union[str, "SpanTemplate"], dict[str, Any]) -> dict[str, Any] |
| 880 | +def _get_input_attributes(template, args, kwargs): |
| 881 | + # type: (Union[str, "SpanTemplate"], tuple[Any, ...], dict[str, Any]) -> dict[str, Any] |
881 | 882 | """ |
882 | 883 | Get input attributes for the given span template. |
883 | 884 | """ |
884 | 885 | attributes = {} # type: dict[str, Any] |
885 | 886 |
|
886 | | - for key, value in list(kwargs.items()): |
887 | | - if template in [ |
888 | | - SpanTemplate.AI_AGENT, |
889 | | - SpanTemplate.AI_TOOL, |
890 | | - SpanTemplate.AI_CHAT, |
891 | | - ]: |
| 887 | + if template in [SpanTemplate.AI_AGENT, SpanTemplate.AI_TOOL, SpanTemplate.AI_CHAT]: |
| 888 | + for key, value in list(kwargs.items()): |
892 | 889 | if key == "model" and isinstance(value, str): |
893 | 890 | attributes[SPANDATA.GEN_AI_REQUEST_MODEL] = value |
894 | 891 | elif key == "model_name" and isinstance(value, str): |
@@ -929,6 +926,11 @@ def _get_input_attributes(template, kwargs): |
929 | 926 | elif key == "top_k" and isinstance(value, int): |
930 | 927 | attributes.setdefault(SPANDATA.GEN_AI_REQUEST_TOP_K, []).append(value) |
931 | 928 |
|
| 929 | + if template == SpanTemplate.AI_TOOL: |
| 930 | + attributes[SPANDATA.GEN_AI_TOOL_INPUT] = safe_repr( |
| 931 | + {"args": args, "kwargs": kwargs} |
| 932 | + ) |
| 933 | + |
932 | 934 | return attributes |
933 | 935 |
|
934 | 936 |
|
@@ -984,6 +986,9 @@ def _get_output_attributes(template, result): |
984 | 986 | elif hasattr(result, "model_name") and isinstance(result.model_name, str): |
985 | 987 | attributes[SPANDATA.GEN_AI_RESPONSE_MODEL] = result.model_name |
986 | 988 |
|
| 989 | + if template == SpanTemplate.AI_TOOL: |
| 990 | + attributes[SPANDATA.GEN_AI_TOOL_OUTPUT] = safe_repr(result) |
| 991 | + |
987 | 992 | return attributes |
988 | 993 |
|
989 | 994 |
|
@@ -1019,7 +1024,7 @@ def _set_input_attributes(span, template, name, f, args, kwargs): |
1019 | 1024 | if docstring is not None: |
1020 | 1025 | attributes[SPANDATA.GEN_AI_TOOL_DESCRIPTION] = docstring |
1021 | 1026 |
|
1022 | | - attributes.update(_get_input_attributes(template, kwargs)) |
| 1027 | + attributes.update(_get_input_attributes(template, args, kwargs)) |
1023 | 1028 | span.set_data(attributes) |
1024 | 1029 |
|
1025 | 1030 |
|
@@ -1114,7 +1119,7 @@ def sync_wrapper(*args, **kwargs): |
1114 | 1119 | function_name = name or qualname_from_function(f) or "" |
1115 | 1120 | with start_span_func( |
1116 | 1121 | op=_get_span_op(template), |
1117 | | - name=_get_span_name(template, function_name), |
| 1122 | + name=_get_span_name(template, function_name, kwargs), |
1118 | 1123 | ) as span: |
1119 | 1124 | _set_input_attributes(span, template, function_name, f, args, kwargs) |
1120 | 1125 |
|
|
0 commit comments