From 354b36221cd5b877ca12663e780455176b2eb02b Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 23 Oct 2026 11:46:43 +0200 Subject: [PATCH] ref: Allow trace_lifecycle as init option --- MIGRATION_GUIDE.md | 2 +- sentry_sdk/client.py | 6 ++++++ sentry_sdk/consts.py | 5 +++++ tests/test_client.py | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 01e164fb9b..4f2e310bd7 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -252,7 +252,7 @@ Additionally, the OpenAI integration now sets `gen_ai.operation.name` to `chat` - The `update_current_span` API was removed. - The `sentry_sdk.tracing` module was removed, including the `Span`, `Transaction`, `NoOpSpan`, and `TransactionSource` classes. Import tracing primitives from `sentry_sdk.traces` instead. `TransactionSource` was replaced by `sentry_sdk.traces.SegmentNameSource`, which has the same values. The span classes from 2.x's span streaming mode, `sentry_sdk.traces.StreamedSpan` and `NoOpStreamedSpan`, are now called `Span` and `NoOpSpan`; the old names remain available as aliases. - The `stream_gen_ai_spans` option was removed. All spans are streamed now. If you previously set `stream_gen_ai_spans=False`, note that GenAI integrations no longer truncate messages (previously, only the last message was kept and truncated), and the OpenAI, Anthropic, LangChain, LiteLLM, and OpenAI Agents integrations no longer replace binary content in messages (for example, base64-encoded images) with `[Filtered]`. To prevent prompts and responses from being sent, set `data_collection`'s `gen_ai` `inputs` and/or `outputs` to `False`. -- The `trace_lifecycle` option (both top-level and experimental) was removed. Span streaming is now the only tracing mode. +- Span streaming is now the only tracing mode. The experimental `trace_lifecycle` option was removed. The top-level `trace_lifecycle` option is still accepted, but any value other than `"stream"` is ignored and logs a warning. ### Integrations diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index ed637619b2..141dba29d1 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -349,6 +349,12 @@ def _record_lost_event( try: _client_init_debug.set(self.options["debug"]) + + if self.options["trace_lifecycle"] not in (None, "stream"): + logger.warning( + "Span streaming is the only tracing mode. Ignoring unknown trace_lifecycle value." + ) + self.transport = make_transport(self.options) self.monitor = None diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 0140b6471b..45c1a68fae 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -1539,6 +1539,7 @@ def __init__( attach_stacktrace: bool = True, ca_certs: "Optional[str]" = None, traces_sample_rate: "Optional[float]" = None, + trace_lifecycle: "Optional[str]" = None, traces_sampler: "Optional[TracesSampler]" = None, profiler_mode: "Optional[ContinuousProfilerMode]" = None, profile_lifecycle: 'Literal["manual", "trace"]' = "manual", @@ -1853,6 +1854,10 @@ def __init__( If you want to disable all tracing you need to set `traces_sample_rate=None`. In this case, no new traces will be started and no incoming traces will be continued. + :param trace_lifecycle: Controls how traces are sent. Span streaming is the only supported tracing mode, + so the only accepted value is `"stream"`. Other values are ignored and a warning is logged. + This option only exists for backwards compatibility with 2.x and has no effect. + :param traces_sampler: A function responsible for determining the percentage chance a given service span will be sent to Sentry. diff --git a/tests/test_client.py b/tests/test_client.py index df56714fa8..c341d087f6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -643,6 +643,25 @@ def test_client_debug_option_enabled(sentry_init, caplog): assert "OK" in caplog.text +@pytest.mark.parametrize( + "trace_lifecycle,warns", + [ + (None, False), + ("stream", False), + ("static", True), + ("unknown", True), + ], +) +def test_trace_lifecycle_option(sentry_init, caplog, trace_lifecycle, warns): + sentry_init(debug=True, trace_lifecycle=trace_lifecycle) + + warning = ( + "Span streaming is the only tracing mode. " + "Ignoring unknown trace_lifecycle value." + ) + assert (warning in caplog.text) is warns + + @pytest.mark.tests_internal_exceptions @pytest.mark.parametrize("with_client", (True, False)) def test_client_debug_option_disabled(with_client, sentry_init, caplog):