|
9 | 9 | import pytest
|
10 | 10 | from sentry_sdk.client import Client
|
11 | 11 | from sentry_sdk.utils import datetime_from_isoformat
|
12 |
| -from tests.conftest import patch_start_tracing_child |
13 | 12 |
|
14 | 13 | import sentry_sdk
|
15 | 14 | import sentry_sdk.scope
|
@@ -935,46 +934,96 @@ def class_(cls, arg):
|
935 | 934 | return cls, arg
|
936 | 935 |
|
937 | 936 |
|
938 |
| -def test_staticmethod_tracing(sentry_init): |
939 |
| - test_staticmethod_name = "tests.test_basics.TracingTestClass.static" |
| 937 | +@pytest.mark.forked |
| 938 | +def test_staticmethod_class_tracing(sentry_init, capture_events): |
| 939 | + sentry_init( |
| 940 | + debug=True, |
| 941 | + traces_sample_rate=1.0, |
| 942 | + functions_to_trace=[ |
| 943 | + {"qualified_name": "tests.test_basics.TracingTestClass.static"} |
| 944 | + ], |
| 945 | + ) |
940 | 946 |
|
941 |
| - assert ( |
942 |
| - ".".join( |
943 |
| - [ |
944 |
| - TracingTestClass.static.__module__, |
945 |
| - TracingTestClass.static.__qualname__, |
946 |
| - ] |
947 |
| - ) |
948 |
| - == test_staticmethod_name |
949 |
| - ), "The test static method was moved or renamed. Please update the name accordingly" |
| 947 | + events = capture_events() |
950 | 948 |
|
951 |
| - sentry_init(functions_to_trace=[{"qualified_name": test_staticmethod_name}]) |
| 949 | + with sentry_sdk.start_transaction(name="test"): |
| 950 | + assert TracingTestClass.static(1) == 1 |
952 | 951 |
|
953 |
| - for instance_or_class in (TracingTestClass, TracingTestClass()): |
954 |
| - with patch_start_tracing_child() as fake_start_child: |
955 |
| - assert instance_or_class.static(1) == 1 |
956 |
| - assert fake_start_child.call_count == 1 |
| 952 | + (event,) = events |
| 953 | + assert event["type"] == "transaction" |
| 954 | + assert event["transaction"] == "test" |
957 | 955 |
|
| 956 | + (span,) = event["spans"] |
| 957 | + assert span["description"] == "tests.test_basics.TracingTestClass.static" |
958 | 958 |
|
959 |
| -def test_classmethod_tracing(sentry_init): |
960 |
| - test_classmethod_name = "tests.test_basics.TracingTestClass.class_" |
961 | 959 |
|
962 |
| - assert ( |
963 |
| - ".".join( |
964 |
| - [ |
965 |
| - TracingTestClass.class_.__module__, |
966 |
| - TracingTestClass.class_.__qualname__, |
967 |
| - ] |
968 |
| - ) |
969 |
| - == test_classmethod_name |
970 |
| - ), "The test class method was moved or renamed. Please update the name accordingly" |
| 960 | +@pytest.mark.forked |
| 961 | +def test_staticmethod_instance_tracing(sentry_init, capture_events): |
| 962 | + sentry_init( |
| 963 | + debug=True, |
| 964 | + traces_sample_rate=1.0, |
| 965 | + functions_to_trace=[ |
| 966 | + {"qualified_name": "tests.test_basics.TracingTestClass.static"} |
| 967 | + ], |
| 968 | + ) |
| 969 | + |
| 970 | + events = capture_events() |
| 971 | + |
| 972 | + with sentry_sdk.start_transaction(name="test"): |
| 973 | + assert TracingTestClass().static(1) == 1 |
| 974 | + |
| 975 | + (event,) = events |
| 976 | + assert event["type"] == "transaction" |
| 977 | + assert event["transaction"] == "test" |
971 | 978 |
|
972 |
| - sentry_init(functions_to_trace=[{"qualified_name": test_classmethod_name}]) |
| 979 | + (span,) = event["spans"] |
| 980 | + assert span["description"] == "tests.test_basics.TracingTestClass.static" |
| 981 | + |
| 982 | + |
| 983 | +@pytest.mark.forked |
| 984 | +def test_classmethod_class_tracing(sentry_init, capture_events): |
| 985 | + sentry_init( |
| 986 | + debug=True, |
| 987 | + traces_sample_rate=1.0, |
| 988 | + functions_to_trace=[ |
| 989 | + {"qualified_name": "tests.test_basics.TracingTestClass.class_"} |
| 990 | + ], |
| 991 | + ) |
| 992 | + |
| 993 | + events = capture_events() |
| 994 | + |
| 995 | + with sentry_sdk.start_transaction(name="test"): |
| 996 | + assert TracingTestClass.class_(1) == (TracingTestClass, 1) |
| 997 | + |
| 998 | + (event,) = events |
| 999 | + assert event["type"] == "transaction" |
| 1000 | + assert event["transaction"] == "test" |
| 1001 | + |
| 1002 | + (span,) = event["spans"] |
| 1003 | + assert span["description"] == "tests.test_basics.TracingTestClass.class_" |
| 1004 | + |
| 1005 | + |
| 1006 | +@pytest.mark.forked |
| 1007 | +def test_classmethod_instance_tracing(sentry_init, capture_events): |
| 1008 | + sentry_init( |
| 1009 | + debug=True, |
| 1010 | + traces_sample_rate=1.0, |
| 1011 | + functions_to_trace=[ |
| 1012 | + {"qualified_name": "tests.test_basics.TracingTestClass.class_"} |
| 1013 | + ], |
| 1014 | + ) |
| 1015 | + |
| 1016 | + events = capture_events() |
| 1017 | + |
| 1018 | + with sentry_sdk.start_transaction(name="test"): |
| 1019 | + assert TracingTestClass().class_(1) == (TracingTestClass, 1) |
| 1020 | + |
| 1021 | + (event,) = events |
| 1022 | + assert event["type"] == "transaction" |
| 1023 | + assert event["transaction"] == "test" |
973 | 1024 |
|
974 |
| - for instance_or_class in (TracingTestClass, TracingTestClass()): |
975 |
| - with patch_start_tracing_child() as fake_start_child: |
976 |
| - assert instance_or_class.class_(1) == (TracingTestClass, 1) |
977 |
| - assert fake_start_child.call_count == 1 |
| 1025 | + (span,) = event["spans"] |
| 1026 | + assert span["description"] == "tests.test_basics.TracingTestClass.class_" |
978 | 1027 |
|
979 | 1028 |
|
980 | 1029 | def test_last_event_id(sentry_init):
|
|
0 commit comments