|
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,92 @@ 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 | +def test_staticmethod_class_tracing(sentry_init, capture_events): |
| 938 | + sentry_init( |
| 939 | + debug=True, |
| 940 | + traces_sample_rate=1.0, |
| 941 | + functions_to_trace=[ |
| 942 | + {"qualified_name": "tests.test_basics.TracingTestClass.static"} |
| 943 | + ], |
| 944 | + ) |
940 | 945 |
|
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" |
| 946 | + events = capture_events() |
950 | 947 |
|
951 | | - sentry_init(functions_to_trace=[{"qualified_name": test_staticmethod_name}]) |
| 948 | + with sentry_sdk.start_transaction(name="test"): |
| 949 | + assert TracingTestClass.static(1) == 1 |
952 | 950 |
|
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 |
| 951 | + (event,) = events |
| 952 | + assert event["type"] == "transaction" |
| 953 | + assert event["transaction"] == "test" |
957 | 954 |
|
| 955 | + (span,) = event["spans"] |
| 956 | + assert span["description"] == "tests.test_basics.TracingTestClass.static" |
958 | 957 |
|
959 | | -def test_classmethod_tracing(sentry_init): |
960 | | - test_classmethod_name = "tests.test_basics.TracingTestClass.class_" |
961 | 958 |
|
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" |
| 959 | +def test_staticmethod_instance_tracing(sentry_init, capture_events): |
| 960 | + sentry_init( |
| 961 | + debug=True, |
| 962 | + traces_sample_rate=1.0, |
| 963 | + functions_to_trace=[ |
| 964 | + {"qualified_name": "tests.test_basics.TracingTestClass.static"} |
| 965 | + ], |
| 966 | + ) |
| 967 | + |
| 968 | + events = capture_events() |
| 969 | + |
| 970 | + with sentry_sdk.start_transaction(name="test"): |
| 971 | + assert TracingTestClass().static(1) == 1 |
| 972 | + |
| 973 | + (event,) = events |
| 974 | + assert event["type"] == "transaction" |
| 975 | + assert event["transaction"] == "test" |
971 | 976 |
|
972 | | - sentry_init(functions_to_trace=[{"qualified_name": test_classmethod_name}]) |
| 977 | + (span,) = event["spans"] |
| 978 | + assert span["description"] == "tests.test_basics.TracingTestClass.static" |
| 979 | + |
| 980 | + |
| 981 | +def test_classmethod_class_tracing(sentry_init, capture_events): |
| 982 | + sentry_init( |
| 983 | + debug=True, |
| 984 | + traces_sample_rate=1.0, |
| 985 | + functions_to_trace=[ |
| 986 | + {"qualified_name": "tests.test_basics.TracingTestClass.class_"} |
| 987 | + ], |
| 988 | + ) |
| 989 | + |
| 990 | + events = capture_events() |
| 991 | + |
| 992 | + with sentry_sdk.start_transaction(name="test"): |
| 993 | + assert TracingTestClass.class_(1) == (TracingTestClass, 1) |
| 994 | + |
| 995 | + (event,) = events |
| 996 | + assert event["type"] == "transaction" |
| 997 | + assert event["transaction"] == "test" |
| 998 | + |
| 999 | + (span,) = event["spans"] |
| 1000 | + assert span["description"] == "tests.test_basics.TracingTestClass.class_" |
| 1001 | + |
| 1002 | + |
| 1003 | +def test_classmethod_instance_tracing(sentry_init, capture_events): |
| 1004 | + sentry_init( |
| 1005 | + debug=True, |
| 1006 | + traces_sample_rate=1.0, |
| 1007 | + functions_to_trace=[ |
| 1008 | + {"qualified_name": "tests.test_basics.TracingTestClass.class_"} |
| 1009 | + ], |
| 1010 | + ) |
| 1011 | + |
| 1012 | + events = capture_events() |
| 1013 | + |
| 1014 | + with sentry_sdk.start_transaction(name="test"): |
| 1015 | + assert TracingTestClass().class_(1) == (TracingTestClass, 1) |
| 1016 | + |
| 1017 | + (event,) = events |
| 1018 | + assert event["type"] == "transaction" |
| 1019 | + assert event["transaction"] == "test" |
973 | 1020 |
|
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 |
| 1021 | + (span,) = event["spans"] |
| 1022 | + assert span["description"] == "tests.test_basics.TracingTestClass.class_" |
978 | 1023 |
|
979 | 1024 |
|
980 | 1025 | def test_last_event_id(sentry_init): |
|
0 commit comments