Skip to content

ref: Add warnings to span streaming APIs (10)#5613

Merged
sentrivana merged 68 commits intomasterfrom
ivana/span-first-10-random-improvements
Mar 10, 2026
Merged

ref: Add warnings to span streaming APIs (10)#5613
sentrivana merged 68 commits intomasterfrom
ivana/span-first-10-random-improvements

Conversation

@sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Mar 9, 2026

Add warnings to span streaming APIs.

@sentrivana sentrivana changed the base branch from master to ivana/span-first-9-start-end March 9, 2026 09:51
@sentrivana sentrivana marked this pull request as ready for review March 9, 2026 09:56
@sentrivana sentrivana requested a review from a team as a code owner March 9, 2026 09:56
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.client instead of self.get_client() for options
    • Scope.start_streamed_span now checks span-streaming options via self.get_client().options so configured clients on parent scopes are respected.

Create PR

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 ""
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@cursor
Copy link

cursor bot commented Mar 9, 2026

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Warning check runs at decoration time, not call time
    • Removed the decoration-time span-streaming warning check in trace() so warning behavior now occurs at runtime in start_streamed_span after SDK initialization.

Create PR

Or push these changes by commenting:

@cursor push 9032d05639
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,
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

Comment on lines +965 to 970
"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 ""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

Base automatically changed from ivana/span-first-9-start-end to master March 10, 2026 11:05
@sentrivana sentrivana enabled auto-merge (squash) March 10, 2026 11:07
@sentrivana sentrivana merged commit bde87ac into master Mar 10, 2026
160 checks passed
@sentrivana sentrivana deleted the ivana/span-first-10-random-improvements branch March 10, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants