ref: Add warnings to span streaming APIs (10)#5613
ref: Add warnings to span streaming APIs (10)#5613sentrivana wants to merge 12 commits intoivana/span-first-9-start-endfrom
Conversation
Codecov Results 📊✅ 9 passed | ⏭️ 1 skipped | Total: 10 | Pass Rate: 90% | Execution Time: 3.26s All tests are passing successfully. ❌ Patch coverage is 8.33%. Project has 14346 uncovered lines. Files with missing lines (2)
Generated by Codecov Action |
Codecov Results 📊✅ 52 passed | Total: 52 | Pass Rate: 100% | Execution Time: 15.16s All tests are passing successfully. ❌ Patch coverage is 27.54%. Project has 14560 uncovered lines. Generated by Codecov Action |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 6.07s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14956 uncovered lines. Files with missing lines (2)
Generated by Codecov Action |
…random-improvements
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Decorator warns but still proceeds to create streaming span
- Both async and sync streaming decorator wrappers now return immediately after warning in non-streaming mode, preventing a second conflicting warning from span creation.
- ✅ Fixed: Uses
self.clientinstead ofself.get_client()for optionsScope.start_streamed_spannow checks span-streaming options viaself.get_client().optionsso configured clients on parent scopes are respected.
Or push these changes by commenting:
@cursor push 597152d23e
Preview (597152d23e)
diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py
--- a/sentry_sdk/scope.py
+++ b/sentry_sdk/scope.py
@@ -1182,7 +1182,7 @@
active: bool,
) -> "StreamedSpan":
# TODO: rename to start_span once we drop the old API
- if not has_span_streaming_enabled(self.client.options):
+ if not has_span_streaming_enabled(self.get_client().options):
warnings.warn(
"Using span streaming API in non-span-streaming mode. Use "
"sentry_sdk.start_transaction() and sentry_sdk.start_span() "
diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py
--- a/sentry_sdk/tracing_utils.py
+++ b/sentry_sdk/tracing_utils.py
@@ -966,6 +966,7 @@
"@sentry_sdk.trace instead.",
stacklevel=2,
)
+ return await f(*args, **kwargs)
span_name = name or qualname_from_function(f) or ""
@@ -989,6 +990,7 @@
"@sentry_sdk.trace instead.",
stacklevel=2,
)
+ return f(*args, **kwargs)
span_name = name or qualname_from_function(f) or ""|
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting: Preview (9032d05639)diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py
--- a/sentry_sdk/traces.py
+++ b/sentry_sdk/traces.py
@@ -589,19 +589,8 @@
# Function implementation
pass
"""
- from sentry_sdk.tracing_utils import (
- create_streaming_span_decorator,
- has_span_streaming_enabled,
- )
+ from sentry_sdk.tracing_utils import create_streaming_span_decorator
- client = sentry_sdk.get_client()
- if not has_span_streaming_enabled(client.options):
- warnings.warn(
- "Using span streaming API in non-span-streaming mode. Use "
- "@sentry_sdk.trace instead.",
- stacklevel=2,
- )
-
decorator = create_streaming_span_decorator(
name=name,
attributes=attributes, |
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
…random-improvements
…random-improvements
…random-improvements
| "Using span streaming API in non-span-streaming mode. Use " | ||
| "@sentry_sdk.trace instead.", | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| span_name = name or qualname_from_function(f) or "" |
There was a problem hiding this comment.
Bug: The @traces.trace decorator issues a duplicate warning when span streaming is disabled because both the decorator wrapper and the start_span function perform the same check and warning.
Severity: MEDIUM
Suggested Fix
Remove the warning check from the async_wrapper and sync_wrapper in sentry_sdk/tracing_utils.py. Rely solely on the existing warning within the start_span() function, which is called by the wrappers, to avoid duplication.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/tracing_utils.py#L965-L970
Potential issue: When span streaming is not enabled, functions decorated with
`@traces.trace` will trigger two identical warnings for each call. One warning
originates from the decorator's wrapper in `sentry_sdk/tracing_utils.py`
(`async_wrapper` or `sync_wrapper`). The wrapper then calls `traces.start_span()`, which
issues a second, duplicate warning. Because the warnings originate from different code
locations, Python's warning deduplication mechanism does not suppress the second one,
resulting in confusing and redundant output for the user.

Add warnings to span streaming APIs.