10
10
start_span ,
11
11
start_transaction ,
12
12
)
13
- from sentry_sdk .tracing import Span , Transaction
13
+ from sentry_sdk .tracing import Transaction
14
14
15
15
16
16
@pytest .mark .parametrize ("sample_rate" , [0.0 , 1.0 ])
@@ -46,23 +46,6 @@ def test_basic(sentry_init, capture_events, sample_rate):
46
46
assert not events
47
47
48
48
49
- def test_start_span_to_start_transaction (sentry_init , capture_events ):
50
- # XXX: this only exists for backwards compatibility with code before
51
- # Transaction / start_transaction were introduced.
52
- sentry_init (traces_sample_rate = 1.0 )
53
- events = capture_events ()
54
-
55
- with start_span (transaction = "/1/" ):
56
- pass
57
-
58
- with start_span (Span (transaction = "/2/" )):
59
- pass
60
-
61
- assert len (events ) == 2
62
- assert events [0 ]["transaction" ] == "/1/"
63
- assert events [1 ]["transaction" ] == "/2/"
64
-
65
-
66
49
@pytest .mark .parametrize ("sampled" , [True , False , None ])
67
50
def test_continue_from_headers (sentry_init , capture_events , sampled ):
68
51
sentry_init (traces_sample_rate = 1.0 )
@@ -114,19 +97,6 @@ def test_continue_from_headers(sentry_init, capture_events, sampled):
114
97
assert message ["message" ] == "hello"
115
98
116
99
117
- def test_sampling_decided_only_for_transactions (sentry_init , capture_events ):
118
- sentry_init (traces_sample_rate = 0.5 )
119
-
120
- with start_transaction (name = "hi" ) as transaction :
121
- assert transaction .sampled is not None
122
-
123
- with start_span () as span :
124
- assert span .sampled == transaction .sampled
125
-
126
- with start_span () as span :
127
- assert span .sampled is None
128
-
129
-
130
100
@pytest .mark .parametrize (
131
101
"args,expected_refcount" ,
132
102
[({"traces_sample_rate" : 1.0 }, 100 ), ({"traces_sample_rate" : 0.0 }, 0 )],
@@ -156,67 +126,6 @@ def foo():
156
126
assert len (references ) == expected_refcount
157
127
158
128
159
- def test_span_trimming (sentry_init , capture_events ):
160
- sentry_init (traces_sample_rate = 1.0 , _experiments = {"max_spans" : 3 })
161
- events = capture_events ()
162
-
163
- with start_transaction (name = "hi" ):
164
- for i in range (10 ):
165
- with start_span (op = "foo{}" .format (i )):
166
- pass
167
-
168
- (event ,) = events
169
- span1 , span2 = event ["spans" ]
170
- assert span1 ["op" ] == "foo0"
171
- assert span2 ["op" ] == "foo1"
172
-
173
-
174
- def test_nested_transaction_sampling_override ():
175
- with start_transaction (name = "outer" , sampled = True ) as outer_transaction :
176
- assert outer_transaction .sampled is True
177
- with start_transaction (name = "inner" , sampled = False ) as inner_transaction :
178
- assert inner_transaction .sampled is False
179
- assert outer_transaction .sampled is True
180
-
181
-
182
- def test_transaction_method_signature (sentry_init , capture_events ):
183
- sentry_init (traces_sample_rate = 1.0 )
184
- events = capture_events ()
185
-
186
- with pytest .raises (TypeError ):
187
- start_span (name = "foo" )
188
- assert len (events ) == 0
189
-
190
- with start_transaction () as transaction :
191
- pass
192
- assert transaction .name == "<unlabeled transaction>"
193
- assert len (events ) == 1
194
-
195
- with start_transaction () as transaction :
196
- transaction .name = "name-known-after-transaction-started"
197
- assert len (events ) == 2
198
-
199
- with start_transaction (name = "a" ):
200
- pass
201
- assert len (events ) == 3
202
-
203
- with start_transaction (Transaction (name = "c" )):
204
- pass
205
- assert len (events ) == 4
206
-
207
-
208
- def test_no_double_sampling (sentry_init , capture_events ):
209
- # Transactions should not be subject to the global/error sample rate.
210
- # Only the traces_sample_rate should apply.
211
- sentry_init (traces_sample_rate = 1.0 , sample_rate = 0.0 )
212
- events = capture_events ()
213
-
214
- with start_transaction (name = "/" ):
215
- pass
216
-
217
- assert len (events ) == 1
218
-
219
-
220
129
def test_transactions_do_not_go_through_before_send (sentry_init , capture_events ):
221
130
def before_send (event , hint ):
222
131
raise RuntimeError ("should not be called" )
@@ -228,17 +137,3 @@ def before_send(event, hint):
228
137
pass
229
138
230
139
assert len (events ) == 1
231
-
232
-
233
- def test_get_transaction_from_scope (sentry_init , capture_events ):
234
- sentry_init (traces_sample_rate = 1.0 )
235
- events = capture_events ()
236
-
237
- with start_transaction (name = "/" ):
238
- with start_span (op = "child-span" ):
239
- with start_span (op = "child-child-span" ):
240
- scope = Hub .current .scope
241
- assert scope .span .op == "child-child-span"
242
- assert scope .transaction .name == "/"
243
-
244
- assert len (events ) == 1
0 commit comments