Skip to content

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

Open
sentrivana wants to merge 12 commits intoivana/span-first-9-start-endfrom
ivana/span-first-10-random-improvements
Open

ref: Add warnings to span streaming APIs (10)#5613
sentrivana wants to merge 12 commits intoivana/span-first-9-start-endfrom
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 title ref: Add warnings to span streaming APIs ref: Add warnings to span streaming APIs (10) Mar 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

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)
File Patch % Lines
tracing_utils.py 42.81% ⚠️ 354 Missing and 28 partials
traces.py 40.43% ⚠️ 140 Missing

Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

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)
File Patch % Lines
scope.py 64.95% ⚠️ 293 Missing and 68 partials
traces.py 40.95% ⚠️ 137 Missing

Generated by Codecov Action

@sentrivana sentrivana changed the base branch from ivana/span-first-9-start-end to master March 9, 2026 09:51
@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.

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.

2 participants