From 472aa9ac316509bc654546921f42cbb4391ecec8 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 11 Sep 2026 11:00:55 +0200 Subject: [PATCH 1/5] chore: Make all tests use span streaming --- .../pydantic_ai/test_pydantic_ai.py | 35 +++++++++++++++++++ tests/profiler/test_continuous_profiler.py | 1 + tests/test_basics.py | 5 +-- tests/test_dsc.py | 1 + tests/test_envelope.py | 1 + tests/test_scope.py | 4 +-- tests/test_tracing_utils.py | 1 + tests/tracing/test_decorator.py | 1 + tests/tracing/test_misc.py | 1 + tests/tracing/test_propagation.py | 10 +++--- 10 files changed, 51 insertions(+), 9 deletions(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 8255ab3386..23d7da8b76 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -1093,6 +1093,7 @@ async def test_context_cleanup_after_run(sentry_init, get_test_agent): sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Verify context is not set before run @@ -1116,6 +1117,7 @@ def test_context_cleanup_after_run_sync(sentry_init, get_test_agent, sync_event_ sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Verify context is not set before run @@ -1140,6 +1142,7 @@ async def test_context_cleanup_after_streaming(sentry_init, get_test_agent): sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Verify context is not set before run @@ -1166,6 +1169,7 @@ async def test_context_cleanup_on_error(sentry_init, get_test_agent): sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) test_agent = get_test_agent() @@ -1200,6 +1204,7 @@ async def test_context_isolation_concurrent_agents(sentry_init, get_test_agent): sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Create a second agent @@ -1355,6 +1360,7 @@ async def test_model_name_extraction_with_callable( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Test the utility function directly @@ -1384,6 +1390,7 @@ async def test_model_name_extraction_fallback_to_str( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Test the utility function directly @@ -1617,6 +1624,7 @@ async def test_update_invoke_agent_span_with_none_output( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -1643,6 +1651,7 @@ async def test_update_ai_client_span_with_none_response( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) span = sentry_sdk.traces.start_span(name="test_span") @@ -1691,6 +1700,7 @@ async def test_input_messages_error_handling( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -1720,6 +1730,7 @@ async def test_available_tools_error_handling( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) span = sentry_sdk.traces.start_span(name="test_span") @@ -1747,6 +1758,7 @@ async def test_set_usage_data_with_none_usage( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) span = sentry_sdk.traces.start_span(name="test_span") @@ -1772,6 +1784,7 @@ async def test_set_usage_data_with_partial_fields( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) span = sentry_sdk.traces.start_span(name="test_span") @@ -1844,6 +1857,7 @@ async def test_message_parts_with_list_content( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -1956,6 +1970,7 @@ async def test_output_data_error_handling( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -1988,6 +2003,7 @@ async def test_message_with_system_prompt_part( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2022,6 +2038,7 @@ async def test_message_with_instructions( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2054,6 +2071,7 @@ async def test_set_input_messages_without_prompts( sentry_init( integrations=[PydanticAIIntegration(include_prompts=False)], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2080,6 +2098,7 @@ async def test_get_model_name_with_exception_in_callable( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Create model with callable name that raises exception @@ -2105,6 +2124,7 @@ async def test_get_model_name_with_string_model( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Pass a string as model @@ -2126,6 +2146,7 @@ async def test_get_model_name_with_none( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Pass None @@ -2150,6 +2171,7 @@ async def test_should_send_prompts_without_pii( sentry_init( integrations=[PydanticAIIntegration(include_prompts=True)], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=False, # PII disabled, ) @@ -2173,6 +2195,7 @@ async def test_set_available_tools_without_toolset( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) span = sentry_sdk.traces.start_span(name="test_span") @@ -2202,6 +2225,7 @@ async def test_set_available_tools_with_schema( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) span = sentry_sdk.traces.start_span(name="test_span") @@ -2237,6 +2261,7 @@ async def test_execute_tool_span_creation( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2260,6 +2285,7 @@ async def test_execute_tool_span_with_mcp_type( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2284,6 +2310,7 @@ async def test_execute_tool_span_without_prompts( sentry_init( integrations=[PydanticAIIntegration(include_prompts=False)], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2305,6 +2332,7 @@ async def test_execute_tool_span_with_none_args( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2327,6 +2355,7 @@ async def test_update_execute_tool_span_with_none_span( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Update with None span - should not raise @@ -2351,6 +2380,7 @@ async def test_update_execute_tool_span_with_none_result( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2373,6 +2403,7 @@ async def test_tool_execution_without_span_context( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Create a simple agent with no tools (won't have function_toolset) @@ -2405,6 +2436,7 @@ async def test_invoke_agent_span_with_callable_instruction( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2436,6 +2468,7 @@ async def test_invoke_agent_span_with_string_instructions( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", send_default_pii=True, ) @@ -2463,6 +2496,7 @@ async def test_ai_client_span_with_streaming_flag( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Set streaming flag in scope @@ -2489,6 +2523,7 @@ async def test_ai_client_span_gets_agent_from_scope( sentry_init( integrations=[PydanticAIIntegration()], traces_sample_rate=1.0, + trace_lifecycle="stream", ) # Set agent in scope diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 1f5fb65be5..6471497357 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -564,6 +564,7 @@ def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyl ) sentry_init( traces_sample_rate=1.0, + trace_lifecycle="stream", **options, ) diff --git a/tests/test_basics.py b/tests/test_basics.py index ea7224a3ac..8e28792da4 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -940,11 +940,12 @@ def test_functions_to_trace_no_dot_does_not_crash(sentry_init): sentry_init( traces_sample_rate=1.0, functions_to_trace=[{"qualified_name": "my_function"}], + trace_lifecycle="stream", ) def test_last_event_id(sentry_init): - sentry_init(traces_sample_rate=1.0) + sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") assert last_event_id() is None @@ -954,7 +955,7 @@ def test_last_event_id(sentry_init): def test_last_event_id_scope(sentry_init): - sentry_init(traces_sample_rate=1.0) + sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") # Should not crash with isolation_scope() as scope: diff --git a/tests/test_dsc.py b/tests/test_dsc.py index ea1aa2fa3b..464a8635ce 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -449,6 +449,7 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): environment="canary", traces_sample_rate=traces_sample_rate, transport=TestTransportWithOptions, + trace_lifecycle="stream", ) envelopes = capture_envelopes() diff --git a/tests/test_envelope.py b/tests/test_envelope.py index f6a7c4b541..15856c4bd0 100644 --- a/tests/test_envelope.py +++ b/tests/test_envelope.py @@ -88,6 +88,7 @@ def test_envelope_headers(sentry_init, capture_envelopes, monkeypatch): sentry_init( dsn="https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012", traces_sample_rate=1.0, + trace_lifecycle="stream", ) envelopes = capture_envelopes() diff --git a/tests/test_scope.py b/tests/test_scope.py index ee7643a77f..b90fb4665c 100644 --- a/tests/test_scope.py +++ b/tests/test_scope.py @@ -884,7 +884,7 @@ def test_set_tags(): def test_last_event_id(sentry_init): - sentry_init(traces_sample_rate=1.0) + sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") assert Scope.last_event_id() is None @@ -894,7 +894,7 @@ def test_last_event_id(sentry_init): def test_last_event_id_cleared(sentry_init): - sentry_init(traces_sample_rate=1.0) + sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") # Make sure last_event_id is set sentry_sdk.capture_exception(Exception("test")) diff --git a/tests/test_tracing_utils.py b/tests/test_tracing_utils.py index 070c56e8b8..0b2f730909 100644 --- a/tests/test_tracing_utils.py +++ b/tests/test_tracing_utils.py @@ -277,6 +277,7 @@ def test_should_continue_trace( org_id=explicit_org_id, strict_trace_continuation=strict_trace_continuation, traces_sample_rate=1.0, + trace_lifecycle="stream", transport=TestTransportWithOptions, ) diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index 954ffe4323..a61f172bf9 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -327,6 +327,7 @@ async def _some_function_traced_stream(a, b, c): def test_functions_to_trace_signature_unchanged_sync(sentry_init): sentry_init( traces_sample_rate=1.0, + trace_lifecycle="stream", ) def _some_function(a, b, c): diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index 3c25506224..4ef12711a0 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -109,6 +109,7 @@ def test_should_propagate_trace_to_sentry( sentry_init( dsn=dsn, traces_sample_rate=1.0, + trace_lifecycle="stream", ) client = sentry_sdk.get_client() diff --git a/tests/tracing/test_propagation.py b/tests/tracing/test_propagation.py index 29b1af295a..3006bdc4b1 100644 --- a/tests/tracing/test_propagation.py +++ b/tests/tracing/test_propagation.py @@ -4,19 +4,19 @@ def test_standalone_span_iter_headers(sentry_init): - sentry_init(traces_sample_rate=1.0) + sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") - with sentry_sdk.start_span(op="test") as span: + with sentry_sdk.traces.start_span(name="test") as span: with pytest.raises(StopIteration): # We should not have any propagation headers next(span.iter_headers()) def test_span_in_span_iter_headers(sentry_init): - sentry_init(traces_sample_rate=1.0) + sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") - with sentry_sdk.start_span(op="test"): - with sentry_sdk.start_span(op="test2") as span_inner: + with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.traces.start_span(name="test2") as span_inner: with pytest.raises(StopIteration): # We should not have any propagation headers next(span_inner.iter_headers()) From ab95129c6101facc7cd405c30cb85a975a4cec4c Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 11 Sep 2026 11:04:07 +0200 Subject: [PATCH 2/5] continue_trace --- tests/test_dsc.py | 8 ++--- tests/test_feature_flags.py | 8 ++--- tests/tracing/test_sample_rand_propagation.py | 35 ++----------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/tests/test_dsc.py b/tests/test_dsc.py index 464a8635ce..9aa91f9293 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -140,7 +140,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes): } # We continue the incoming trace and start a new segment - sentry_sdk.continue_trace(incoming_http_headers) + sentry_sdk.traces.continue_trace(incoming_http_headers) with sentry_sdk.traces.start_span(name="foo"): pass @@ -222,7 +222,7 @@ def my_traces_sampler(sampling_context): # We continue the incoming trace and start a new segment with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=125000): - sentry_sdk.continue_trace(incoming_http_headers) + sentry_sdk.traces.continue_trace(incoming_http_headers) with sentry_sdk.traces.start_span(name="foo"): pass @@ -473,7 +473,7 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): # We continue the trace (meaning: saving the incoming trace information on the scope) # but in this test, we do not start a transaction. - sentry_sdk.continue_trace(incoming_http_headers) + sentry_sdk.traces.continue_trace(incoming_http_headers) # No transaction is started, just an error is captured try: @@ -564,7 +564,7 @@ def test_dsc_issue_twp_span_streaming( # We continue the trace (meaning: saving the incoming trace information on the scope) # but in this test, we do not start a segment. - sentry_sdk.continue_trace(incoming_http_headers) + sentry_sdk.traces.continue_trace(incoming_http_headers) # No segment is started, just an error is captured try: diff --git a/tests/test_feature_flags.py b/tests/test_feature_flags.py index 292d7f61c5..c9f3e421f3 100644 --- a/tests/test_feature_flags.py +++ b/tests/test_feature_flags.py @@ -39,8 +39,8 @@ async def test_featureflags_integration_spans_async(sentry_init, capture_events) add_feature_flag("hello", False) try: - with sentry_sdk.start_span(name="test-span"): - with sentry_sdk.start_span(name="test-span-2"): + with sentry_sdk.traces.start_span(name="test-span"): + with sentry_sdk.traces.start_span(name="test-span-2"): raise ValueError("something wrong!") except ValueError as e: sentry_sdk.capture_exception(e) @@ -68,8 +68,8 @@ def test_featureflags_integration_spans_sync(sentry_init, capture_events): add_feature_flag("hello", False) try: - with sentry_sdk.start_span(name="test-span"): - with sentry_sdk.start_span(name="test-span-2"): + with sentry_sdk.traces.start_span(name="test-span"): + with sentry_sdk.traces.start_span(name="test-span-2"): raise ValueError("something wrong!") except ValueError as e: sentry_sdk.capture_exception(e) diff --git a/tests/tracing/test_sample_rand_propagation.py b/tests/tracing/test_sample_rand_propagation.py index 4b63d86442..773c06ff48 100644 --- a/tests/tracing/test_sample_rand_propagation.py +++ b/tests/tracing/test_sample_rand_propagation.py @@ -12,20 +12,7 @@ import sentry_sdk -def test_continue_trace_with_sample_rand(): - """ - Test that an incoming sample_rand is propagated onto the transaction's baggage. - """ - headers = { - "sentry-trace": "00000000000000000000000000000000-0000000000000000-0", - "baggage": "sentry-sample_rand=0.1,sentry-sample_rate=0.5", - } - - transaction = sentry_sdk.continue_trace(headers) - assert transaction.get_baggage().sentry_items["sample_rand"] == "0.1" - - -def test_continue_trace_with_sample_rand_span_streaming(sentry_init): +def test_continue_trace_with_sample_rand(sentry_init): """ Test that an incoming sample_rand is propagated onto the segment's baggage. """ @@ -41,25 +28,7 @@ def test_continue_trace_with_sample_rand_span_streaming(sentry_init): assert segment._get_baggage().sentry_items["sample_rand"] == "0.100000" -def test_continue_trace_missing_sample_rand(): - """ - Test that a missing sample_rand is filled in onto the transaction's baggage. - """ - - headers = { - "sentry-trace": "00000000000000000000000000000000-0000000000000000", - "baggage": "sentry-placeholder=asdf", - } - - with mock.patch( - "sentry_sdk.tracing_utils.Random.randrange", Mock(return_value=500000) - ): - transaction = sentry_sdk.continue_trace(headers) - - assert transaction.get_baggage().sentry_items["sample_rand"] == "0.500000" - - -def test_continue_trace_missing_sample_rand_span_streaming(sentry_init): +def test_continue_trace_missing_sample_rand(sentry_init): """ Test that a missing sample_rand is filled in onto the segment's baggage. """ From 1b7ebcfc1a19f0bce2b9219fad810af1797229e5 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 11 Sep 2026 11:17:02 +0200 Subject: [PATCH 3/5] more --- .../aws_lambda/test_aws_lambda.py | 38 +---- .../integrations/starlette/test_starlette.py | 2 +- tests/profiler/test_continuous_profiler.py | 39 ----- tests/test_api.py | 30 +--- tests/test_dsc.py | 143 +----------------- tests/tracing/test_decorator.py | 100 ++---------- tests/tracing/test_deprecated.py | 11 -- tests/tracing/test_http_headers.py | 43 +----- 8 files changed, 21 insertions(+), 385 deletions(-) delete mode 100644 tests/tracing/test_deprecated.py diff --git a/tests/integrations/aws_lambda/test_aws_lambda.py b/tests/integrations/aws_lambda/test_aws_lambda.py index a9382150e1..487323dcb9 100644 --- a/tests/integrations/aws_lambda/test_aws_lambda.py +++ b/tests/integrations/aws_lambda/test_aws_lambda.py @@ -335,20 +335,6 @@ def test_user_info_with_data_collection_user_info_on(lambda_client, test_environ assert _get_span_attr(attrs, "user.id") == "42" -def test_user_info_with_data_collection_user_info_off(lambda_client, test_environment): - lambda_client.invoke( - FunctionName="BasicOkDataCollectionUserInfoOff", - Payload=USER_INFO_PAYLOAD, - ) - span_items = test_environment["server"].span_items - - segment_spans = [s for s in span_items if s.get("is_segment")] - assert len(segment_spans) == 1 - attrs = segment_spans[0]["attributes"] - - assert "user.id" not in attrs - - def test_request_data_with_data_collection_allowlist(lambda_client, test_environment): payload = b""" { @@ -902,9 +888,7 @@ def test_url_query_params_with_data_collection(lambda_client, test_environment): ) -def test_span_streaming_user_info_with_send_default_pii( - lambda_client, test_environment -): +def test_user_info_with_send_default_pii(lambda_client, test_environment): payload = b""" { "resource": "/asd", @@ -944,25 +928,7 @@ def test_span_streaming_user_info_with_send_default_pii( assert _get_span_attr(attrs, "user.id") == "42" -def test_span_streaming_user_info_with_data_collection_user_info_on( - lambda_client, test_environment -): - lambda_client.invoke( - FunctionName="BasicOkSpanStreamingDataCollectionUserInfoOn", - Payload=USER_INFO_PAYLOAD, - ) - span_items = test_environment["server"].span_items - - segment_spans = [s for s in span_items if s.get("is_segment")] - assert len(segment_spans) == 1 - attrs = segment_spans[0]["attributes"] - - assert _get_span_attr(attrs, "user.id") == "42" - - -def test_span_streaming_user_info_with_data_collection_user_info_off( - lambda_client, test_environment -): +def test_user_info_with_data_collection_user_info_off(lambda_client, test_environment): lambda_client.invoke( FunctionName="BasicOkSpanStreamingDataCollectionUserInfoOff", Payload=USER_INFO_PAYLOAD, diff --git a/tests/integrations/starlette/test_starlette.py b/tests/integrations/starlette/test_starlette.py index 36d9193fc0..41b905746f 100644 --- a/tests/integrations/starlette/test_starlette.py +++ b/tests/integrations/starlette/test_starlette.py @@ -1441,7 +1441,7 @@ def test_active_thread_id(sentry_init, capture_items, endpoint): @pytest.mark.parametrize("endpoint", ["/sync/thread_ids", "/async/thread_ids"]) -def test_http_route_span_streaming(sentry_init, capture_items, endpoint): +def test_http_route(sentry_init, capture_items, endpoint): sentry_init( auto_enabling_integrations=False, integrations=[StarletteIntegration(transaction_style="url")], diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 6471497357..a791aa343c 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -581,45 +581,6 @@ def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyl mock_teardown.assert_not_called() -@pytest.mark.parametrize( - ["mode", "class_name"], - [ - pytest.param("thread", "ThreadContinuousScheduler"), - pytest.param( - "gevent", - "GeventContinuousScheduler", - marks=requires_gevent, - ), - ], -) -def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyle_span_streaming( - sentry_init, - mode, - class_name, - teardown_profiling, -): - options = make_options( - mode=mode, profile_session_sample_rate=0.0, lifecycle="trace" - ) - sentry_init( - traces_sample_rate=1.0, - trace_lifecycle="stream", - **options, - ) - - with mock.patch( - f"sentry_sdk.profiler.continuous_profiler.{class_name}.ensure_running" - ) as mock_ensure_running: - start_profiler() - mock_ensure_running.assert_not_called() - - with mock.patch( - f"sentry_sdk.profiler.continuous_profiler.{class_name}.teardown" - ) as mock_teardown: - stop_profiler() - mock_teardown.assert_not_called() - - def test_continuous_profiler_run_does_not_null_buffer( sentry_init, capture_envelopes, diff --git a/tests/test_api.py b/tests/test_api.py index 981ca13bca..dfc4d9a9e0 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -16,7 +16,6 @@ ) from sentry_sdk.client import Client, NonRecordingClient from sentry_sdk.traces import StreamedSpan -from sentry_sdk.tracing import Span from tests.conftest import TestTransportWithOptions @@ -29,7 +28,7 @@ def test_get_current_span(): assert get_current_span(fake_scope) is None -def test_get_current_span_span_streaming(): +def test_get_current_span_via_traces(): fake_scope = mock.MagicMock() fake_scope.streamed_span = mock.MagicMock() assert sentry_sdk.traces.get_current_span(fake_scope) == fake_scope.streamed_span @@ -44,13 +43,12 @@ def test_get_current_span_current_scope(sentry_init): assert get_current_span() is None scope = get_current_scope() - fake_span = Span() - scope.span = fake_span + fake_span = StreamedSpan(name="test", scope=scope) assert get_current_span() == fake_span -def test_get_current_span_current_scope_span_streaming(sentry_init): +def test_get_current_span_current_scope_via_traces(sentry_init): sentry_init(trace_lifecycle="stream") assert sentry_sdk.traces.get_current_span() is None @@ -83,17 +81,6 @@ def test_traceparent_with_tracing_enabled(sentry_init): def test_traceparent_with_tracing_disabled(sentry_init): - sentry_init() - - propagation_context = get_isolation_scope()._propagation_context - expected_traceparent = "%s-%s" % ( - propagation_context.trace_id, - propagation_context.span_id, - ) - assert get_traceparent() == expected_traceparent - - -def test_traceparent_with_tracing_disabled_span_streaming(sentry_init): sentry_init(trace_lifecycle="stream") propagation_context = get_isolation_scope()._propagation_context @@ -105,17 +92,6 @@ def test_traceparent_with_tracing_disabled_span_streaming(sentry_init): def test_baggage_with_tracing_disabled(sentry_init): - sentry_init(release="1.0.0", environment="dev") - propagation_context = get_isolation_scope()._propagation_context - expected_baggage = ( - "sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0".format( - propagation_context.trace_id - ) - ) - assert get_baggage() == expected_baggage - - -def test_baggage_with_tracing_disabled_span_streaming(sentry_init): sentry_init(release="1.0.0", environment="dev", trace_lifecycle="stream") propagation_context = get_isolation_scope()._propagation_context expected_baggage = ( diff --git a/tests/test_dsc.py b/tests/test_dsc.py index 9aa91f9293..4c2b8a1f14 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -263,56 +263,6 @@ def my_traces_sampler(sampling_context): def test_dsc_issue(sentry_init, capture_envelopes): - """ - Our service is a standalone service that does not have tracing enabled. Just uses Sentry for error reporting. - """ - sentry_init( - dsn="https://mysecret@o1234.ingest.sentry.io/12312012", - release="myapp@0.0.1", - environment="canary", - transport=TestTransportWithOptions, - ) - envelopes = capture_envelopes() - - # No transaction is started, just an error is captured - try: - 1 / 0 - except ZeroDivisionError as exp: - sentry_sdk.capture_exception(exp) - - assert len(envelopes) == 1 - - error_envelope = envelopes[0] - - envelope_trace_header = error_envelope.headers["trace"] - - assert "trace_id" in envelope_trace_header - assert type(envelope_trace_header["trace_id"]) == str - - assert "public_key" in envelope_trace_header - assert type(envelope_trace_header["public_key"]) == str - assert envelope_trace_header["public_key"] == "mysecret" - - assert "org_id" in envelope_trace_header - assert type(envelope_trace_header["org_id"]) == str - assert envelope_trace_header["org_id"] == "1234" - - assert "sample_rate" not in envelope_trace_header - - assert "sampled" not in envelope_trace_header - - assert "release" in envelope_trace_header - assert type(envelope_trace_header["release"]) == str - assert envelope_trace_header["release"] == "myapp@0.0.1" - - assert "environment" in envelope_trace_header - assert type(envelope_trace_header["environment"]) == str - assert envelope_trace_header["environment"] == "canary" - - assert "transaction" not in envelope_trace_header - - -def test_dsc_issue_span_streaming(sentry_init, capture_envelopes): """ Our service is a standalone service that does not have tracing enabled. Just uses Sentry for error reporting. """ @@ -427,95 +377,6 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes): assert envelope_trace_header["transaction"] == "foo" -@pytest.mark.parametrize( - "traces_sample_rate", - [ - 0, # no traces will be started, but if incoming traces will be continued (by our instrumentations, not happening in this test) - None, # no tracing at all. This service will never create transactions. - ], -) -def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): - """ - Our service does not have tracing enabled, but we receive tracing information from an upstream service. - Error envelopes still contain a DCS. This is called "tracing without performance" or TWP for short. - - This way if I have three services A, B, and C, and A and C have tracing enabled, but B does not, - we still can see the full trace in Sentry, and associate errors send by service B to Sentry. - (This test would be service B in this scenario) - """ - sentry_init( - dsn="https://mysecret@o1234.ingest.sentry.io/12312012", - release="myapp@0.0.1", - environment="canary", - traces_sample_rate=traces_sample_rate, - transport=TestTransportWithOptions, - trace_lifecycle="stream", - ) - envelopes = capture_envelopes() - - # This is what the upstream service sends us - sentry_trace = "771a43a4192642f0b136d5159a501700-1234567890abcdef-1" - baggage = ( - "other-vendor-value-1=foo;bar;baz, " - "sentry-trace_id=771a43a4192642f0b136d5159a501700, " - "sentry-public_key=frontendpublickey, " - "sentry-sample_rate=0.01337, " - "sentry-sampled=true, " - "sentry-release=myfrontend@1.2.3, " - "sentry-environment=bird, " - "sentry-transaction=bar, " - "other-vendor-value-2=foo;bar;" - ) - incoming_http_headers = { - "HTTP_SENTRY_TRACE": sentry_trace, - "HTTP_BAGGAGE": baggage, - } - - # We continue the trace (meaning: saving the incoming trace information on the scope) - # but in this test, we do not start a transaction. - sentry_sdk.traces.continue_trace(incoming_http_headers) - - # No transaction is started, just an error is captured - try: - 1 / 0 - except ZeroDivisionError as exp: - sentry_sdk.capture_exception(exp) - - assert len(envelopes) == 1 - - error_envelope = envelopes[0] - - envelope_trace_header = error_envelope.headers["trace"] - - assert "trace_id" in envelope_trace_header - assert type(envelope_trace_header["trace_id"]) == str - assert envelope_trace_header["trace_id"] == "771a43a4192642f0b136d5159a501700" - - assert "public_key" in envelope_trace_header - assert type(envelope_trace_header["public_key"]) == str - assert envelope_trace_header["public_key"] == "frontendpublickey" - - assert "sample_rate" in envelope_trace_header - assert type(envelope_trace_header["sample_rate"]) == str - assert envelope_trace_header["sample_rate"] == "0.01337" - - assert "sampled" in envelope_trace_header - assert type(envelope_trace_header["sampled"]) == str - assert envelope_trace_header["sampled"] == "true" - - assert "release" in envelope_trace_header - assert type(envelope_trace_header["release"]) == str - assert envelope_trace_header["release"] == "myfrontend@1.2.3" - - assert "environment" in envelope_trace_header - assert type(envelope_trace_header["environment"]) == str - assert envelope_trace_header["environment"] == "bird" - - assert "transaction" in envelope_trace_header - assert type(envelope_trace_header["transaction"]) == str - assert envelope_trace_header["transaction"] == "bar" - - @pytest.mark.parametrize( "traces_sample_rate", [ @@ -523,9 +384,7 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): None, # no tracing at all. This service will never create segments. ], ) -def test_dsc_issue_twp_span_streaming( - sentry_init, capture_envelopes, traces_sample_rate -): +def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): """ Our service does not have tracing enabled, but we receive tracing information from an upstream service. Error envelopes still contain a DSC. This is called "tracing without performance" or TWP for short. diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index a61f172bf9..21287e39d5 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -1,12 +1,8 @@ import inspect -from unittest import mock import pytest import sentry_sdk -from sentry_sdk.tracing_utils import create_span_decorator -from sentry_sdk.utils import logger -from tests.conftest import patch_start_tracing_child def my_example_function(): @@ -17,74 +13,7 @@ async def my_async_example_function(): return "return_of_async_function" -@pytest.mark.forked -def test_trace_decorator(): - with patch_start_tracing_child() as fake_start_child: - result = my_example_function() - fake_start_child.assert_not_called() - assert result == "return_of_sync_function" - - start_child_span_decorator = create_span_decorator() - result2 = start_child_span_decorator(my_example_function)() - fake_start_child.assert_called_once_with( - op="function", name="test_decorator.my_example_function" - ) - assert result2 == "return_of_sync_function" - - -def test_trace_decorator_no_trx(): - with patch_start_tracing_child(fake_transaction_is_none=True): - with mock.patch.object(logger, "debug", mock.Mock()) as fake_debug: - result = my_example_function() - fake_debug.assert_not_called() - assert result == "return_of_sync_function" - - start_child_span_decorator = create_span_decorator() - result2 = start_child_span_decorator(my_example_function)() - fake_debug.assert_called_once_with( - "Cannot create a child span for %s. " - "Please start a Sentry transaction before calling this function.", - "test_decorator.my_example_function", - ) - assert result2 == "return_of_sync_function" - - -@pytest.mark.forked -@pytest.mark.asyncio -async def test_trace_decorator_async(): - with patch_start_tracing_child() as fake_start_child: - result = await my_async_example_function() - fake_start_child.assert_not_called() - assert result == "return_of_async_function" - - start_child_span_decorator = create_span_decorator() - result2 = await start_child_span_decorator(my_async_example_function)() - fake_start_child.assert_called_once_with( - op="function", - name="test_decorator.my_async_example_function", - ) - assert result2 == "return_of_async_function" - - -@pytest.mark.asyncio -async def test_trace_decorator_async_no_trx(): - with patch_start_tracing_child(fake_transaction_is_none=True): - with mock.patch.object(logger, "debug", mock.Mock()) as fake_debug: - result = await my_async_example_function() - fake_debug.assert_not_called() - assert result == "return_of_async_function" - - start_child_span_decorator = create_span_decorator() - result2 = await start_child_span_decorator(my_async_example_function)() - fake_debug.assert_any_call( - "Cannot create a child span for %s. " - "Please start a Sentry transaction before calling this function.", - "test_decorator.my_async_example_function", - ) - assert result2 == "return_of_async_function" - - -def test_trace_decorator_span_streaming(sentry_init, capture_items): +def test_trace_decorator(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, trace_lifecycle="stream", @@ -106,14 +35,13 @@ def traced_function(): (span,) = spans assert ( - span["name"] - == "test_decorator.test_trace_decorator_span_streaming..traced_function" + span["name"] == "test_decorator.test_trace_decorator..traced_function" ) assert span["attributes"]["sentry.op"] == "function" assert span["status"] == "ok" -def test_trace_decorator_arguments_span_streaming(sentry_init, capture_items): +def test_trace_decorator_arguments(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, trace_lifecycle="stream", @@ -140,7 +68,7 @@ def traced_function(): assert span["status"] == "ok" -def test_trace_decorator_inactive_span_streaming(sentry_init, capture_items): +def test_trace_decorator_inactive(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, trace_lifecycle="stream", @@ -169,7 +97,7 @@ def traced_function(): @pytest.mark.asyncio -async def test_trace_decorator_async_span_streaming(sentry_init, capture_items): +async def test_trace_decorator_async(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, trace_lifecycle="stream", @@ -192,16 +120,14 @@ async def traced_function(): assert ( span["name"] - == "test_decorator.test_trace_decorator_async_span_streaming..traced_function" + == "test_decorator.test_trace_decorator_async..traced_function" ) assert span["attributes"]["sentry.op"] == "function" assert span["status"] == "ok" @pytest.mark.asyncio -async def test_trace_decorator_async_arguments_span_streaming( - sentry_init, capture_items -): +async def test_trace_decorator_async_arguments(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, trace_lifecycle="stream", @@ -229,9 +155,7 @@ async def traced_function(): @pytest.mark.asyncio -async def test_trace_decorator_async_inactive_span_streaming( - sentry_init, capture_items -): +async def test_trace_decorator_async_inactive(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, trace_lifecycle="stream", @@ -259,7 +183,7 @@ async def traced_function(): assert span2["name"] == "outer" -def test_trace_decorator_child_span_streaming(sentry_init, capture_items): +def test_trace_decorator_child(sentry_init, capture_items): """Spans created with @trace show up as children if a span is active.""" sentry_init( traces_sample_rate=1.0, @@ -284,7 +208,7 @@ def _some_function_traced_stream(a, b, c): assert ( child_span["name"] - == "test_decorator.test_trace_decorator_child_span_streaming.._some_function_traced_stream" + == "test_decorator.test_trace_decorator_child.._some_function_traced_stream" ) assert child_span["parent_span_id"] == segment.span_id assert segment_span["name"] == "segment" @@ -292,7 +216,7 @@ def _some_function_traced_stream(a, b, c): @pytest.mark.asyncio -async def test_trace_decorator_async_child_span_streaming(sentry_init, capture_items): +async def test_trace_decorator_async_child(sentry_init, capture_items): """Spans created with @trace show up as children if a span is active.""" sentry_init( traces_sample_rate=1.0, @@ -317,7 +241,7 @@ async def _some_function_traced_stream(a, b, c): assert ( child_span["name"] - == "test_decorator.test_trace_decorator_async_child_span_streaming.._some_function_traced_stream" + == "test_decorator.test_trace_decorator_async_child.._some_function_traced_stream" ) assert child_span["parent_span_id"] == segment.span_id assert segment_span["name"] == "segment" diff --git a/tests/tracing/test_deprecated.py b/tests/tracing/test_deprecated.py deleted file mode 100644 index 8b8150f5d1..0000000000 --- a/tests/tracing/test_deprecated.py +++ /dev/null @@ -1,11 +0,0 @@ -import warnings - -import sentry_sdk -import sentry_sdk.tracing - - -def test_no_warnings_scope_to_transaction_finish(): - transaction = sentry_sdk.tracing.Transaction() - with warnings.catch_warnings(): - warnings.simplefilter("error") - transaction.finish(sentry_sdk.Scope()) diff --git a/tests/tracing/test_http_headers.py b/tests/tracing/test_http_headers.py index 818c934fc2..9083e4c883 100644 --- a/tests/tracing/test_http_headers.py +++ b/tests/tracing/test_http_headers.py @@ -4,32 +4,11 @@ import sentry_sdk from sentry_sdk.traces import StreamedSpan -from sentry_sdk.tracing import Transaction from sentry_sdk.tracing_utils import extract_sentrytrace_data -@pytest.mark.parametrize("sampled", [True, False, None]) -def test_to_traceparent(sampled): - transaction = Transaction( - name="/interactions/other-dogs/new-dog", - op="greeting.sniff", - trace_id="12312012123120121231201212312012", - sampled=sampled, - ) - - traceparent = transaction.to_traceparent() - - parts = traceparent.split("-") - assert parts[0] == "12312012123120121231201212312012" # trace_id - assert parts[1] == transaction.span_id # parent_span_id - if sampled is None: - assert len(parts) == 2 - else: - assert parts[2] == "1" if sampled is True else "0" # sampled - - @pytest.mark.parametrize("traces_sample_rate", [1.0, 0.0, None]) -def test_to_traceparent_span_streaming(sentry_init, traces_sample_rate): +def test_to_traceparent(sentry_init, traces_sample_rate): sentry_init( traces_sample_rate=traces_sample_rate, trace_lifecycle="stream", @@ -88,25 +67,7 @@ def test_sentrytrace_extraction_leading_empty_fragment(): } -def test_iter_headers(monkeypatch): - monkeypatch.setattr( - Transaction, - "to_traceparent", - mock.Mock(return_value="12312012123120121231201212312012-0415201309082013-0"), - ) - - transaction = Transaction( - name="/interactions/other-dogs/new-dog", - op="greeting.sniff", - ) - - headers = dict(transaction.iter_headers()) - assert ( - headers["sentry-trace"] == "12312012123120121231201212312012-0415201309082013-0" - ) - - -def test_iter_headers_span_streaming(sentry_init, monkeypatch): +def test_iter_headers(sentry_init, monkeypatch): sentry_init( traces_sample_rate=0.0, trace_lifecycle="stream", From 3ccfb93b57a94d2707400c4cb61ddd50a3152eef Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 11 Sep 2026 11:18:32 +0200 Subject: [PATCH 4/5] iter_headers --- tests/tracing/test_propagation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tracing/test_propagation.py b/tests/tracing/test_propagation.py index 3006bdc4b1..d61d4c0e37 100644 --- a/tests/tracing/test_propagation.py +++ b/tests/tracing/test_propagation.py @@ -9,7 +9,7 @@ def test_standalone_span_iter_headers(sentry_init): with sentry_sdk.traces.start_span(name="test") as span: with pytest.raises(StopIteration): # We should not have any propagation headers - next(span.iter_headers()) + next(span._iter_headers()) def test_span_in_span_iter_headers(sentry_init): @@ -19,7 +19,7 @@ def test_span_in_span_iter_headers(sentry_init): with sentry_sdk.traces.start_span(name="test2") as span_inner: with pytest.raises(StopIteration): # We should not have any propagation headers - next(span_inner.iter_headers()) + next(span_inner._iter_headers()) def test_span_in_segment(sentry_init): From 69718a51390d0c5a1b549ac7eecf764179a8189f Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 11 Sep 2026 11:27:51 +0200 Subject: [PATCH 5/5] not applicable anymore, no standalone spans --- tests/test_api.py | 11 ----------- tests/tracing/test_propagation.py | 21 --------------------- 2 files changed, 32 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index dfc4d9a9e0..e4d3569172 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -37,17 +37,6 @@ def test_get_current_span_via_traces(): assert sentry_sdk.traces.get_current_span(fake_scope) is None -def test_get_current_span_current_scope(sentry_init): - sentry_init() - - assert get_current_span() is None - - scope = get_current_scope() - fake_span = StreamedSpan(name="test", scope=scope) - - assert get_current_span() == fake_span - - def test_get_current_span_current_scope_via_traces(sentry_init): sentry_init(trace_lifecycle="stream") diff --git a/tests/tracing/test_propagation.py b/tests/tracing/test_propagation.py index d61d4c0e37..22458ed76e 100644 --- a/tests/tracing/test_propagation.py +++ b/tests/tracing/test_propagation.py @@ -1,27 +1,6 @@ -import pytest - import sentry_sdk -def test_standalone_span_iter_headers(sentry_init): - sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") - - with sentry_sdk.traces.start_span(name="test") as span: - with pytest.raises(StopIteration): - # We should not have any propagation headers - next(span._iter_headers()) - - -def test_span_in_span_iter_headers(sentry_init): - sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream") - - with sentry_sdk.traces.start_span(name="test"): - with sentry_sdk.traces.start_span(name="test2") as span_inner: - with pytest.raises(StopIteration): - # We should not have any propagation headers - next(span_inner._iter_headers()) - - def test_span_in_segment(sentry_init): sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream")