@@ -66,7 +66,7 @@ async def async_func(a, b):
66
66
mock_span .set_attribute .assert_any_call ("function.result" , "20" )
67
67
68
68
69
- def test_disable_function_attributes (mock_tracer ):
69
+ def test_disable_function_attributes_sync (mock_tracer ):
70
70
"""
71
71
Test a synchronous function with `add_function_attributes` set to False.
72
72
"""
@@ -89,6 +89,29 @@ def sync_func(a, b):
89
89
)
90
90
91
91
92
+ async def test_disable_function_attributes_async (mock_tracer ):
93
+ """
94
+ Test an asynchronous function with `add_function_attributes` set to False.
95
+ """
96
+ mock_tracer , mock_span = mock_tracer
97
+
98
+ # Define a sync function with attributes disabled
99
+ @trace_function (trace_attributes = False )
100
+ async def async_func (a , b ):
101
+ return a - b
102
+
103
+ # Call the function
104
+ result = await async_func (10 , 6 )
105
+
106
+ # Assertions
107
+ assert result == 4
108
+ mock_tracer .start_as_current_span .assert_called_once_with ("async_func" )
109
+ mock_span .set_attribute .assert_any_call ("function.result" , "4" )
110
+ assert (
111
+ call ("function.args" , "(10, 6)" ) not in mock_span .set_attribute .call_args_list
112
+ )
113
+
114
+
92
115
def test_disable_result_in_span_sync (mock_tracer ):
93
116
"""
94
117
Test an asynchronous function with `add_result_to_span` set to False.
@@ -133,7 +156,7 @@ async def async_func(a, b):
133
156
assert call ("function.result" ) not in mock_span .set_attribute .call_args_list
134
157
135
158
136
- def test_exception_in_function (mock_tracer ):
159
+ def test_exception_in_function_sync (mock_tracer ):
137
160
"""
138
161
Test behavior when the function raises an exception.
139
162
"""
@@ -154,3 +177,26 @@ def failing_func(a, b):
154
177
mock_tracer .start_as_current_span .assert_called_once_with ("failing_func" )
155
178
mock_span .record_exception .assert_called_once ()
156
179
mock_span .set_status .assert_called_once ()
180
+
181
+
182
+ async def test_exception_in_function_async (mock_tracer ):
183
+ """
184
+ Test behavior when the function raises an exception.
185
+ """
186
+ mock_tracer , mock_span = mock_tracer
187
+
188
+ # Define a failing function
189
+ @trace_function ()
190
+ async def failing_func (a , b ):
191
+ if b == 0 :
192
+ raise ValueError ("Division by zero!" )
193
+ return a / b
194
+
195
+ # Use pytest to assert the exception is raised
196
+ with pytest .raises (ValueError , match = "Division by zero!" ):
197
+ await failing_func (10 , 0 )
198
+
199
+ # Assertions
200
+ mock_tracer .start_as_current_span .assert_called_once_with ("failing_func" )
201
+ mock_span .record_exception .assert_called_once ()
202
+ mock_span .set_status .assert_called_once ()
0 commit comments