ref: Add streaming trace decorator (7) #5594
5 issues
High
Circular import will cause ImportError at runtime - `sentry_sdk/tracing_utils.py:1377-1381`
This module-level import from sentry_sdk.traces creates a circular import. When traces.py is imported first, it attempts to import Baggage from tracing_utils.py at line 13. This triggers tracing_utils.py to load, which now tries to import LOW_QUALITY_SEGMENT_SOURCES, start_span, and StreamedSpan from traces.py. However, traces.py hasn't finished loading yet (it's still at line 13), so these symbols don't exist, causing an ImportError. The existing pattern in this file handles circular imports via deferred/lazy imports inside functions (see create_streaming_span_decorator which does from sentry_sdk.scope import... inside the function body).
StreamedSpan lacks context manager methods (__enter__/__exit__) causing decorator to fail at runtime - `sentry_sdk/traces.py:350-418`
The new trace decorator at line 350 calls create_streaming_span_decorator which uses start_streaming_span in a with statement (lines 964-966 and 979-982 in tracing_utils.py). However, StreamedSpan (the return type of start_streaming_span) does not implement __enter__ and __exit__ methods. This will cause a TypeError: 'StreamedSpan' object does not support the context manager protocol when any function decorated with @trace (from sentry_sdk.traces) is called.
Also found at:
sentry_sdk/tracing_utils.py:964-966
Medium
Missing test coverage for new streaming trace decorator - `sentry_sdk/traces.py:350-418`
The PR adds a new trace decorator in traces.py that wraps create_streaming_span_decorator, but there are no corresponding tests for this new functionality. The existing test_decorator.py tests only cover the trace decorator from sentry_sdk.tracing, not the new streaming equivalent in sentry_sdk.traces. Tests should verify the decorator works correctly for both sync and async functions, handles parameters (name, attributes, active) properly, and behaves correctly when used with and without parentheses (@trace vs @trace(...)).
Low
Unused import of should_send_default_pii - `sentry_sdk/tracing_utils.py:953`
The function imports should_send_default_pii from sentry_sdk.scope on line 953 but never uses it. This appears to be leftover code copied from the existing create_span_creating_decorator function which uses should_send_default_pii() to control PII handling in _set_input_attributes and _set_output_attributes. The streaming version doesn't call these functions and thus the import is dead code.
Unused import of should_send_default_pii in create_streaming_span_decorator - `sentry_sdk/tracing_utils.py:953`
The function imports should_send_default_pii from sentry_sdk.scope at line 953, but this function is never used within create_streaming_span_decorator. The non-streaming version (create_span_decorator) uses this import to determine whether to include PII in span attributes, but the streaming version appears incomplete.
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 3 | 2m 27s | $1.20 |
| find-bugs | 2 | 3m 12s | $2.08 |
| skill-scanner | 0 | 2m 51s | $0.36 |
| security-review | 0 | 1m 44s | $0.54 |
Duration: 10m 14s · Tokens: 3.4M in / 25.1k out · Cost: $4.20 (+merge: $0.00, +fix_gate: $0.01, +dedup: $0.00, +extraction: $0.00)