Skip to content

Commit 60217e1

Browse files
committed
ref: Add warnings to span streaming APIs
1 parent 0235053 commit 60217e1

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

sentry_sdk/scope.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,15 @@ def start_streamed_span(
11821182
active: bool,
11831183
) -> "StreamedSpan":
11841184
# TODO: rename to start_span once we drop the old API
1185+
if not has_span_streaming_enabled(self.client):
1186+
warnings.warn(
1187+
"Using span streaming API in non-span-streaming mode. Use "
1188+
"sentry_sdk.start_transaction() and sentry_sdk.start_span() "
1189+
"instead.",
1190+
stacklevel=2,
1191+
)
1192+
return NoOpStreamedSpan()
1193+
11851194
if isinstance(parent_span, NoOpStreamedSpan):
11861195
# parent_span is only set if the user explicitly set it
11871196
logger.debug(

sentry_sdk/traces.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
EXPERIMENTAL. Do not use in production.
3+
24
The API in this file is only meant to be used in span streaming mode.
35
46
You can enable span streaming mode via
@@ -84,6 +86,9 @@ def start_span(
8486
"""
8587
Start a span.
8688
89+
EXPERIMENTAL. Use sentry_sdk.start_transaction() and sentry_sdk.start_span()
90+
instead.
91+
8792
The span's parent, unless provided explicitly via the `parent_span` argument,
8893
will be the current active span, if any. If there is none, this span will
8994
become the root of a new span tree. If you explicitly want this span to be
@@ -144,6 +149,8 @@ def continue_trace(incoming: "dict[str, Any]") -> None:
144149
"""
145150
Continue a trace from headers or environment variables.
146151
152+
EXPERIMENTAL. Use sentry_sdk.continue_trace() instead.
153+
147154
This function sets the propagation context on the scope. Any span started
148155
in the updated scope will belong under the trace extracted from the
149156
provided propagation headers or environment variables.
@@ -168,6 +175,8 @@ def new_trace() -> None:
168175
"""
169176
Resets the propagation context, forcing a new trace.
170177
178+
EXPERIMENTAL.
179+
171180
This function sets the propagation context on the scope. Any span started
172181
in the updated scope will start its own trace.
173182
@@ -531,6 +540,8 @@ def trace(
531540
"""
532541
Decorator to start a span around a function call.
533542
543+
EXPERIMENTAL. Use @sentry_sdk.trace instead.
544+
534545
This decorator automatically creates a new span when the decorated function
535546
is called, and finishes the span when the function returns or raises an exception.
536547
@@ -578,7 +589,18 @@ def make_db_query(sql):
578589
# Function implementation
579590
pass
580591
"""
581-
from sentry_sdk.tracing_utils import create_streaming_span_decorator
592+
from sentry_sdk.tracing_utils import (
593+
create_streaming_span_decorator,
594+
has_span_streaming_enabled,
595+
)
596+
597+
client = sentry_sdk.get_client()
598+
if not has_span_streaming_enabled(client):
599+
warnings.warn(
600+
"Using span streaming API in non-span-streaming mode. Use "
601+
"@sentry_sdk.trace instead.",
602+
stacklevel=2,
603+
)
582604

583605
decorator = create_streaming_span_decorator(
584606
name=name,

0 commit comments

Comments
 (0)