|
22 | 22 | from sentry_sdk._compat import PY2, PY310 |
23 | 23 | from sentry_sdk import capture_message, capture_exception, configure_scope |
24 | 24 | from sentry_sdk.consts import SPANDATA |
25 | | -from sentry_sdk.integrations.django import DjangoIntegration |
| 25 | +from sentry_sdk.integrations.django import DjangoIntegration, _set_db_data |
26 | 26 | from sentry_sdk.integrations.django.signals_handlers import _get_receiver_name |
27 | 27 | from sentry_sdk.integrations.django.caching import _get_span_description |
28 | 28 | from sentry_sdk.integrations.executing import ExecutingIntegration |
| 29 | +from sentry_sdk.tracing import Span |
29 | 30 | from tests.integrations.django.myapp.wsgi import application |
30 | 31 | from tests.integrations.django.utils import pytest_mark_django_db_decorator |
31 | 32 |
|
@@ -656,6 +657,24 @@ def test_db_connection_span_data(sentry_init, client, capture_events): |
656 | 657 | assert data.get(SPANDATA.SERVER_PORT) == "5432" |
657 | 658 |
|
658 | 659 |
|
| 660 | +def test_set_db_data_custom_backend(): |
| 661 | + class DummyBackend(object): |
| 662 | + # https://github.com/mongodb/mongo-python-driver/blob/6ffae5522c960252b8c9adfe2a19b29ff28187cb/pymongo/collection.py#L126 |
| 663 | + def __getattr__(self, attr): |
| 664 | + return self |
| 665 | + |
| 666 | + def __call__(self): |
| 667 | + raise TypeError |
| 668 | + |
| 669 | + def get_connection_params(self): |
| 670 | + return {} |
| 671 | + |
| 672 | + try: |
| 673 | + _set_db_data(Span(), DummyBackend()) |
| 674 | + except TypeError: |
| 675 | + pytest.fail("A TypeError was raised") |
| 676 | + |
| 677 | + |
659 | 678 | @pytest.mark.parametrize( |
660 | 679 | "transaction_style,client_url,expected_transaction,expected_source,expected_response", |
661 | 680 | [ |
|
0 commit comments