11
11
RustTracingLevel ,
12
12
EventTypeMapping ,
13
13
)
14
- from sentry_sdk import start_transaction , capture_message
14
+ from sentry_sdk import start_span , capture_message
15
+ from tests .conftest import ApproxDict
15
16
16
17
17
18
def _test_event_type_mapping (metadata : Dict [str , object ]) -> EventTypeMapping :
@@ -74,11 +75,11 @@ def test_on_new_span_on_close(sentry_init, capture_events):
74
75
sentry_init (integrations = [integration ], traces_sample_rate = 1.0 )
75
76
76
77
events = capture_events ()
77
- with start_transaction ():
78
+ with start_span ():
78
79
rust_tracing .new_span (RustTracingLevel .Info , 3 )
79
80
80
81
sentry_first_rust_span = sentry_sdk .get_current_span ()
81
- _ , rust_first_rust_span = rust_tracing .spans [3 ]
82
+ rust_first_rust_span = rust_tracing .spans [3 ]
82
83
83
84
assert sentry_first_rust_span == rust_first_rust_span
84
85
@@ -102,7 +103,7 @@ def test_on_new_span_on_close(sentry_init, capture_events):
102
103
data = span ["data" ]
103
104
assert data ["use_memoized" ]
104
105
assert data ["index" ] == 10
105
- assert data [ "version" ] is None
106
+ assert "version" not in data
106
107
107
108
108
109
def test_nested_on_new_span_on_close (sentry_init , capture_events ):
@@ -115,23 +116,20 @@ def test_nested_on_new_span_on_close(sentry_init, capture_events):
115
116
sentry_init (integrations = [integration ], traces_sample_rate = 1.0 )
116
117
117
118
events = capture_events ()
118
- with start_transaction ():
119
+ with start_span ():
119
120
original_sentry_span = sentry_sdk .get_current_span ()
120
121
121
122
rust_tracing .new_span (RustTracingLevel .Info , 3 , index_arg = 10 )
122
123
sentry_first_rust_span = sentry_sdk .get_current_span ()
123
- _ , rust_first_rust_span = rust_tracing .spans [3 ]
124
+ rust_first_rust_span = rust_tracing .spans [3 ]
124
125
125
126
# Use a different `index_arg` value for the inner span to help
126
127
# distinguish the two at the end of the test
127
128
rust_tracing .new_span (RustTracingLevel .Info , 5 , index_arg = 9 )
128
129
sentry_second_rust_span = sentry_sdk .get_current_span ()
129
- rust_parent_span , rust_second_rust_span = rust_tracing .spans [5 ]
130
+ rust_second_rust_span = rust_tracing .spans [5 ]
130
131
131
132
assert rust_second_rust_span == sentry_second_rust_span
132
- assert rust_parent_span == sentry_first_rust_span
133
- assert rust_parent_span == rust_first_rust_span
134
- assert rust_parent_span != rust_second_rust_span
135
133
136
134
rust_tracing .close_span (5 )
137
135
@@ -171,12 +169,12 @@ def test_nested_on_new_span_on_close(sentry_init, capture_events):
171
169
first_span_data = first_span ["data" ]
172
170
assert first_span_data ["use_memoized" ]
173
171
assert first_span_data ["index" ] == 10
174
- assert first_span_data [ "version" ] is None
172
+ assert "version" not in first_span_data
175
173
176
174
second_span_data = second_span ["data" ]
177
175
assert second_span_data ["use_memoized" ]
178
176
assert second_span_data ["index" ] == 9
179
- assert second_span_data [ "version" ] is None
177
+ assert "version" not in second_span_data
180
178
181
179
182
180
def test_on_new_span_without_transaction (sentry_init ):
@@ -207,7 +205,7 @@ def test_on_event_exception(sentry_init, capture_events):
207
205
events = capture_events ()
208
206
sentry_sdk .get_isolation_scope ().clear_breadcrumbs ()
209
207
210
- with start_transaction ():
208
+ with start_span ():
211
209
rust_tracing .new_span (RustTracingLevel .Info , 3 )
212
210
213
211
# Mapped to Exception
@@ -243,7 +241,7 @@ def test_on_event_breadcrumb(sentry_init, capture_events):
243
241
events = capture_events ()
244
242
sentry_sdk .get_isolation_scope ().clear_breadcrumbs ()
245
243
246
-
1241
with start_transaction ():
244
+ with start_span ():
247
245
rust_tracing .new_span (RustTracingLevel .Info , 3 )
248
246
249
247
# Mapped to Breadcrumb
@@ -274,7 +272,7 @@ def test_on_event_event(sentry_init, capture_events):
274
272
events = capture_events ()
275
273
sentry_sdk .get_isolation_scope ().clear_breadcrumbs ()
276
274
277
- with start_transaction ():
275
+ with start_span ():
278
276
rust_tracing .new_span (RustTracingLevel .Info , 3 )
279
277
280
278
# Mapped to Event
@@ -311,7 +309,7 @@ def test_on_event_ignored(sentry_init, capture_events):
311
309
events = capture_events ()
312
310
sentry_sdk .get_isolation_scope ().clear_breadcrumbs ()
313
311
314
- with start_transaction ():
312
+ with start_span ():
315
313
rust_tracing .new_span (RustTracingLevel .Info , 3 )
316
314
317
315
# Ignored
@@ -344,7 +342,7 @@ def span_filter(metadata: Dict[str, object]) -> bool:
344
342
sentry_init (integrations = [integration ], traces_sample_rate = 1.0 )
345
343
346
344
events = capture_events ()
347
- with start_transaction ():
345
+ with start_span ():
348
346
original_sentry_span = sentry_sdk .get_current_span ()
349
347
350
348
# Span is not ignored
@@ -377,16 +375,16 @@ def test_record(sentry_init):
377
375
)
378
376
sentry_init (integrations = [integration ], traces_sample_rate = 1.0 )
379
377
380
- with start_transaction ():
378
+ with start_span ():
381
379
rust_tracing .new_span (RustTracingLevel .Info , 3 )
382
380
383
381
span_before_record = sentry_sdk .get_current_span ().to_json ()
384
- assert span_before_record [ "data" ][ "version" ] is None
382
+ assert "version" not in span_before_record [ "attributes" ]
385
383
386
384
rust_tracing .record (3 )
387
385
388
386
span_after_record = sentry_sdk .get_current_span ().to_json ()
389
- assert span_after_record ["data " ]["version" ] == "memoized"
387
+ assert span_after_record ["attributes " ]["version" ] == "memoized"
390
388
391
389
392
390
def test_record_in_ignored_span (sentry_init ):
@@ -403,18 +401,18 @@ def span_filter(metadata: Dict[str, object]) -> bool:
403
401
)
404
402
sentry_init (integrations = [integration ], traces_sample_rate = 1.0 )
405
403
406
- with start_transaction ():
404
+ with start_span ():
407
405
rust_tracing .new_span (RustTracingLevel .Info , 3 )
408
406
409
407
span_before_record = sentry_sdk .get_current_span ().to_json ()
410
- assert span_before_record [ "data" ][ "version" ] is None
408
+ assert "version" not in span_before_record [ "attributes" ]
411
409
412
410
rust_tracing .new_span (RustTracingLevel .Trace , 5 )
413
411
rust_tracing .record (5 )
414
412
415
413
# `on_record()` should not do anything to the current Sentry span if the associated Rust span was ignored
416
414
span_after_record = sentry_sdk .get_current_span ().to_json ()
417
- assert span_after_record [ "data" ][ "version" ] is None
415
+ assert "version" not in span_after_record [ "attributes" ]
418
416
419
417
420
418
@pytest .mark .parametrize (
@@ -443,33 +441,37 @@ def test_include_tracing_fields(
443
441
traces_sample_rate = 1.0 ,
444
442
send_default_pii = send_default_pii ,
445
443
)
446
- with start_transaction ():
444
+ with start_span ():
447
445
rust_tracing .new_span (RustTracingLevel .Info , 3 )
448
446
449
447
span_before_record = sentry_sdk .get_current_span ().to_json ()
450
448
if tracing_fields_expected :
451
- assert span_before_record [ "data" ][ "version" ] is None
449
+ assert "version" not in span_before_record [ "attributes" ]
452
450
else :
453
- assert span_before_record ["data " ]["version" ] == "[Filtered]"
451
+ assert span_before_record ["attributes " ]["version" ] == "[Filtered]"
454
452
455
453
rust_tracing .record (3 )
456
454
457
455
span_after_record = sentry_sdk .get_current_span ().to_json ()
458
456
459
457
if tracing_fields_expected :
460
- assert span_after_record ["data" ] == {
461
- "thread.id" : mock .ANY ,
462
- "thread.name" : mock .ANY ,
463
- "use_memoized" : True ,
464
- "version" : "memoized" ,
465
- "index" : 10 ,
466
- }
458
+ assert span_after_record ["attributes" ] == ApproxDict (
459
+ {
460
+ "thread.id" : mock .ANY ,
461
+ "thread.name" : mock .ANY ,
462
+ "use_memoized" : True ,
463
+ "version" : "memoized" ,
464
+ "index" : 10 ,
465
+ }
466
+ )
467
467
468
468
else :
469
- assert span_after_record ["data" ] == {
470
- "thread.id" : mock .ANY ,
471
- "thread.name" : mock .ANY ,
472
- "use_memoized" : "[Filtered]" ,
473
- "version" : "[Filtered]" ,
474
- "index" : "[Filtered]" ,
475
- }
469
+ assert span_after_record ["attributes" ] == ApproxDict (
470
+ {
471
+ "thread.id" : mock .ANY ,
472
+ "thread.name" : mock .ANY ,
473
+ "use_memoized" : "[Filtered]" ,
474
+ "version" : "[Filtered]" ,
475
+ "index" : "[Filtered]" ,
476
+ }
477
+ )
0 commit comments