-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): Fix tracing TypeError for static and class methods (#2559)
Fixes TypeError that occurred when static or class methods, which were passed in the `functions_to_trace` argument when initializing the SDK, were called on an instance. Fixes GH-2525 --------- Co-authored-by: Ivana Kellyerova <ivana.kellyerova@sentry.io>
- Loading branch information
1 parent
6470063
commit 8bd2f46
Showing
7 changed files
with
168 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from unittest import mock | ||
import pytest | ||
import sys | ||
|
||
from tests.conftest import patch_start_tracing_child | ||
|
||
from sentry_sdk.tracing_utils_py3 import ( | ||
start_child_span_decorator as start_child_span_decorator_py3, | ||
) | ||
from sentry_sdk.utils import logger | ||
|
||
if sys.version_info < (3, 6): | ||
pytest.skip("Async decorator only works on Python 3.6+", allow_module_level=True) | ||
|
||
|
||
async def my_async_example_function(): | ||
return "return_of_async_function" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_trace_decorator_async_py3(): | ||
with patch_start_tracing_child() as fake_start_child: | ||
result = await my_async_example_function() | ||
fake_start_child.assert_not_called() | ||
assert result == "return_of_async_function" | ||
|
||
result2 = await start_child_span_decorator_py3(my_async_example_function)() | ||
fake_start_child.assert_called_once_with( | ||
op="function", | ||
description="test_decorator_async_py3.my_async_example_function", | ||
) | ||
assert result2 == "return_of_async_function" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_trace_decorator_async_py3_no_trx(): | ||
with patch_start_tracing_child(fake_transaction_is_none=True): | ||
with mock.patch.object(logger, "warning", mock.Mock()) as fake_warning: | ||
result = await my_async_example_function() | ||
fake_warning.assert_not_called() | ||
assert result == "return_of_async_function" | ||
|
||
result2 = await start_child_span_decorator_py3(my_async_example_function)() | ||
fake_warning.assert_called_once_with( | ||
"Can not create a child span for %s. " | ||
"Please start a Sentry transaction before calling this function.", | ||
"test_decorator_async_py3.my_async_example_function", | ||
) | ||
assert result2 == "return_of_async_function" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.