Skip to content

Commit 354b362

Browse files
committed
ref: Allow trace_lifecycle as init option
1 parent 495ff6b commit 354b362

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎MIGRATION_GUIDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Additionally, the OpenAI integration now sets `gen_ai.operation.name` to `chat`
252252
- The `update_current_span` API was removed.
253253
- 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.
254254
- 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`.
255-
- The `trace_lifecycle` option (both top-level and experimental) was removed. Span streaming is now the only tracing mode.
255+
- 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.
256256

257257
### Integrations
258258

‎sentry_sdk/client.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ def _record_lost_event(
349349

350350
try:
351351
_client_init_debug.set(self.options["debug"])
352+
353+
if self.options["trace_lifecycle"] not in (None, "stream"):
354+
logger.warning(
355+
"Span streaming is the only tracing mode. Ignoring unknown trace_lifecycle value."
356+
)
357+
352358
self.transport = make_transport(self.options)
353359

354360
self.monitor = None

‎sentry_sdk/consts.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ def __init__(
15391539
attach_stacktrace: bool = True,
15401540
ca_certs: "Optional[str]" = None,
15411541
traces_sample_rate: "Optional[float]" = None,
1542+
trace_lifecycle: "Optional[str]" = None,
15421543
traces_sampler: "Optional[TracesSampler]" = None,
15431544
profiler_mode: "Optional[ContinuousProfilerMode]" = None,
15441545
profile_lifecycle: 'Literal["manual", "trace"]' = "manual",
@@ -1853,6 +1854,10 @@ def __init__(
18531854
If you want to disable all tracing you need to set `traces_sample_rate=None`. In this case, no new traces
18541855
will be started and no incoming traces will be continued.
18551856
1857+
:param trace_lifecycle: Controls how traces are sent. Span streaming is the only supported tracing mode,
1858+
so the only accepted value is `"stream"`. Other values are ignored and a warning is logged.
1859+
This option only exists for backwards compatibility with 2.x and has no effect.
1860+
18561861
:param traces_sampler: A function responsible for determining the percentage chance a given service span will be
18571862
sent to Sentry.
18581863

‎tests/test_client.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,25 @@ def test_client_debug_option_enabled(sentry_init, caplog):
643643
assert "OK" in caplog.text
644644

645645

646+
@pytest.mark.parametrize(
647+
"trace_lifecycle,warns",
648+
[
649+
(None, False),
650+
("stream", False),
651+
("static", True),
652+
("unknown", True),
653+
],
654+
)
655+
def test_trace_lifecycle_option(sentry_init, caplog, trace_lifecycle, warns):
656+
sentry_init(debug=True, trace_lifecycle=trace_lifecycle)
657+
658+
warning = (
659+
"Span streaming is the only tracing mode. "
660+
"Ignoring unknown trace_lifecycle value."
661+
)
662+
assert (warning in caplog.text) is warns
663+
664+
646665
@pytest.mark.tests_internal_exceptions
647666
@pytest.mark.parametrize("with_client", (True, False))
648667
def test_client_debug_option_disabled(with_client, sentry_init, caplog):

0 commit comments

Comments
 (0)