| 
27 | 27 |     code_attributes,  | 
28 | 28 | )  | 
29 | 29 | 
 
  | 
30 |  | -from .custom_semconv import (  | 
31 |  | -    CODE_MODULE,  | 
32 |  | -    FUNCTION_TOOL_CALL_END_EVENT_BODY_RESULT,  | 
33 |  | -    FUNCTION_TOOL_CALL_START_EVENT_ATTRS_KEYWORD_ARGS_COUNT,  | 
34 |  | -    FUNCTION_TOOL_CALL_START_EVENT_ATTRS_POSITIONAL_ARGS_COUNT,  | 
35 |  | -    FUNCTION_TOOL_CALL_START_EVENT_BODY_KEYWORD_ARGS,  | 
36 |  | -    FUNCTION_TOOL_CALL_START_EVENT_BODY_POSITIONAL_ARGS,  | 
37 |  | -    TOOL_CALL_KEYWORD_ARG_COUNT,  | 
38 |  | -    TOOL_CALL_POSITIONAL_ARG_COUNT,  | 
39 |  | -)  | 
40 | 30 | from .flags import is_content_recording_enabled  | 
41 | 31 | from .otel_wrapper import OTelWrapper  | 
42 | 32 | 
 
  | 
@@ -74,95 +64,48 @@ def _create_function_span_attributes(  | 
74 | 64 |     if extra_span_attributes:  | 
75 | 65 |         result.update(extra_span_attributes)  | 
76 | 66 |     result[code_attributes.CODE_FUNCTION_NAME] = wrapped_function.__name__  | 
77 |  | -    result[CODE_MODULE] = wrapped_function.__module__  | 
78 |  | -    result[TOOL_CALL_POSITIONAL_ARG_COUNT] = len(function_args)  | 
79 |  | -    result[TOOL_CALL_KEYWORD_ARG_COUNT] = len(function_kwargs)  | 
 | 67 | +    result["code.module"] = wrapped_function.__module__  | 
 | 68 | +    result["code.args.positional.count"] = len(function_args)  | 
 | 69 | +    result["code.args.keyword.count"] = len(function_kwargs)  | 
80 | 70 |     return result  | 
81 | 71 | 
 
  | 
82 | 72 | 
 
  | 
83 |  | -def _record_function_call_span_attributes(  | 
 | 73 | +def _record_function_call_arguments(  | 
84 | 74 |     otel_wrapper, wrapped_function, function_args, function_kwargs  | 
85 | 75 | ):  | 
86 | 76 |     """Records the details about a function invocation as span attributes."""  | 
87 |  | -    if not is_content_recording_enabled():  | 
88 |  | -        return  | 
 | 77 | +    include_values = is_content_recording_enabled()  | 
89 | 78 |     span = trace.get_current_span()  | 
90 | 79 |     signature = inspect.signature(wrapped_function)  | 
91 | 80 |     params = list(signature.parameters.values())  | 
92 | 81 |     for index, entry in enumerate(function_args):  | 
93 | 82 |         param_name = f"args[{index}]"  | 
94 | 83 |         if index < len(params):  | 
95 | 84 |             param_name = params[index].name  | 
96 |  | -        attribute_name = f"code.function.params.{param_name}"  | 
97 |  | -        span.set_attribute(attribute_name, _to_otel_value(entry))  | 
 | 85 | +        attribute_prefix = f"code.function.parameters.{param_name}"  | 
 | 86 | +        type_attribute = f"{attribute_prefix}.type"  | 
 | 87 | +        span.set_attribute(type_attribute, type(entry).__name__)  | 
 | 88 | +        if include_values:  | 
 | 89 | +            value_attribute = f"{attribute_prefix}.value"  | 
 | 90 | +            span.set_attribute(value_attribute, _to_otel_value(entry))  | 
98 | 91 |     for key, value in function_kwargs.items():  | 
99 |  | -        attribute_name = f"code.function.params.{key}"  | 
100 |  | -        span.set_attribute(attribute_name, _to_otel_value(value))  | 
 | 92 | +        attribute_prefix = f"code.function.parameters.{key}"  | 
 | 93 | +        type_attribute = f"{attribute_prefix}.type"  | 
 | 94 | +        span.set_attribute(type_attribute, type(value).__name__)  | 
 | 95 | +        if include_values:  | 
 | 96 | +            value_attribute = f"{attribute_prefix}.value"  | 
 | 97 | +            span.set_attribute(value_attribute, _to_otel_value(value))  | 
101 | 98 | 
 
  | 
102 | 99 | 
 
  | 
103 |  | -def _record_function_call_event(  | 
104 |  | -    otel_wrapper, wrapped_function, function_args, function_kwargs  | 
105 |  | -):  | 
106 |  | -    """Records the details about a function invocation as a log event."""  | 
107 |  | -    attributes = {  | 
108 |  | -        code_attributes.CODE_FUNCTION_NAME: wrapped_function.__name__,  | 
109 |  | -        CODE_MODULE: wrapped_function.__module__,  | 
110 |  | -        FUNCTION_TOOL_CALL_START_EVENT_ATTRS_POSITIONAL_ARGS_COUNT: len(  | 
111 |  | -            function_args  | 
112 |  | -        ),  | 
113 |  | -        FUNCTION_TOOL_CALL_START_EVENT_ATTRS_KEYWORD_ARGS_COUNT: len(  | 
114 |  | -            function_kwargs  | 
115 |  | -        ),  | 
116 |  | -    }  | 
117 |  | -    body = {}  | 
118 |  | -    if is_content_recording_enabled():  | 
119 |  | -        body[FUNCTION_TOOL_CALL_START_EVENT_BODY_POSITIONAL_ARGS] = (  | 
120 |  | -            _to_otel_value(function_args)  | 
121 |  | -        )  | 
122 |  | -        body[FUNCTION_TOOL_CALL_START_EVENT_BODY_KEYWORD_ARGS] = (  | 
123 |  | -            _to_otel_value(function_kwargs)  | 
124 |  | -        )  | 
125 |  | -    otel_wrapper.log_function_call_start(attributes, body)  | 
126 |  | - | 
127 |  | - | 
128 |  | -def _record_function_call_arguments(  | 
129 |  | -    otel_wrapper, wrapped_function, function_args, function_kwargs  | 
130 |  | -):  | 
131 |  | -    _record_function_call_span_attributes(  | 
132 |  | -        otel_wrapper, wrapped_function, function_args, function_kwargs  | 
133 |  | -    )  | 
134 |  | -    _record_function_call_event(  | 
135 |  | -        otel_wrapper, wrapped_function, function_args, function_kwargs  | 
136 |  | -    )  | 
137 |  | - | 
138 |  | - | 
139 |  | -def _record_function_call_result_event(otel_wrapper, wrapped_function, result):  | 
140 |  | -    """Records the details about a function result as a log event."""  | 
141 |  | -    attributes = {  | 
142 |  | -        code_attributes.CODE_FUNCTION_NAME: wrapped_function.__name__,  | 
143 |  | -        CODE_MODULE: wrapped_function.__module__,  | 
144 |  | -    }  | 
145 |  | -    body = {}  | 
146 |  | -    if is_content_recording_enabled():  | 
147 |  | -        body[FUNCTION_TOOL_CALL_END_EVENT_BODY_RESULT] = _to_otel_value(result)  | 
148 |  | -    otel_wrapper.log_function_call_end(attributes, body)  | 
149 |  | - | 
150 |  | - | 
151 |  | -def _record_function_call_result_span_attributes(  | 
 | 100 | +def _record_function_call_result(  | 
152 | 101 |     otel_wrapper, wrapped_function, result  | 
153 | 102 | ):  | 
154 | 103 |     """Records the details about a function result as span attributes."""  | 
155 |  | -    if not is_content_recording_enabled():  | 
156 |  | -        return  | 
 | 104 | +    include_values = is_content_recording_enabled()  | 
157 | 105 |     span = trace.get_current_span()  | 
158 |  | -    span.set_attribute("code.function.return_value", _to_otel_value(result))  | 
159 |  | - | 
160 |  | - | 
161 |  | -def _record_function_call_result(otel_wrapper, wrapped_function, result):  | 
162 |  | -    _record_function_call_result_event(otel_wrapper, wrapped_function, result)  | 
163 |  | -    _record_function_call_result_span_attributes(  | 
164 |  | -        otel_wrapper, wrapped_function, result  | 
165 |  | -    )  | 
 | 106 | +    span.set_attribute("code.function.return.type", type(result).__name__)  | 
 | 107 | +    if include_values:  | 
 | 108 | +        span.set_attribute("code.function.return.value", _to_otel_value(result))  | 
166 | 109 | 
 
  | 
167 | 110 | 
 
  | 
168 | 111 | def _wrap_sync_tool_function(  | 
 | 
0 commit comments