|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 | 3 | import json
|
| 4 | +import os |
| 5 | +import random |
4 | 6 | import re
|
5 | 7 | import pytest
|
6 |
| -import random |
7 | 8 | from functools import partial
|
8 | 9 |
|
9 | 10 | from werkzeug.test import Client
|
@@ -584,9 +585,7 @@ def test_django_connect_trace(sentry_init, client, capture_events, render_span_t
|
584 | 585 |
|
585 | 586 | @pytest.mark.forked
|
586 | 587 | @pytest_mark_django_db_decorator(transaction=True)
|
587 |
| -def test_django_connect_breadcrumbs( |
588 |
| - sentry_init, client, capture_events, render_span_tree |
589 |
| -): |
| 588 | +def test_django_connect_breadcrumbs(sentry_init, capture_events): |
590 | 589 | """
|
591 | 590 | Verify we record a breadcrumb when opening a new database.
|
592 | 591 | """
|
@@ -620,6 +619,43 @@ def test_django_connect_breadcrumbs(
|
620 | 619 | ]
|
621 | 620 |
|
622 | 621 |
|
| 622 | +@pytest.mark.forked |
| 623 | +@pytest_mark_django_db_decorator(transaction=True) |
| 624 | +def test_db_connection_span_data(sentry_init, client, capture_events): |
| 625 | + sentry_init( |
| 626 | + integrations=[DjangoIntegration()], |
| 627 | + send_default_pii=True, |
| 628 | + traces_sample_rate=1.0, |
| 629 | + ) |
| 630 | + from django.db import connections |
| 631 | + |
| 632 | + if "postgres" not in connections: |
| 633 | + pytest.skip("postgres tests disabled") |
| 634 | + |
| 635 | + # trigger Django to open a new connection by marking the existing one as None. |
| 636 | + connections["postgres"].connection = None |
| 637 | + |
| 638 | + events = capture_events() |
| 639 | + |
| 640 | + content, status, headers = client.get(reverse("postgres_select")) |
| 641 | + assert status == "200 OK" |
| 642 | + |
| 643 | + (event,) = events |
| 644 | + |
| 645 | + for span in event["spans"]: |
| 646 | + if span.get("op") == "db": |
| 647 | + data = span.get("data") |
| 648 | + assert data.get(SPANDATA.DB_SYSTEM) == "postgresql" |
| 649 | + assert ( |
| 650 | + data.get(SPANDATA.DB_NAME) |
| 651 | + == connections["postgres"].get_connection_params()["database"] |
| 652 | + ) |
| 653 | + assert data.get(SPANDATA.SERVER_ADDRESS) == os.environ.get( |
| 654 | + "SENTRY_PYTHON_TEST_POSTGRES_HOST", "localhost" |
| 655 | + ) |
| 656 | + assert data.get(SPANDATA.SERVER_PORT) == 5432 |
| 657 | + |
| 658 | + |
623 | 659 | @pytest.mark.parametrize(
|
624 | 660 | "transaction_style,client_url,expected_transaction,expected_source,expected_response",
|
625 | 661 | [
|
@@ -1059,11 +1095,7 @@ def dummy(a, b):
|
1059 | 1095 | @pytest_mark_django_db_decorator()
|
1060 | 1096 | @pytest.mark.skipif(DJANGO_VERSION < (1, 9), reason="Requires Django >= 1.9")
|
1061 | 1097 | def test_cache_spans_disabled_middleware(
|
1062 |
| - sentry_init, |
1063 |
| - client, |
1064 |
| - capture_events, |
1065 |
| - use_django_caching_with_middlewares, |
1066 |
| - settings, |
| 1098 | + sentry_init, client, capture_events, use_django_caching_with_middlewares |
1067 | 1099 | ):
|
1068 | 1100 | sentry_init(
|
1069 | 1101 | integrations=[
|
@@ -1141,11 +1173,7 @@ def test_cache_spans_disabled_templatetag(
|
1141 | 1173 | @pytest_mark_django_db_decorator()
|
1142 | 1174 | @pytest.mark.skipif(DJANGO_VERSION < (1, 9), reason="Requires Django >= 1.9")
|
1143 | 1175 | def test_cache_spans_middleware(
|
1144 |
| - sentry_init, |
1145 |
| - client, |
1146 |
| - capture_events, |
1147 |
| - use_django_caching_with_middlewares, |
1148 |
| - settings, |
| 1176 | + sentry_init, client, capture_events, use_django_caching_with_middlewares |
1149 | 1177 | ):
|
1150 | 1178 | sentry_init(
|
1151 | 1179 | integrations=[
|
|
0 commit comments