Skip to content

Commit 1d83903

Browse files
authored
test: Use top-level options if available (#6959)
Properly this time...
1 parent cbfb30e commit 1d83903

24 files changed

Lines changed: 158 additions & 369 deletions

tests/integrations/aiohttp/test_aiohttp.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,10 +1904,7 @@ async def test_server_url_query_data_collection_span_streaming(
19041904
sentry_init(
19051905
integrations=[AioHttpIntegration()],
19061906
traces_sample_rate=1.0,
1907-
_experiments={
1908-
"trace_lifecycle": "stream",
1909-
**init_kwargs.pop("_experiments", {}),
1910-
},
1907+
trace_lifecycle="stream",
19111908
**init_kwargs,
19121909
)
19131910

@@ -1949,10 +1946,7 @@ async def test_client_url_query_data_collection_span_streaming(
19491946
sentry_init(
19501947
integrations=[AioHttpIntegration()],
19511948
traces_sample_rate=1.0,
1952-
_experiments={
1953-
"trace_lifecycle": "stream",
1954-
**init_kwargs.pop("_experiments", {}),
1955-
},
1949+
trace_lifecycle="stream",
19561950
**init_kwargs,
19571951
)
19581952

tests/integrations/aiomysql/test_aiomysql.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,7 @@ async def test_query_source_disabled(
441441
"traces_sample_rate": 1.0,
442442
"enable_db_query_source": False,
443443
"db_query_source_threshold_ms": 0,
444-
"_experiments": {
445-
"trace_lifecycle": "stream" if span_streaming else "static",
446-
},
444+
"trace_lifecycle": "stream" if span_streaming else "static",
447445
}
448446

449447
sentry_init(**sentry_options)
@@ -516,9 +514,7 @@ async def test_query_source_enabled(
516514
"integrations": [AioMySQLIntegration()],
517515
"traces_sample_rate": 1.0,
518516
"db_query_source_threshold_ms": 0,
519-
"_experiments": {
520-
"trace_lifecycle": "stream" if span_streaming else "static",
521-
},
517+
"trace_lifecycle": "stream" if span_streaming else "static",
522518
}
523519
if enable_db_query_source is not None:
524520
sentry_options["enable_db_query_source"] = enable_db_query_source
@@ -591,9 +587,7 @@ async def test_query_source(sentry_init, capture_events, capture_items, span_str
591587
traces_sample_rate=1.0,
592588
enable_db_query_source=True,
593589
db_query_source_threshold_ms=0,
594-
_experiments={
595-
"trace_lifecycle": "stream" if span_streaming else "static",
596-
},
590+
trace_lifecycle="stream" if span_streaming else "static",
597591
)
598592

599593
if span_streaming:
@@ -692,9 +686,7 @@ async def test_no_query_source_if_duration_too_short(
692686
traces_sample_rate=1.0,
693687
enable_db_query_source=True,
694688
db_query_source_threshold_ms=100,
695-
_experiments={
696-
"trace_lifecycle": "stream" if span_streaming else "static",
697-
},
689+
trace_lifecycle="stream" if span_streaming else "static",
698690
)
699691

700692
if span_streaming:
@@ -789,9 +781,7 @@ async def test_query_source_if_duration_over_threshold(
789781
traces_sample_rate=1.0,
790782
enable_db_query_source=True,
791783
db_query_source_threshold_ms=100,
792-
_experiments={
793-
"trace_lifecycle": "stream" if span_streaming else "static",
794-
},
784+
trace_lifecycle="stream" if span_streaming else "static",
795785
)
796786

797787
if span_streaming:
@@ -915,9 +905,7 @@ async def test_span_origin(sentry_init, capture_events, capture_items, span_stre
915905
sentry_init(
916906
integrations=[AioMySQLIntegration()],
917907
traces_sample_rate=1.0,
918-
_experiments={
919-
"trace_lifecycle": "stream" if span_streaming else "static",
920-
},
908+
trace_lifecycle="stream" if span_streaming else "static",
921909
)
922910

923911
if span_streaming:
@@ -972,9 +960,7 @@ async def test_multiline_query_description_normalized(
972960
sentry_init(
973961
integrations=[AioMySQLIntegration()],
974962
traces_sample_rate=1.0,
975-
_experiments={
976-
"trace_lifecycle": "stream" if span_streaming else "static",
977-
},
963+
trace_lifecycle="stream" if span_streaming else "static",
978964
)
979965

980966
if span_streaming:
@@ -1099,9 +1085,7 @@ async def test_db_data_on_spans(
10991085
sentry_init(
11001086
integrations=[AioMySQLIntegration()],
11011087
traces_sample_rate=1.0,
1102-
_experiments={
1103-
"trace_lifecycle": "stream" if span_streaming else "static",
1104-
},
1088+
trace_lifecycle="stream" if span_streaming else "static",
11051089
)
11061090

11071091
if span_streaming:

tests/integrations/asgi/test_asgi.py

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ async def test_capture_transaction(
186186
sentry_init(
187187
send_default_pii=should_send_pii,
188188
traces_sample_rate=1.0,
189-
_experiments={
190-
"trace_lifecycle": "stream" if span_streaming else "static",
191-
},
189+
trace_lifecycle="stream" if span_streaming else "static",
192190
)
193191
app = SentryAsgiMiddleware(asgi3_app)
194192

@@ -262,9 +260,7 @@ async def test_capture_transaction_with_error(
262260
sentry_init(
263261
send_default_pii=True,
264262
traces_sample_rate=1.0,
265-
_experiments={
266-
"trace_lifecycle": "stream" if span_streaming else "static",
267-
},
263+
trace_lifecycle="stream" if span_streaming else "static",
268264
)
269265

270266
app = SentryAsgiMiddleware(asgi3_app_with_error)
@@ -330,9 +326,7 @@ async def test_has_trace_if_performance_enabled(
330326
):
331327
sentry_init(
332328
traces_sample_rate=1.0,
333-
_experiments={
334-
"trace_lifecycle": "stream" if span_streaming else "static",
335-
},
329+
trace_lifecycle="stream" if span_streaming else "static",
336330
)
337331
app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg)
338332

@@ -425,9 +419,7 @@ async def test_trace_from_headers_if_performance_enabled(
425419
):
426420
sentry_init(
427421
traces_sample_rate=1.0,
428-
_experiments={
429-
"trace_lifecycle": "stream" if span_streaming else "static",
430-
},
422+
trace_lifecycle="stream" if span_streaming else "static",
431423
)
432424
app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg)
433425

@@ -526,9 +518,7 @@ async def test_websocket(
526518
sentry_init(
527519
send_default_pii=True,
528520
traces_sample_rate=1.0,
529-
_experiments={
530-
"trace_lifecycle": "stream" if span_streaming else "static",
531-
},
521+
trace_lifecycle="stream" if span_streaming else "static",
532522
)
533523

534524
asgi3_ws_app = SentryAsgiMiddleware(asgi3_ws_app)
@@ -655,9 +645,7 @@ async def test_transaction_style(
655645
sentry_init(
656646
send_default_pii=True,
657647
traces_sample_rate=1.0,
658-
_experiments={
659-
"trace_lifecycle": "stream" if span_streaming else "static",
660-
},
648+
trace_lifecycle="stream" if span_streaming else "static",
661649
)
662650
app = SentryAsgiMiddleware(asgi3_app, transaction_style=transaction_style)
663651

@@ -874,8 +862,8 @@ async def test_get_request_attributes_url_with_filtered_host(
874862
sentry_init(
875863
send_default_pii=True,
876864
traces_sample_rate=1.0,
865+
trace_lifecycle="stream",
877866
_experiments={
878-
"trace_lifecycle": "stream",
879867
"data_collection": {
880868
"http_headers": {"request": {"mode": "allowlist", "terms": []}}
881869
},
@@ -906,8 +894,8 @@ async def test_get_request_attributes_url_with_headers_off(
906894
sentry_init(
907895
send_default_pii=True,
908896
traces_sample_rate=1.0,
897+
trace_lifecycle="stream",
909898
_experiments={
910-
"trace_lifecycle": "stream",
911899
"data_collection": {"http_headers": {"request": {"mode": "off"}}},
912900
},
913901
)
@@ -1140,9 +1128,11 @@ async def test_get_request_attributes_query_data_collection(
11401128
expected_query,
11411129
expected_url_full,
11421130
):
1143-
kwargs = {k: v for k, v in init_kwargs.items() if k != "_experiments"}
1144-
experiments = {"trace_lifecycle": "stream", **init_kwargs.get("_experiments", {})}
1145-
sentry_init(traces_sample_rate=1.0, _experiments=experiments, **kwargs)
1131+
sentry_init(
1132+
traces_sample_rate=1.0,
1133+
trace_lifecycle="stream",
1134+
**init_kwargs,
1135+
)
11461136
app = SentryAsgiMiddleware(asgi3_app)
11471137

11481138
items = capture_items("span")
@@ -1242,9 +1232,11 @@ async def test_get_request_data_env_user_info(
12421232
async def test_get_request_attributes_client_address_user_info(
12431233
sentry_init, capture_items, asgi3_app, init_kwargs, has_client, expect_ip
12441234
):
1245-
kwargs = {k: v for k, v in init_kwargs.items() if k != "_experiments"}
1246-
experiments = {"trace_lifecycle": "stream", **init_kwargs.get("_experiments", {})}
1247-
sentry_init(traces_sample_rate=1.0, _experiments=experiments, **kwargs)
1235+
sentry_init(
1236+
traces_sample_rate=1.0,
1237+
trace_lifecycle="stream",
1238+
**init_kwargs,
1239+
)
12481240
app = SentryAsgiMiddleware(asgi3_app)
12491241

12501242
scope = _http_scope()
@@ -1304,9 +1296,7 @@ async def test_transaction_name(
13041296
"""
13051297
sentry_init(
13061298
traces_sample_rate=1.0,
1307-
_experiments={
1308-
"trace_lifecycle": "stream" if span_streaming else "static",
1309-
},
1299+
trace_lifecycle="stream" if span_streaming else "static",
13101300
)
13111301

13121302
if span_streaming:
@@ -1390,9 +1380,7 @@ def dummy_traces_sampler(sampling_context):
13901380
sentry_init(
13911381
traces_sampler=dummy_traces_sampler,
13921382
traces_sample_rate=1.0,
1393-
_experiments={
1394-
"trace_lifecycle": "stream" if span_streaming else "static",
1395-
},
1383+
trace_lifecycle="stream" if span_streaming else "static",
13961384
)
13971385

13981386
app = SentryAsgiMiddleware(asgi3_app, transaction_style=transaction_style)
@@ -1415,9 +1403,7 @@ async def test_custom_transaction_name(
14151403
):
14161404
sentry_init(
14171405
traces_sample_rate=1.0,
1418-
_experiments={
1419-
"trace_lifecycle": "stream" if span_streaming else "static",
1420-
},
1406+
trace_lifecycle="stream" if span_streaming else "static",
14211407
)
14221408
app = SentryAsgiMiddleware(asgi3_custom_transaction_app)
14231409

@@ -1505,11 +1491,9 @@ async def app(scope, receive, send):
15051491
await send({"type": "http.response.body", "body": b"Hello, world!"})
15061492

15071493
kwargs = dict(init_kwargs)
1508-
experiments = kwargs.pop("_experiments", {})
15091494
sentry_init(
15101495
trace_lifecycle="stream",
15111496
traces_sample_rate=1.0,
1512-
_experiments=experiments,
15131497
**kwargs,
15141498
)
15151499
sentry_app = SentryAsgiMiddleware(app)

tests/integrations/asyncio/test_asyncio.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ async def test_create_task(
7676
integrations=[
7777
AsyncioIntegration(),
7878
],
79-
_experiments={
80-
"trace_lifecycle": "stream" if span_streaming else "static",
81-
},
79+
trace_lifecycle="stream" if span_streaming else "static",
8280
)
8381

8482
if span_streaming:
@@ -171,9 +169,7 @@ async def test_gather(
171169
integrations=[
172170
AsyncioIntegration(),
173171
],
174-
_experiments={
175-
"trace_lifecycle": "stream" if span_streaming else "static",
176-
},
172+
trace_lifecycle="stream" if span_streaming else "static",
177173
)
178174

179175
if span_streaming:
@@ -463,9 +459,7 @@ async def test_span_origin(
463459
sentry_init(
464460
integrations=[AsyncioIntegration()],
465461
traces_sample_rate=1.0,
466-
_experiments={
467-
"trace_lifecycle": "stream" if span_streaming else "static",
468-
},
462+
trace_lifecycle="stream" if span_streaming else "static",
469463
)
470464

471465
if span_streaming:
@@ -520,9 +514,7 @@ async def test_task_spans_false(
520514
integrations=[
521515
AsyncioIntegration(task_spans=False),
522516
],
523-
_experiments={
524-
"trace_lifecycle": "stream" if span_streaming else "static",
525-
},
517+
trace_lifecycle="stream" if span_streaming else "static",
526518
)
527519

528520
if span_streaming:
@@ -594,9 +586,7 @@ async def test_delayed_enable_integration(
594586
):
595587
sentry_init(
596588
traces_sample_rate=1.0,
597-
_experiments={
598-
"trace_lifecycle": "stream" if span_streaming else "static",
599-
},
589+
trace_lifecycle="stream" if span_streaming else "static",
600590
)
601591

602592
assert "asyncio" not in sentry_sdk.get_client().integrations
@@ -711,9 +701,7 @@ async def test_delayed_enable_integration_after_disabling(
711701
sentry_init(
712702
disabled_integrations=[AsyncioIntegration()],
713703
traces_sample_rate=1.0,
714-
_experiments={
715-
"trace_lifecycle": "stream" if span_streaming else "static",
716-
},
704+
trace_lifecycle="stream" if span_streaming else "static",
717705
)
718706

719707
assert "asyncio" not in sentry_sdk.get_client().integrations
@@ -782,9 +770,7 @@ async def test_internal_tasks_not_wrapped(
782770
sentry_init(
783771
integrations=[AsyncioIntegration()],
784772
traces_sample_rate=1.0,
785-
_experiments={
786-
"trace_lifecycle": "stream" if span_streaming else "static",
787-
},
773+
trace_lifecycle="stream" if span_streaming else "static",
788774
)
789775

790776
async def user_task():

0 commit comments

Comments
 (0)