@@ -66,7 +66,7 @@ async def async_func(a, b):
6666 mock_span .set_attribute .assert_any_call ("function.result" , "20" )
6767
6868
69- def test_disable_function_attributes (mock_tracer ):
69+ def test_disable_function_attributes_sync (mock_tracer ):
7070 """
7171 Test a synchronous function with `add_function_attributes` set to False.
7272 """
@@ -89,6 +89,29 @@ def sync_func(a, b):
8989 )
9090
9191
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+
92115def test_disable_result_in_span_sync (mock_tracer ):
93116 """
94117 Test an asynchronous function with `add_result_to_span` set to False.
@@ -133,7 +156,7 @@ async def async_func(a, b):
133156 assert call ("function.result" ) not in mock_span .set_attribute .call_args_list
134157
135158
136- def test_exception_in_function (mock_tracer ):
159+ def test_exception_in_function_sync (mock_tracer ):
137160 """
138161 Test behavior when the function raises an exception.
139162 """
@@ -154,3 +177,26 @@ def failing_func(a, b):
154177 mock_tracer .start_as_current_span .assert_called_once_with ("failing_func" )
155178 mock_span .record_exception .assert_called_once ()
156179 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